Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

IOT

Download as pdf or txt
Download as pdf or txt
You are on page 1of 79

LAB SESSION 01: BASIC LED BLINKING

Date oftheSession: / / Time ofthe Session:

Prerequis
ite:

 General idea how a NodeMCU works.

 General idea of microcontrollers like Arduino.

In-Lab:
OBJECTIVE:To Blink an On-Board LED on NodeMCU .

COMPONENTS REQUIRED:1) NodeMCU – 1


2) Micro USB Cable – 1
3) PC – 1
4) Connecting Wires.
5)Bread Board.

SOFTWARE REQUIREMENTS:1)uPycraft.
Or
2) Arduino IDE.

PRE-LAB WORK:
NodeMCU is an open source IoT platform.It includes firmware which runs on the ESP8266 Wi-
Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module.The ESP8266
NodeMcu is a complex device, which combines some features of the ordinary Arduino board with
the possibility of connecting to the internet.

Features:
 It is a Tensilica 32-bit RISC CPU Xtensa LX106 Microcontroller.
 Its Operating Voltage is 3.3V & Input Voltage is 7-12V.
 Its having 16 Digital I/O Pins & 1 Analog Input Pin (ADC).
 Its having Flash Memory of 4MB & SRAM 64KB. NodeMCUhaving clock speed of 80
Mhz.
 Operating temperature range -40C ~ 125C.
 Modes of operation: Client, Access point, Client + Access point.
 10-bit ADC, SDIO 2.0, (H) SPI, UART, I2C, I2S, IR Remote Control, PWM, GPIO.

The interface of the module is mainly divided into two parts including both Firmware
and Hardware where former runs on the ESP8266 Wi-Fi SoC and later is based on the ESP-12 module.

Pin Diagram:

Pin Description:

1)Power Pin:There are four power pins viz. one VIN pin & three 3.3V pins. The VIN pin can be
used to directly supply the ESP8266 and its peripherals, if you have a regulated 5V voltage source.
The 3.3V pins are the output of an on-board voltage regulator.These pins can be used to supply
power to external components.

2)GND :GND is a ground pin of ESP8266 NodeMCU development board.

3)I2C Pins:I2C Pins are used to hook up all sorts of I2C sensors and peripherals in your project.
Both I2C Master and I2C Slave are supported. I2C interface functionality can be realized
programmatically, and the clock frequency is 100 kHz at a maximum.It should be noted that I2C
clock frequency should be higher than the slowest clock frequency of the slave device.

4)GPIO Pins:ESP8266 NodeMCU has 17 GPIO pins which can be assigned to various functions
such as I2C, I2S, UART, PWM, IR Remote Control, LED Light and Button programmatically.Each
digital enabled GPIO can be configured to internal pull-up or pull-down, or set to high impedance.
When configured as an input, it can also be set to edge-trigger or level-trigger to generate CPU
interrupts.

5)ADC Channel:The NodeMCU is embedded with a 10-bit precision SAR ADC. The two
functions can be implemented using ADC viz. Testing power supply voltage of VDD3P3 pin and
testing input voltage of TOUT pin. However, they cannot be implemented at the same time.
6)UART Pins:ESP8266 NodeMCU has 2 UART interfaces, i.e. UART0 and UART1, which
provide asynchronous communication (RS232 and RS485), and can communicate at up to 4.5 Mbps.
UART0 (TXD0, RXD0, RST0 & CTS0 pins) can be used for communication.It supports fluid

control. However, UART1 (TXD1 pin) features only data transmit signal so, it is usually used for
printing log.

7)SPI Pins:ESP8266 features two SPIs (SPI and HSPI) in slave and master modes. These SPIs
also support the following general-purpose SPI features:
 4 timing modes of the SPI format transfer.
 Up to 80 MHz and the divided clocks of 80 MHz.
 Up to 64-Byte FIFO.

8)SDIO Pins:ESP8266 features Secure Digital Input/Output Interface (SDIO) which is used to
directly interface SD cards. 4-bit 25 MHz SDIO v1.1 and 4-bit 50 MHz SDIO v2.0 are supported.

9)PWM Pins:The board has 4 channels of Pulse Width Modulation (PWM). The PWM output can
be implemented programmatically and used for driving digital motors and LEDs. PWM frequency
range is adjustable from 1000 μs to 10000 μs, i.e., between 100 Hz and 1 kHz.

10)Control Pins:Control Pins are used to control ESP8266. These pins include Chip Enable pin
(EN), Reset pin (RST) and WAKE pin.EN pin – The ESP8266 chip is enabled when EN pin is pulled
HIGH. When pulled LOW the chip works at minimum power.RST pin – RST pin is used to reset the
ESP8266 chip.WAKE pin – Wake pin is used to wake the chip from deep-sleep.

POST-LAB REQUIREMENTS:
 Observe the OUTPUT and note down the readings carefully.
 Apply this concepts to make our projects or Applications.
 Submit practical report in next lab for correction.

CODE:

import time
from machine import Pin
led=Pin(4,Pin.OUT)
while True:
led.value(1)
time.sleep(0.5)
led.value(0)
time.sleep(0.5)
CIRCUIT DIAGRAM:

PROCEDURE:
1. Make the connections as per the circuit diagram.
2. Check the ground connection precisely before switching on the power supply.
3. Connect Micro USB Cable to PC .
4. Write the Code in Python or C/C++ accordingly .
5. Run the code through Arduino IDE or uPycraft IDE and Observe the output.

PRECAUTIONS:
1.Check the sensor is working properly.
2.Check the connections are properly connected.
3.See that there are no errors in the code.
4. Check whether Ground and VCC connections are connected properly.

RESULT:Successfully implemented & Blink an On-Board LED on NodeMCU.


LAB SESSION 02: GAS DETECTING SENSOR USING

NODEMCU

Date oftheSession:/ / Time ofthe Session: to

PREREQUIST:-

 General idea of microcontroller Arduino.

 General idea how a sensor works.

In-Lab:-
OBJECTIVE:-
To design and implement a circuit to detect Gas using MQ-135 with the help of NODEMCU.

COMPONENTS REQUIRED:-
 MQ-135
 NODEMCU
 Connecting Wires
 Buzzer, Breadboard
 USB Cable

SOFTWARE:-uPycraft (or) Arduino IDE.

PRE-LAB WORK:-
GAS SENSOR(MQ-135):-
In this project we will learn about Gas Level Using NODEMCU & Gas Sensor
Module(MQ135). We will measure the quantity of gas in percentage.If the gas percentage increases
then the buzzer rings and led glows.
The MQ-135 gas sensor senses the gases like ammonia nitrogen, oxygen, alcohols,
aromatic compounds, sulfide and other harmful smoke. The MQ-3 gas sensor has a lower
conductivity to clean the air as a gas sensing material. In the atmosphere we can find polluting
gases, but the conductivity of gas sensor increases as the concentration of polluting gas increases.
MQ-135 gas sensor can be implementation to detect the smoke, benzene, steam and other
harmful gases. It has potential to detect different harmful gases. It is with low cost and particularly
suitable for Air quality monitoring application.
MQ-135

PIN DESCRIPTION:-
The MQ135 sensor is a signal output indicator instruction. It has two outputs: analog output
and TTL output. The TTL output is low signal light which can be accessed through the IO ports on
the Microcontroller. The analog output is an concentration, i.e. increasing voltage is directly
proportional to increasing concentration.
This sensor has a long life and reliable stability as well. It has high Sensitivity to detect
Ammonia, Sulfide and Benze.It can detect at a range of: 10 – 300 ppm NH3, 10 – 1000 ppm
Benzene, 10 – 300 Alcohol. It is operated at voltage of 5.0V.It is of low cost.

NODEMCU:-

NodeMCU is an open source IoTplatform.It includes firmware which runs on the ESP8266
Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module.The
ESP8266 NodeMcu is a complex device, which combines some features of the ordinary Arduino
board with the possibility of connecting to the internet.

NodeMCU
CIRCUIT DIAGRAM:-

PROCEDURE:-

1. Make the connections as per the circuit diagram.


2. Check the ground connection precisely before switching on the power supply.
3. Connect Micro USB Cable to PC .
4. Write the Code in Python or C/C++ accordingly.
5. Run the code through Arduino IDE or uPycraft IDE and Observe the output.

CODE:-
int buzzer = 8;

int smokeA0 = A0;

intsensorThres = 100;

void setup()

pinMode(buzzer, OUTPUT);

pinMode(smokeA0, INPUT);
Serial.begin(9600);

void loop() {

intanalogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");

Serial.println(analogSensor);

if (analogSensor-50 >sensorThres)

tone(buzzer, 1000, 200);

else

noTone(buzzer);

delay(500);

PRECAUTIONS:-

1. Check the sensor is working properly.

2.Check the connections are properly connected.

3.See that there are no errors in the code.

RESULT:-

Hence the gas sensor senses the harmful gases present around it, by using NODEMCU
microcontroller.
POST LAB:-

1. Record your observation and get it corrected by your next lab.

2. Check the experiment by connecting with other gas sensors.


LAB SESSION 03: PRESSURE SENSOR

Date oftheSession: / / Time ofthe Session: to

PREREQUISTE:
 General idea of microcontrollers like Arduino
 General idea how a sensor works.

IN LAB:-
OBJECTIVE:-
To know the amount pressure using BMP180 with the help of ESP32 .

COMPONENTS REQUIRED:-
o BMP180
o Breadboard
o ESP32
o Connecting wires
o USB Cable

SOFTWARE:-uPycraft (or) Arduino IDE.

PRE-LAB WORK:-
In this project we will learn about amount of Pressure Using ESP32 & Pressure
Sensor Module(BMP180). We will measure the amount of pressure applied. If the increases then
the buzzer rings.

PRESSURE SENSOR(BMP180):
The BMP180is a digital pressure sensor and it measures the absolute pressure of the air
around it. It features a measuring range from 300 to 1100hPa with an accuracy down to 0.02 hPa.
Because temperature affects the pressure, the sensor comes with a temperature sensor to give
temperature compensated pressure readings. Additionally, because the pressure changes with
altitude, you can also estimate the altitude based on the current pressure measurement.
There are only two pins present to communicate with the module. The BMP180 barometric sensor
uses I2C communication protocol. So, you need to use the SDA and SCL pins of the ESP32.It has
capable to read pressure, temperature, altitude parameters also. The data is sent to the module or
received from the module though I2C interface. So we have to get the information of barometric
pressure and temperature through this interface.
FEATURES OF BMP180:-
 Can measure temperature and altitude.
 Pressure range: 300 to 1100hPa.
 High relative accuracy of ±0.12hPa.
 Can work on low voltages.
 3.4Mhz I2C interface.
 Low power consumption (3uA)
 Pressure conversion time: 5msec.
 Potable size.

ESP32(MICRO CONTROLLER):-
ESP32 is a series of low-cost, low-power system on a chipmicrocontrollers with integrated Wi-
Fi and dual-mode Bluetooth. The ESP32 series employs a Tensilica Xtensa LX6 microprocessor in
both dual-core and single-core variations and includes built-in antenna switches, power amplifier,
low-noise receive amplifier, filters, and power-management modules. ESP32 is created and
developed by Espressif Systems, a Shanghai-based Chinese company, and is manufactured
by TSMC using their 40nm process.

PIN DESCRIPTION:-
The ESP32 chip comes with 48 pins with multiple functions. 18 Analog-to-Digital Converter
(ADC) channels, 3 SPI interfaces, 3 UART interfaces,2-I2C interfaces, 16 PWM output channels, 2
Digital-to-Analog Converters (DAC), 2 I2S interfaces, 10 Capacitive sensing GPIOs. ESP32 is
capable of functioning reliably in industrial environments, with an operating temperature ranging
from –40°C to +125°C.
CIRCUIT DIAGRAM:-

SCL-SERIAL CLOCK PIN


SDA-SERIAL DATA PIN

PROCEDURE:-
1. Make the connections as per the circuit diagram.
2. Check the ground connection precisely before switching on the power supply.
3. Connect Micro USB Cable to PC .
4. Write the Code in Python or C/C++ accordingly.
5. Run the code through Arduino IDE or uPycraft IDE and Observe the output.
CODE:-
#include <Wire.h>

#include <Adafruit_BMP085.h>

Adafruit_BMP085 bmp;

void setup() {

Serial.begin(9600);

if (!bmp.begin()) {

Serial.println("Could not find a valid BMP085/BMP180 sensor, check wiring!");

while (1) {}

void loop() {

Serial.print("Temperature = ");

Serial.print(bmp.readTemperature());

Serial.println(" *C");

Serial.print("Pressure = ");

Serial.print(bmp.readPressure());

Serial.println(" Pa");

Serial.print("Altitude = ");

Serial.print(bmp.readAltitude());

Serial.println(" meters");

Serial.print("Pressure at sealevel (calculated) = ");

Serial.print(bmp.readSealevelPressure());

Serial.println(" Pa");
Serial.print("Real altitude = ");

Serial.print(bmp.readAltitude(102000));

Serial.println(" meters");

Serial.println();

delay(500);

PRECAUTIONS:-

1. Check the sensor is working properly.

2. Check the connections are properly connected.

3. See that there are no errors in the code.

RESULT:-
Hence the pressure sensor calculates the amount of pressure using barometer(BMP180) with
the help of ESP32.

POST LAB:-

1. Record your observation and get it corrected by your next lab.

2. Check the experiment by connecting with other gas sensors.


LAB SESSION 04: SERVO MOTOR WITH ESP32

Date oftheSession: / / Time ofthe Session: to


Prereq
uisite:
 General idea of microcontrollers like Arduino.
 General idea how a motor works.

In-Lab:
OBJECTIVE:
To design and implement controlling of servo motor with the ESP32.

COMPONENTS REQUIRED:

 ESP32
 SERVO MOTOR
 JUMPER WIRES
 POWER SUPPLY
 CONNECTING WIRES

SORFTWARE REQUIRED:

1. uPycraft
or
2. Arduino ide

PRELAB WORK:
ESP32 MICROCONTROLLER
ESP32 is in the series of low power and low cost on chip
microcontroller. It comes up with already integrated dual mode Bluetooth and Wi-Fi. ESP32
comes up with a USB port so we can say that it is a plug and play device i.e. just plug in
cable and your device is turned on and you are able to program it just like Arduino
development boards.

Features:
• Built in Wi-Fi module of standard 802.11 and Wi-Fi module operate in range of 2.4 GHz –
2.5 GHz.

• Three modes of operation: 1. Access point. 2. Client. 3. Access point + station.

• Dual core microprocessor of 32 – bit.


• Operating voltage is 3.3 V and Clock frequency from 80 MHz and goes up to 240 MHz.
• SRAM memory is of 512 KB and ROM memory is 448 KB.
• External flash memory is supported and is up to 32 Mb i.e. 4MB.
• It has 36 general purpose input / output pins.
• General purpose input / output pins comes up with PWM / I2C and SPI
functionality.
• Bluetooth version 4.2 is available and Bluetooth low energy (BLE) version and its having
2 to 3.6 V operating voltage.

PIN DIAGRAM OF ESP32:

SERVO MOTOR :
 A servo motor is an electronic device which can push or rotate an object with great pression.
 If motors uses dc power then it is called dc servo motor, and if it is uses ac power supply
then it is called ac servo motor
 Servo motors works on pwm principle
 Its angle of rotation is controlled by the duration of pulse applied to its control pin.
CIRCUIT DIAGRAM:

Input of of servo (yellow wire) ----------


---------- digital input pin of Esp32 (D5)
Vcc of servomotor (red wire) ------------
------------Vcc of Esp32
Gnd of servo (black wire)-----------------
-----------------gnd of Esp32

POST-LAB
LAB REQUIREMENTS:
 Observe the OUTPUT and note down the readings carefully.
 Apply this concepts to make our projects or Applications.
 Submit practical report in next lab for correction.
CODE:

#include <Servo.h> // including servo library.

Servo servo_1; // Giving name to servo.

void setup (){


servo_1.attach(0); // Attaching Servo to D
}

void loop(){
servo_1.write (45); // Servo will move to 45 degree angle.
delay (1000);
servo_1.write (90); // servo will move to 90 degree angle.
delay (1000);
Servo_1.write(135); //servo will move to 135 degree angle.
Delay(1000);
Servo_1.write(180); //servo will move to 180 degree angle.
}

PROCEDURE:
1.) Make the connections as per the circuit diagram.

2.) Connect the Vcc pin of the servo motor to the Vcc pin of esp32

3.) Connect input pin of the servo motor to the digital input pins of the esp32

4.) Connect ground of servo to the ground of esp32

PRECAUTIONS:
1. Check the sensor is working properly.
2. Check the connections are properly connected.
3. See that there are no errors in the code.
4. Check whether Ground and VCC connections are connected properly.

RESULT: Successfully implemented & controlled Servo motor using ESP32.


LAB SESSION 05: SERVO MOTOR CONTROL USING
ESP32(BLUETOOTH)

Date oftheSession: / / Time ofthe Session: to


Prerequisite:
 General idea of microcontrollers like Arduino.
 General idea of how servomotor works.
In-Lab:

AIM:
To control the servo motor using ESP-32(BLUETOOTH MODULE)

COMPONENTS REQUIRED:
ESP 32
Few Jumper Wires
Servo Motor(We can use any type of servo motor within the current limit of ESP32)

PRE-LAB WORK:

SERVOMOTOR
A servo motor is an electrical device which can push or rotate an object with great precision.
If you want to rotate and object at some specific angles or distance, then you use servo motor.
It is just made up of simple motor which run through servo mechanism.
WORKING PRINCIPLE OF SERVO MOTOR
A servo consists of a Motor (DC or AC), a potentiometer, gear assembly and a controlling
circuit. First of all we use gear assembly to reduce RPM and to increase torque of motor. Say
at initial position of servo motor shaft, the position of the potentiometer knob is such that there
is no electrical signal generated at the output port of the potentiometer. Now an electrical
signal is given to another input terminal of the error detector amplifier. Now difference
between these two signals, one comes from potentiometer and another comes from other
source, will be processed in feedback mechanism and output will be provided in term of error
signal. This error signal acts as the input for motor and motor starts rotating. Now motor shaft
is connected with potentiometer and as motor rotates so the potentiometer and it will generate a
signal. So as the potentiometer’s angular position changes, its output feedback signal changes.
After sometime the position of potentiometer reaches at a position that the output of
potentiometer is same as external signal provided. At this condition, there will be no output
signal from the amplifier to the motor input as there is no difference between external applied
signal and the signal generated at potentiometer, and in this situation motor stops rotating.

CONROLLING SERVO MOTOR


All motors have three wires coming out of them. Out of which two will be used for Supply
(positive and negative) and one will be used for the signal that is to be sent from the MCU.
Servo motor is controlled by PWM (Pulse with Modulation) which is provided by the control
wires. There is a minimum pulse, a maximum pulse and a repetition rate. Servo motor can turn
90 degree from either direction form its neutral position. The servo motor expects to see a
pulse every 20 milliseconds (ms) and the length of the pulse will determine how far the motor
turns. For example, a 1.5ms pulse will make the motor turn to the 90° position, such as if pulse
is shorter than 1.5ms shaft moves to 0° and if it is longer than 1.5ms than it will turn the servo
to 180°.

Servo motor works on PWM (Pulse width modulation) principle, means its angle of rotation
is controlled by the duration of applied pulse to its Control PIN. Basically servo motor is made
up of DC motor which is controlled by a variable resistor (potentiometer) and some gears.
High speed force of DC motor is converted into torque by Gears. We know that WORK=
FORCE X DISTANCE, in DC motor Force is less and distance (speed) is high and in Servo,
force is High and distance is less. Potentiometer is connected to the output shaft of the Servo,
to calculate the angle and stop the DC motor on required angle.

ESP32
As you might know, the ESP32 is an incredibly feature-packed module that has not only WiFi
but also Bluetooth Low Energy (BLE).
BLUETOOTH LOW ENERGY(BLE)
ESP32 not just supports the latest BLE Bluetooth 4.2, it also supports classic bluetooth. It basically
means it can speak to old and new bluetooth phones/tables. This could one of the best features
especially, if you're designing a device that needs to work with existing as well as new
phones/tablets in the market. The ESP32 Bluetooth Radio and Baseband supports the following
features:

 Class-1, class-2 and class-3 transmit output powers and over 30 dB dynamic control range
 π/4 DQPSK and 8 DPSK modulation
 High performance in NZIF receiver sensitivity with over 98 dB dynamic range
 Class-1 operation without external PA
 Internal SRAM allows full speed data transfer, mixed voice and data, and full piconet operation
 Logic for forward error correction, header error control, access code correlation, CRC,
demodulation, encryption bit stream generation, whitening and transmit pulse shaping
 ACL, SCO, eSCO and AFH
 A-law, µ-law and CVSD digital audio CODEC in PCM interface
 SBC audio CODEC
 Power management for low power applications

PAJ7620

The PAC7620 integrates gesture recognition function with general I2C interface into a single chip
forming an image analytic sensor system. It can recognize 9 human hand gesticulations such as
moving up, down, left, right, forward, backward, circle-clockwise, circle-counter clockwise, and
waving. It also offers built-in proximity detection in sensing approaching or departing object from
the sensor. The PAC7620 is designed with great flexibility in power-saving mechanism, well suit
for low power battery operated HMI devices. The PAJ7620 is packaged into module form in-built
with IR LED and optics lens as a complete sensor solution
CODE:
constintxpin = A0; // x-axis of the accelerometer
constintypin = A3; // y-axis
constintzpin = A4; // z-axis

void setup()
{
Serial.begin(9600);
}

void loop()
{
int x = analogRead(xpin); //read from xpin
delay(1); //
int y = analogRead(ypin); //read from ypin
delay(1);
int z = analogRead(zpin); //read from zpin

floatzero_G = 512.0; //ADC is 0~1023 the zero g output equal to Vs/2


float scale = 102.3; //ADXL335330 Sensitivity is 330mv/g
//330 * 1024/3.3/1000
Serial.print(((float)x - 331.5)/65*9.8); //print x value on serial monitor
Serial.print("\t");
Serial.print(((float)y - 329.5)/68.5*9.8); //print y value on serial monitor
Serial.print("\t");
Serial.print(((float)z - 340)/68*9.8); //print z value on serial monitor
Serial.print("\n");
delay(1000); //wait for 1 second
}
CIRCUIT DIAGRAM:
PROCEDURE:
1. Make the connections as per the circuit diagram.
2. Check the ground connection precisely before switching on the power supply.
3. Connect Micro USB Cable to PC .
4. Write the Code in Python or C/C++ accordingly .
5. Run the code through Arduino IDE or uPycraft IDE and Observe the output.

RESULT:
LAB SESSION 06:GREETINGS MESSAGETHROUGH
WEBPAGEWITH ESP AS SERVER

Date oftheSession: / / Time ofthe Session: to

Prerequisite:
 General idea of microcontrollers like Arduino.
 General idea how a NodeMCU works.

In-lab:
AIM:To send a message through webpage with ESP as server
APPARATUS:
 ESP32 board
 PAJ7620
 Arduino IDE
 Breadboard
 Connecting wires
 USB Cable

PRE-LAB WORK:

ESP32:
ESP32 is a single 2.4 GHz Wi-Fi-and-Bluetooth combo chip designed with the TSMC
ultra-low-power 40 nm technology. It is designed to achieve the best power and RF performance,
showing robustness, versatility and reliability in a wide variety of applications and power scenarios.
The ESP32 series of chips includes ESP32-D0WDQ6, ESP32-D0WD, ESP32-D2WD, and ESP32-
S0WD. For details on part numbers and ordering information.
ESP32 is designed for mobile, wearable electronics, and Internet-of-Things (IoT) applications.
It features all the state-of-the-art characteristics of low-power chips, including fine-grained clock
gating, multiple power modes, and dynamic power scaling. For instance, in a low-power IoT sensor
hub application scenario, ESP32 is woken up periodically and only when a specified condition is
detected. Low-duty cycle is used to minimize the amount of energy that the chip expends. The
output of the power amplifier is also adjustable, thus contributing to an optimal trade-off between
communication range, data rate and power consumption.
ESP32 is a highly-integrated solution for Wi-Fi-and-Bluetooth IoT applications, with
around 20 external components. ESP32 integrates an antenna switch, RF balun, power amplifier,
low-noise receive amplifier, filters, and power management modules. As such, the entire solution
occupies minimal Printed Circuit Board (PCB) area. ESP32 uses CMOS for single-chip fully-
integrated radio and baseband, while also integrating advanced calibration circuitries that allow the
solution to remove external circuit imperfections or adjust to changes in external conditions. As
such, the mass production of ESP32 solutions does not require expensive and specialized Wi-Fi
testing equipment.
1. Wi-Fi Key Features:
• 802.11 b/g/n • 802.11 n (2.4 GHz), up to 150 Mbps • WMM • TX/RX A-MPDU, RX A-MSDU •
Immediate Block ACK • Defragmentation • Automatic Beacon monitoring (hardware TSF) • 4 ×
virtual Wi-Fi interfaces • Simultaneous support for Infrastructure Station, SoftAP, and
Promiscuous modes
Note that when ESP32 is in Station mode, performing a scan, the SoftAP channel will be changed. •
Antenna diversity
Because the ESP32 is the heart of the module, it should be possible to program your ESP32-DOIT
board with any environment supported by the ESP32. As usual, the most practical environment is
the Arduino (another offer that has a lot of support is MicroPython). One of the things that makes
the board so easy to use is that it already has a micro-USB port. Besides, the board includes built-in
buttons and LEDs, which is very useful for getting started without the need to connect to external
hardware. Thus, to program it, you just need a USB cable, and you don’t need to solder anything to
get started and create your first program. Yes, you can start playing with the board without needing
to solder anything, as long as you don’t need to use the GPIOs or other peripherals. There are plenty
of things to try, such as the Wi-Fi/Bluetooth functionalities or the different programming
environments, just to name a few. If you are running Arduino on Windows, you can read the below
instructions (if you’ve never connected an FTDI device to your computer before, you may need to
install drivers for the USB-to-Serial converter)

PROCEDURE:
. Before run and compile the program we have the ESP32 IN ARDUINO IDE

Installing ESP32 Add-on in Arduino IDE:


To install the ESP32 board in your Arduino IDE, follow these next instructions:

1. In your Arduino IDE, go to File> Preferences


2. Enter https://dl.espressif.com/dl/package_esp32_index.json into the “Additional Board
Manager URLs” field as shown in the figure below. Then, click the “OK” button:
Note: if you already have the ESP8266 boards URL, you can separate the URLs with a
comma as follows:
https://dl.espressif.com/dl/package_esp32_index.json,
http://arduino.esp8266.com/stable/package_esp8266com_index.json

3. Open the Boards Manager. Go to Tools > Board > Boards Manager…
4. Search for ESP32 and press install button for the “ESP32 by Espressif Systems“:
5. That’s it. It should be installed after a few seconds.

Testing the Installation:


Plug the ESP32 board to your computer. With your Arduino IDE open, follow these steps:
1. Select your Board in Tools > Board menu (in my case it’s the DOIT ESP32 DEVKIT V1)

2. Select the Port (if you don’t see the COM Port in your Arduino IDE, you need to install
the CP210x USB to UART Bridge VCP Drivers):
3. Open the following example under File > Examples > WiFi (ESP32) > WiFiScan
. write the code on ARUDINO IDE and compile it
. and dump the code
. then send a message to server

Code:
#include"esp_http_client.h"
#include<WiFi.h>
#include"Arduino.h"

constchar*ssid="NSA";
constchar*password="Orange";

constchar*post_url="http://your-webserver.net/yourscript.php";// Location to send POSTed data


constchar*post_data="field1=value1&field2=value2"; // Post data can be name value, or just value

boolinternet_connected=false;

voidsetup()
{
Serial.begin(115200);

if(init_wifi()){// Connected to WiFi


internet_connected=true;
Serial.println("Internet connected");
}
}

boolinit_wifi()
{
intconnAttempts=0;
Serial.println("\r\nConnecting to: "+String(ssid));
WiFi.begin(ssid,password);
while(WiFi.status()!=WL_CONNECTED){
delay(500);
Serial.print(".");
if(connAttempts>10)returnfalse;
connAttempts++;
}
returntrue;
}

esp_err_t_http_event_handler(esp_http_client_event_t*evt)
{
switch(evt->event_id){
caseHTTP_EVENT_ERROR:
Serial.println("HTTP_EVENT_ERROR");
break;
caseHTTP_EVENT_ON_CONNECTED:
Serial.println("HTTP_EVENT_ON_CONNECTED");
break;
caseHTTP_EVENT_HEADER_SENT:
Serial.println("HTTP_EVENT_HEADER_SENT");
break;
caseHTTP_EVENT_ON_HEADER:
Serial.println();
Serial.printf("HTTP_EVENT_ON_HEADER, key=%s, value=%s",evt->header_key,evt-
>header_value);
break;
caseHTTP_EVENT_ON_DATA:
Serial.println();
Serial.printf("HTTP_EVENT_ON_DATA, len=%d",evt->data_len);
if(!esp_http_client_is_chunked_response(evt->client)){
// Write out data
// printf("%.*s", evt->data_len, (char*)evt->data);
}
break;
caseHTTP_EVENT_ON_FINISH:
Serial.println("");
Serial.println("HTTP_EVENT_ON_FINISH");
break;
caseHTTP_EVENT_DISCONNECTED:
Serial.println("HTTP_EVENT_DISCONNECTED");
break;
}
returnESP_OK;
}

staticesp_err_tpost_something()
{
esp_err_tres=ESP_OK;

esp_http_client_handle_thttp_client;

esp_http_client_config_tconfig_client={0};
config_client.url=post_url;
config_client.event_handler=_http_event_handler;
config_client.method=HTTP_METHOD_POST;

http_client=esp_http_client_init(&config_client);

esp_http_client_set_post_field(client,post_data,strlen(post_data));

// esp_http_client_set_header(http_client, "Content-Type", "image/jpg"); // sending a jpg file

esp_err_terr=esp_http_client_perform(http_client);
if(err==ESP_OK){
Serial.print("esp_http_client_get_status_code: ");
Serial.println(esp_http_client_get_status_code(http_client));
}

esp_http_client_cleanup(http_client);
}

voidloop()
{
if(conditionmet){
post_something();
}
}

On the server side assuming you are using PHP you use this code to name and save files:

1 $received = file_get_contents('php://input');
2 $fileToWrite = "upload - ".time().".jpg";
3 file_put_contents($fileToWrite, $received);
This code below will send a received file to your email address. You need to update the email
address in lines 6 and 27. If you are not sending a JPG you need to change line 20 to reflect the
content type.

$received = file_get_contents('php://input');
$timeNow = date("F j, Y, g:i a");
$subject = "Email Subject - ".time();

$bound_text = "----*%$!$%*";
$bound = "--".$bound_text."\r\n";
$bound_last = "--".$bound_text."--\r\n";

$headers = "From: youremail@host.com\r\n";


$headers .= "MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed; boundary=\"$bound_text\""."\r\n" ;
$message =
'Content-Type: text/html; charset=UTF-8'."\r\n".
'Content-Transfer-Encoding: 7bit'."\r\n\r\n".
'
<html>
<head>
</head>
<body>
</body>
</html>'."\n\n".
$bound;

$message .= "Content-Type: image/jpeg; name=\"filename.jpg\"\r\n"


."Content-Transfer-Encoding: base64\r\n"
."Content-ID: <filename.jpg>\r\n"
."\r\n"
.chunk_split(base64_encode($received))
.$bound_last;

echo mail('youremail@yourhost.net', $subject, $message, $headers);


RESULT:

VIVA:
1. What is a server?
2. What is the library file is used in ARDUINO IDE for ESP32 and how to install it?
3. Why we must install new libraries in ARDUINO IDE?
4. How the ESP32 works?
5. How many pins in ESP32 and how many PWM pins and how many analogue pins?
LAB SESSION 07 : SERVO MOTOR
CONTROL WITH WEBPAGE

Date oftheSession: / / Time ofthe Session: to

Prerequisite:
 General idea of microcontrollers like Arduino.
 General idea how a NodeMCU works.

In-Lab:

OBJECTIVE:To interface servo motor to ESP32 and control fromwebpage.


COMPONENTS REQUIRED:
 ESP32 board
 Arduino IDE
 Servo Motor
 Breadboard
 Connecting wires
 USB Cable

SOFTWARE REQUIREMENTS: 1)Arduino IDE


2) Webpage
PRE-LAB WORK :
ESP32 is a series of low-cost, low-power system on
achip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. The
ESP32 series employs a Tensilica Xtensa LX6 microprocessor in both dual-core
and single-core variations and includes built-in antenna switches, RF balun, power
amplifier, low-noise receive amplifier, filters, and power-management modules.
ESP32 is created and developed by Espressif Systems, a Shanghai-based Chinese
company, and is manufactured by TSMC using their 40 nm process.[2] It is a
successor to the ESP8266 microcontroller.
ESP32 Peripherals Features :
 18 Analog-to-Digital
Digital Converter (ADC) channels

 10 Capacitive sensing GPIOs

 3 UART interfaces

 3 SPI interfaces

 2 I2C interfaces

 16 PWM output channels

 2 Digital-to-Analog Converters (DAC)

 2 I2S interfaces

SERVO MOTOR:
You can position the servo’s shaft in various angles from 0 to 180º. Servos are controlled using
a pulse width modulation (PWM) signal. This means that the PWM signal sent to the motor
will determine the shaft’s
ft’s position.Servo motors have three wires: power, ground, and signal.
The power is usually red, the GND is brown, and the signal wire is usually orange
 GND -> ESP32 GND pin;
 Power -> ESP32 VIN pin;
 Signal -> GPIO 13 (or any PWM pin).
CIRCUIT DIAGRAM :

:
Fig:circuit diagram of servo motor interfacing with ESP32

CODE :
#include<WiFi.h>
#include<Servo.h>

ServoObjServo;// Make object of Servo motor from Servo library


// Objects are made for every servo motor,we want to control through this library

staticconstintServoGPIO=13;// define the GPIO pin with which servo is connected

// Variables to store network name and password


constchar*ssid="PTCL-BB";// Enter your network name
constchar* password ="5387c614";//Enter your network password

// Set the server port nunber to deafualt 80


WiFiServerserver(80);

// this variable header stores the HTTP requests data


String header;

// These variables used to store slider position


StringvalueString=String(0);
int positon1 =0;
int positon2 =0;

void setup()
{
Serial.begin(115200);//define serial commuination with baud rate of 115200
ObjServo.attach(ServoGPIO);// it will attach the ObjServo to ServoGPIO pin which is 13
Serial.print("Making connection to ");// it will display message on serial monitor
Serial.println(ssid);
WiFi.begin(ssid, password);
while(WiFi.status()!= WL_CONNECTED){
delay(500);
Serial.print(".");
}
// These lines prints the IP address value on serial monitor
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();// It will start the servo motor with given position value.
}

void loop(){
WiFiClient client =server.available();// Listen for incoming clients

if(client)
{// If a new client connects,

String header =client.readStringUntil('\r');


client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();

// Display the HTML web page


client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-
scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial; margin-
left:auto; margin-right:auto;}");
client.println(".slider { width: 300px; }</style>");
client.println("<script
src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>");

// Web Page
client.println("</head><body><h1>ESP32 with Servo</h1>");
client.println("<p>Position: <span id=\"servoPos\"></span></p>");
client.println("<input type=\"range\" min=\"0\" max=\"180\" class=\"slider\" id=\"servoSlider\"
onchange=\"servo(this.value)\" value=\""+valueString+"\"/>");

client.println("<script>var slider = document.getElementById(\"servoSlider\");");


client.println("varservoP = document.getElementById(\"servoPos\"); servoP.innerHTML =
slider.value;");
client.println("slider.oninput = function() { slider.value = this.value; servoP.innerHTML =
this.value; }");
client.println("$.ajaxSetup({timeout:1000}); function servo(pos) { ");
client.println("$.get(\"/?value=\" + pos + \"&\"); {Connection: close};}</script>");

client.println("</body></html>");

//GET /?value=180& HTTP/1.1


if(header.indexOf("GET /?value=")>=0)
{
positon1 =header.indexOf('=');
positon2 =header.indexOf('&');
valueString=header.substring(positon1+1, positon2);

//Rotate the servo


ObjServo.write(valueString.toInt());
Serial.println(valueString);
}

header ="";
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}

WEBPAGE CODE :
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<style>
body {
text-align: center;
font-family: "Trebuchet MS", Arial;
margin-left:auto;
margin-right:auto;
}
.slider {
width: 300px;
}
</style>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<h1>ESP32 with Servo</h1>
<p>Position: <span id="servoPos"></span></p>
<input type="range" min="0" max="180" class="slider" id="servoSlider"
onchange="servo(this.value)"/>
<script>
var slider = document.getElementById("servoSlider");
varservoP = document.getElementById("servoPos");
servoP.innerHTML = slider.value;
slider.oninput = function() {
slider.value = this.value;
servoP.innerHTML = this.value;
}
$.ajaxSetup({timeout:1000});
function servo(pos) {
$.get("/?value=" + pos + "&");
{Connection: close};
}
</script>
</body>
</html>

PROCEDURE :

 Download the ESP32 libraries for ARDUINO IDE SOFTWARE, after add
the library connect the board
 Write the code in ARDUINO IDE then compile the program and dump in to
the ESP32 board
 Make the connection as per circuit diagram
 Signal wire connect to PWM pin,Vcc connect to vin and GND connect to
GND
 Now go to online HTML compiler and compile the code given above then
created a wedpage
 Webpage have a slider which is from 0 to 180 degrees by using the slider we
can control servo motor angle
 Observe the shaft of servo motor

PRECAUTIONS :
 Download library before uploading code and as well as check board and
ports in tools
 Make connections after dumped the code in ESP32
 Connect the siginal wire to only PWM pins
POST LAB :

1) Explain about PWM pins in ESP32 and what are there ?


2) What are the applications of SERVO motor?
3) How many pins are used in this experiment and what are there?
4) How can extend this experiment?
5) How many degrees it will be rotate_______________

a.0-125 b.25-125 c.0-180 d.25-125


LAB SESSION 08: TEMPERATURE AND HUMIDITY
MONITORING IN CLOUD PLATFORM.

Date oftheSession: / / Time ofthe Session: to

Prerequis
ite:
 General idea of microcontrollers like Arduino.
 General idea how a DHT11 Sensor works.

In-Lab:
OBJECTIVE:To monitor Temperature and Humidity using esp32 in cloud platform.

COMPONENTS REQUIRED:1) ESP32


2) DHT11 – Temperature and Humidity Sensor
3) Micro USB Cable
4) PC
5) Bread Board
6) Connecting Wires

SOFTWARE REQUIREMENTS:1) uPycraft.


Or
2) Arduino IDE.

PRE-LAB WORK:
ESP32 is in the series of low power and low cost on chip microcontroller. It
comes up with already integrated dual mode Bluetooth and Wi-Fi. ESP32 comes up with a USB port
so we can say that it is a plug and play device i.e. just plug in cable and your device is turned on and
you are able to program it just like Arduino development boards.
Features:
 Built in Wi-Fi module of standard 802.11 and Wi-Fi module operate in range of 2.4 GHz – 2.5
GHz.
 Three modes of operation: 1. Access point. 2. Client. 3. Access point + station.
 Dual core microprocessor of 32 – bit.
 Operating voltage is 3.3 V and Clock frequency from 80 MHz and goes up to 240 MHz.
 SRAM memory is of 512 KB and ROM memory is 448 KB.
 External flash memory is supported and is up to 32 Mb i.e. 4MB.
 It has 36 general purpose input / output pins.
 General purpose input / output pins comes up with PWM / I2C and SPI functionality.
 Bluetooth version 4.2 is available and Bluetooth low energy (BLE) version and its having 2 to
3.6 V operating voltage.
Pin Diagram:

Pin Description:
The ESP32 chip comes with 48 pins with multiple functions. 18 Analog-to-
Digital Converter (ADC) channels, 3 SPI interfaces, 3 UART interfaces,2-I2C interfaces, 16 PWM
output channels, 2 Digital-to-Analog Converters (DAC), 2 I2S interfaces, 10 Capacitive sensing
GPIOs.

DHT11 – Temperature and Humidity Sensor:


The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It
uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a
digital signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires
careful timing to grab data. The only real downside of this sensor is you can only get new data
from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds
old.
Pin Diagram of DHT11:
DHT11 Specifications:
 Operating Voltage: 3.5V to 5.5V .
 Operating current: 0.3mA (measuring) 60uA (standby).
 Output: Serial data.
 Temperature Range: 0°C to 50°C.
 Humidity Range: 20% to 90%.
 Resolution: Temperature and Humidity both are 16-bit.
 Accuracy: ±1°C and ±1%.

Step 1: ThingSpeak Setup for Temperature and Humidity Monitoring


For creating your channel on ThingSpeak you first need to sign up on ThingSpeak. In case if you already
have account on ThingSpeak just sign in using your id and password.
For creating your account go to www.thinspeak.com
Click on signup if you don’t have account and if you already have account click on sign in.
After clicking on signup fill your details.

After this verify your E-mail id and click on continue.

Step 2: Create a Channel for Your Data


Once you Sign in after your account verification, Create a new channel by clicking “New Channel” button

After clicking on “New Channel”, enter the Name and Description of the data you want to upload on this
channel. For example I am sending DHT11 sensor data (temperature and humidity), so I named it as
“DHT11”.
Enter the name of your data ‘Temperature’ in Field1 and ‘Humidity’ in Field2. If you want to use more than
one Field you can check the box next to Field option and enter the name and description of your data.
After this click on save channel button to save your details.

Step 3: API Key


To send data to ThingSpeak, we need an unique API key, which we will use later in our code to upload the
Temperature and Humidity to ThingSpeak Website.
Click on “API Keys” button to get your unique API key for uploading DHT11 sensor data.
Now copy your “Write API Key”. We will use this API key in our code.
After this, navigate to your Thingspeak page and open your channel in ThingSpeak and output will be
shown as below.

POST-LAB REQUIREMENTS:
 Observe the OUTPUT and note down the readings carefully.
 Apply this concepts to make our projects or Applications.
 Submit practical report in next lab for correction.
CODE:
#include <DHT.h>

#include <ESP8266WiFi.h>

String apiKey = "Your API KEY"; // Enter your Write API key here

const char *ssid = "WiFi Name"; // Enter your WiFi Name

const char *pass = "WiFi Password"; // Enter your WiFi Password

const char* server = "api.thingspeak.com";

#define DHTPIN 4 // GPIO Pin where the dht11 is connected

DHT dht(DHTPIN, DHT11);

WiFiClient client;

void setup()

Serial.begin(115200);

delay(10);

dht.begin();

Serial.println("Connecting to ");

Serial.println(ssid);

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED)

delay(550);

Serial.print(".");

Serial.println("");

Serial.println("WiFi connected");

}
void loop()

float h = dht.readHumidity();

float t = dht.readTemperature();

if (isnan(h) || isnan(t))

Serial.println("Failed to read from DHT sensor!");

return;

if (client.connect(server,80))

String postStr = apiKey;

postStr +="&field1=";

postStr += String(t);

postStr +="&field2=";

postStr += String(h);

postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n");

client.print("Host: api.thingspeak.com\n");

client.print("Connection: close\n");

client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");

client.print("Content-Type: application/x-www-form-urlencoded\n");

client.print("Content-Length: ");

client.print(postStr.length());

client.print("\n\n");

client.print(postStr);

Serial.print("Temperature: ");
Serial.print(t);

Serial.print(" degrees Celcius, Humidity: ");

Serial.print(h);

Serial.println("%. Send to Thingspeak.");

client.stop();

Serial.println("Waiting...");

delay(10000);

CIRCUIT DIAGRAM:

PROCEDURE:
6. Make the connections as per the circuit diagram.
7. Check the ground connection precisely before switching on the power supply.
8. Connect Micro USB Cable to PC .
9. Write the Code in Python or C/C++ accordingly .
10. Run the code through Arduino IDE or uPycraft IDE and Observe the output.

PRECAUTIONS:
1. Check the sensor is working properly.
2. Check the connections are properly connected.
3. See that there are no errors in the code.
4. Check whether Ground and VCC connections are connected properly.

RESULT:Successfully implemented & monitored temperature and humidity in cloud platform


using ESP32.
Lab Session 09: WIFI WEATHER STATION
TOOL AND ANALYSIS

Date oftheSession: / / Time oftheSession:to

Prerequisite:
 General idea of microcontrollers like Arduino.
 General idea about Wifi cloud and analysis.

In-Lab:
OBJECTIVE:
To build a WiFI weather station using ESP8266 (NodeMCU) &Blynk app

COMPONENTS REQUIRED:
 NodeMCU
 DHT11 sensor
 Breadboard
 Connecting wires
 MicroUSB cable

SOFTWARE REQUIRED:
Arduino IDE, Blynk app

PRE-LAB WORK:

NodeMCU
NodeMCU is an open source IoT platform.It includes firmware which runs on
the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12
module.The ESP8266 NodeMcuisa complex device, which combines some features of the ordinary
Arduino board with the possibility of
connecting to the internet.
NodeMCU is a Tensilica 32-bit RISC CPU Xtensa LX106 Microcontroller. Its Operating
Voltage is 3.3V &amp; Input Voltage is 7-12V. Its having 16 Digital I/O Pins &amp; 1 Analog
Input Pin (ADC). Its having Flash Memory of 4MB &amp; SRAM 64KB. NodeMCU having clock
speed of 80 Mhz.
The interface of the module is mainly divided into two parts including both Firmware and
Hardware where former runs on the ESP8266 Wi-Fi SoC and later is based on the ESP-12 module.

PIN DIAGRAM:
PIN DISCRIPTION:

1) Power Pin: There are four power pins viz. one VIN pin &amp; three 3.3V pins. The VIN
pin can be used to directly supply the ESP8266 and its peripherals, if you have a regulated
5V voltage source. The 3.3V pins are the output of an on-board voltage regulator.These pins
can be used to supply power to external components.
2) GND : GND is a ground pin of ESP8266 NodeMCU development board.
3) I2C Pins: I2C Pins are used to hook up all sorts of I2C sensors and peripherals in your
project. Both I2C Master and I2C Slave are supported. I2C interface functionality can be
realized programmatically, and the clock frequency is 100 kHz at a maximum. It should be
noted that I2C clock frequency should be higher than the slowest clock frequency of the
slave device.
4) GPIO Pins: ESP8266 NodeMCU has 17 GPIO pins which can be assigned to various
functions such as I2C, I2S, UART, PWM, IR Remote Control, LED Light and Button
programmatically. Each digital enabled GPIO can be configured to internal pull-up or pull-
down, or set to high impedance. When configured as an input, it can also be set to edge-
trigger or level-trigger to generate CPU interrupts.
5) ADC Channel: The NodeMCU is embedded with a 10-bit precision SAR ADC. The two
functions can be implemented using ADC viz. Testing power supply voltage of VDD3P3
pin and testing input voltage of TOUT pin. However, they cannot be implemented at the
same time.
6) UART Pins: ESP8266 NodeMCU has 2 UART interfaces, i.e. UART0 and UART1, which
provide asynchronous communication (RS232 and RS485), and can communicate at up to
4.5 Mbps. UART0 (TXD0, RXD0, RST0 &amp; CTS0 pins) can be used for
communication. It supports fluid control. However, UART1 (TXD1 pin) features only data
transmit signal so, it is usually used for printing log.
7) SPI Pins: ESP8266 features two SPIs (SPI and HSPI) in slave and master modes. These
SPIs also support the following general-purpose SPI features:
a) 4 timing modes of the SPI format transfer.
b) Up to 80 MHz and the divided clocks of 80 MHz.
c) Up to 64-Byte FIFO.
8) SDIO Pins: ESP8266 features Secure Digital Input/Output Interface (SDIO) which is used
to directly interface SD cards. 4-bit 25 MHz SDIO v1.1 and 4-bit 50 MHz SDIO v2.0 are
supported.
9) PWM Pins: The board has 4 channels of Pulse Width Modulation (PWM). The PWM
output can be implemented programmatically and used for driving digital motors and LEDs.
PWM frequency range is adjustable from 1000 μs to 10000 μs, i.e., between 100 Hz and 1
kHz.
10) Control Pins: Control Pins are used to control ESP8266. These pins include Chip Enable
pin (EN), Reset pin (RST) and WAKE pin. EN pin – The ESP8266 chip is enabled when
EN pin is pulled HIGH. When pulled LOW the chip works at minimum power. RST pin –
RST pin is used to reset the ESP8266 chip. WAKE pin – Wake pin is used to wake the chip
from deep-sleep.

DHT11:
DHT11 digital temperature and humidity sensor is a calibrated digital signal output of the
temperature and humidity combined sensor. It uses a dedicated digital modules capture technology
and the temperature and humidity sensor technology to ensure that products with high reliability
and excellent long-term stability. Sensor includes a resistive element and a sense of wet NTC
temperature measurement devices, and with a high-performance 8-bit microcontroller connected .
The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a
capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital
signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires careful
timing to grab data.
The DHT11 calculates relative humidity by measuring the electrical resistance between two
electrodes. The humidity sensing component of the DHT11 is a moisture holding substrate with the
electrodes applied to the surface.
A humidity sensor (or hygrometer) senses, measures and reports both moisture and
air temperature. ... Relative humidity becomes an important factor, when looking for comfort. A
sample humidity sensor. Humidity sensors work by detecting changes that alter electrical currents
or temperature in the air

Communication with Microcontroller

 DHT11 uses only one wire for communication. The voltage levels with certain time value
defines the logic one or logic zero on this pin.
 The communication process is divided in three steps, first is to send request to DHT11
sensor then sensor will send response pulse and then it starts sending data of total 40 bits to
the microcontroller.

Communication process
Data format:
The 8bit humidity integer data + 8bit the Humidity decimal data +8 bit temperature
temperatur integer
data + 8bit fractional temperature data +8 bit parity bit.
Parity bit data definition
“8bit humidity integer data + 8bit humidity decimal data +8 bit temperature integer data +
8bit temperature fractional data” 8bit checksum is equal to the res
results
ults of the last eight.

Example 1:

Calculate: 0011 0101+0000 0000+0001 1000+0000 0000= 0100 1101


Received data is correct:
Humidity:0011 0101=35H=53%RH
Temperature:0001 1000=18H=24℃ ℃

BLYNK :
Blynk was designed for the Internet of Things. It can control hardware remotely, it can
display sensor data, it can store data, vizualize it and do many other cool things.
There are three major components in the platform:
 Blynk App - allows to you create amazin
amazing
g interfaces for your projects using various widgets we
provide.
 Blynk Server - responsible for all the communications between the smartphone and hardware.
You can use our Blynk Cloud or run your private Blynk server locally. It’s open-source,
open could
easily handle thousands of devices and can even be launched on a Raspberry Pi.
 Blynk Libraries - for all the popular hardware platforms - enable communication with the
server and process all the incoming and out coming commands.
Now imagine every time you press a Button in the Blynk app, the message travels to theBlynk
Cloud, where it magically finds its way to your hardware. It works the same in the opposite
direction and everything happens in a blynk of an eye.
Getting Started With TheBlynk App
1) Create a Blynk Account
2) Create a new project
3) Choose your hardware
4) Auth Token
5) Add a widget
6) Run the project

CIRCUIT DIAGRAM :
PROCEDURE:

1) Make the connections as per the circuit diagram.


2) Check the ground connection precisely before switching on the power supply.
3) Connect Micro USB Cable to PC .
4) Write the Code in Python or C/C++ accordingly .
5) Run the code through Arduino IDE and Observe the output.

CODE:
* theTechnowright
* Complete Project Details www.youtube.com/thetechnowright
*/

// Include the correct display library


// For a connection via I2C using Wire include
#include <Wire.h>
#include "SSD1306.h"
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.


// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Your WiFi credentials.


// Set password to "" for open networks.
charssid[] = "XXXX";
char pass[] = "XXXXXX";

#include <DHT.h>

#define DHTPIN 4 // what pin we're connected to


#define DHTTYPE DHT11 // DHT 11

// Initialize the OLED display i2C


// D3 -> SDA
// D5 -> SCL

// Initialize the OLED display using Wire library


SSD1306 display(0x3C, D3, D5);

DHT dht(DHTPIN, DHTTYPE);


BlynkTimer timer;
void setup(){
Serial.begin(115200);
// Initialising the UI will init the display too.
display.init();

display.flipScreenVertically();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_LEFT);
dht.begin(); // initialize dht

Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8080);


timer.setInterval(1000L, sendSensor);
}

voiddisplayWeather(){ //Creating a function to read and display temperature and humidity on


OLED display
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)){
display.clear(); // clearing the display
display.drawString(5,0, "DHT Failed!");
return;
}
display.clear();
display.drawString(30, 0, "Weather");
display.drawString(0, 20, "Humidity: " + String(h) + "%\t");
display.drawString(0, 40, "Temp: " + String(t) + "°C");
//Uncomment to get temperature in farenheit
//display.drawString(0, 40, "Temp: " + String(f) + "°F");

}
void loop(){
Blynk.run(); // Running the blynk code
displayWeather(); //Calling back the displayWeather function
display.display();
timer.run();
}

voidsendSensor()
{
float h = dht.readHumidity(); //Read the humidity
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
}

RESULT:
We have successfully designed the weather station using NodeMCU and the Blynk app
LAB SESSION 10: Temperature and Humidity Monitoring with
Raspberry Pi

Date oftheSession: / / Time ofthe Session: to

Prerequisite:

 General idea of microcontrollers like Arduino.


 Greneral idea of sensors.

In-Lab:
OBJECTIVE:To display the temperature and humidity in pc screen

COMPONENTS REQUIRED:
 connecting wires
 micro USB cable
 pc
 DTH11 Sensor
 Rasspberry pi.

SOFTWARE REQUIREMENTS:1) Micro-Python.

Pre-Lab Work:
Raspberry Pi 3 Model B was released in February 2016 with a 1.2 GHz 64-bit quad core processor,
on-board 802.11n Wi-Fi, Bluetooth and USB boot capabilities. On Pi Day 2018 the Raspberry Pi 3
Model B+ was launched with a faster 1.4 GHz processor and a three-times faster gigabit
Ethernet (throughput limited to ca. 300 Mbit/s by the internal USB 2.0 connection) or 2.4 /
5 GHz dual-band 802.11ac Wi-Fi (100 Mbit/s). Other features are Power over Ethernet (PoE), USB
boot and network boot (an SD card is no longer required).

An SD card inserted into the slot on the board acts as the hard drive for the Raspberry Pi. It is
powered by USB and the video output can be hooked up to a traditional RCA TV set, a more
modern monitor, or even a TV using the HDMI port.

Raspbian comes preloaded with Python, the official programming language of the Raspberry Pi and
IDLE 3, a Python Integrated Development Environment.
Pin description:

Pin diagram DTH11:

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive
humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the
data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab
data
The DHT11 calculates relative humidity by measuring the electrical resistance between two
electrodes. The humidity sensing component of the DHT11 is a moisture holding substrate with the
electrodes applied to the surface.
A humidity sensor (or hygrometer) senses, measures and reports both moisture and air temperature.
... Relative humidity becomes an important factor, when looking for comfort. A sample humidity
sensor. Humidity sensors work by detecting changes that alter electrical currents or temperature in
the air

Code:
import RPi.GPIO as GPIO
import dht11
import time

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#GPIO.cleanup()

# read data using Pin GPIO18


instance = dht11.DHT11(pin=12)

while True:
result = instance.read()
if result.is_valid():
print("Temp: %d C" % result.temperature +' '+"Humid: %d %%" % result.humidity)

time.sleep(1)

Circuit Diagram:

Procedure:
 Make the connections as per the circuit diagram.
 Check the ground connection precisely before switching on the power supply.
 Connect Micro USB Cable to PC .
 Write the Code in Python or C/C++ accordingly .
 Run the code through Arduino IDE or uPycraft IDE and Observe the output.

Result:Successfully implemented & we can observe temperature and humidity on pc display.

Post-Lab Requirements:
 Observe the OUTPUT and note down the readings carefully.
 Apply the required voltage for the board.
LAB SESSION 11: TEMPERATUREAND HUMIDITY
MONITORINGWITH RASPBERRY Pi AND SERVO MOTOR

Date oftheSession: / / Time ofthe Session: to

Prerequisite:
 General idea of microcontrollers like Arduino.
 General idea about motor.
In-Lab:

OBJECTIVE:
To open a window by using DTH11 sensor at certain temperature by using servo motor.

COMPONENTS REQUIRED:
1) Raspberry Pi Model B
2) DHT11 sensor
3)micro USB cable
4)connecting wires
5)servo motor
6) pc

SOFTWARE REQUIREMENTS:1) Micro-Python.

PRE-LAB WORK:
Raspberry Pi 3 Model B was released in February 2016 with a 1.2 GHz 64-bit quad core processor,
on-board 802.11n Wi-Fi, Bluetooth and USB boot capabilities. On Pi Day 2018 the Raspberry Pi 3
Model B+ was launched with a faster 1.4 GHz processor and a three-times faster gigabit
Ethernet (throughput limited to ca. 300 Mbit/s by the internal USB 2.0 connection) or 2.4 /
5 GHz dual-band 802.11ac Wi-Fi (100 Mbit/s). Other features are Power over Ethernet (PoE), USB
boot and network boot (an SD card is no longer required).

An SD card inserted into the slot on the board acts as the hard drive for the Raspberry Pi. It is
powered by USB and the video output can be hooked up to a traditional RCA TV set, a more
modern monitor, or even a TV using the HDMI port.

Raspbian comes preloaded with Python, the official programming language of the Raspberry Pi and
IDLE 3, a Python Integrated Development Environment.
Pin description:

Pin diagram DTH11:

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive
humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the
data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab
data
The DHT11 calculates relative humidity by measuring the electrical resistance between two
electrodes. The humidity sensing component of the DHT11 is a moisture holding substrate with the
electrodes applied to the surface.
A humidity sensor (or hygrometer) senses, measures and reports both moisture and
air temperature. ... Relative humidity becomes an important factor, when looking for comfort. A
sample humidity sensor. Humidity sensors work by detecting changes that alter electrical
currents or temperature in the air

Pin diagram SERVO motor:

A servomotor is a rotary actuator or linear actuator that allows for precise control of angular or
linear position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for
position feedback. ... Servomotors are used in applications such as robotics, CNC machinery or
automated manufacturing.

About:
To open a window, I use a servo with a longer wooden staff attached to the axis. In the initial state,
the angle should be 0°. If you are unsure, you should set the servo once per script to 0° and then
attach.

The temperature value is used for control purposes. For this, we still have to connect the DHT11
temperature sensor to GPIO 27, while the servo motor is connected to GPIO 22. Since the engine
probably needs more than 3.3V (see the data sheet, if you are unsure), we connect it to the 5V
voltage.

I have the DHT sensor simply attached to the water resistant housing (next point). To change the
temperature at which the hatch is to be opened, you can change the initial settings.
CODE:
defcheckWindow():
# read remperature
humidity, temperature = Adafruit_DHT.read_retry(SETTINGS["DHT_SENSOR"],
SETTINGS["DHT_GPIO"])

GPIO.setup(SETTINGS["SERVO_GPIO"],
(SETTINGS["SERVO_GPIO"], GPIO.OUT)
pwm = GPIO.PWM(SETTINGS["SERVO_GPIO"], 50)

if temperature > SETTINGS["TEMP_THRESHOLD"]:


# open window
angle = float(SETTINGS["SERVO_OPEN_ANGLE"]) / 20.0 + 2.5
pwm.start(angle)
else:
# close window
pwm.start(2.5)
# save current
time.sleep(2)
pwm.ChangeDutyCycle(0)

CIRCUIT DIAGRAM:

PROCEDURE:
 Make the connections as per the circuit diagram.
 Check the ground connection precisely before switching on the power supply.
 Connect Micro USB Cable to PC .
 Motor is to be in inverted position.
 Write the Code in Python or C/C++ accordingly .
 Run the code through Arduino IDE or uPycraft IDE and Observe the output.

Result:Successfully implemented & for a particular te


temperature
mperature the window will opens
LAB SESSION 12: DIRECTION CONTROL OF A 3D
MODELWITH REFFERENCE TO MPU6050 ORIENTATION

Date oftheSession: / / Time ofthe Session: to

Prerequis
ite:
 General idea of microcontrollers like Arduino.
 General idea how a gyroscope works.

In-Lab:
OBJECTIVE:To Control a 3d model with reference to MPU6050 Orientation

COMPONENTS REQUIRED:1) ARDUINO UNO – 1


2)MPU 6050 -1
3) Micro USB Cable – 1
4) PC – 1
5) Connecting Wires.
6)Bread Board.

SOFTWARE REQUIREMENTS:1)uPycraft.
Or
2) Arduino IDE.
3)Processing 3

PRE-LAB WORK:
The Arduino Integrated Development Environment is a cross-platform application that is written in
functions from C and C++. It is used to write and upload programs to Arduino compatible boards. The
MPU-6050 devices combine a 3-axis gyroscope and a 3-axis accelerometer on the same silicon die, together
with an onboard Digital Motion Processor™ (DMP™), which processes complex 6-axis Motion Fusion
algorithms. The device can access external magnetometers or other sensors through an auxiliary master I²C
bus, allowing the devices to gather a full set of sensor data without intervention from the system processor.
Features:
 Microcontroller: ATmega328
 Operating Voltage: 5V
 Input Voltage (recommended): 7-12V
 Input Voltage (limits): 6-20V
 Digital I/O Pins: 14 (of which 6 provide PWM output)
 Analog Input Pins: 6
 DC Current per I/O Pin: 40 mA
 DC Current for 3.3V Pin: 50 mA
 Flash Memory: 32 KB of which 0.5 KB used by bootloader
b
 SRAM: 2 KB (ATmega328)
 EEPROM: 1 KB (ATmega328)
 Clock Speed: 16 MHz

Pin Diagram:
Pin Description:
ARDUINO:-

Arduino Uno comes with USB interface, 6 analog input pins, 14 I/O digital ports that are used to connect
with external electronic circuits.
Out of 14 I/O ports, 6 pins can be used for PWM output.

MPU6050:-
 Vcc: -Provides power for the module, can be +3V to +5V. Typically +5V is used
 Ground: -Connected to Ground of system
 Serial Clock (SCL):-Used for providing clock pulse for I2C Communication
 Serial Data (SDA):-Used for transferring Data through I2C communication
 Auxiliary Serial Data (XDA):-Can be used to interface other I2C modules with MPU6050. It is
optional
 Auxiliary Serial Clock (XCL):-Can be used to interface other I2C modules with MPU6050. It is
optional
 AD0:-If more than one MPU6050 is used a single MCU, then this pin can be used to vary the address
 Interrupt (INT):-Interrupt pin to indicate that data is available for MCU to read.

POST-LAB REQUIREMENTS:
 Observe the OUTPUT and note down the readings carefully.
 Apply this concept to make projects or Applications.
 Submit practical report in next lab for correction.

CODE:
CIRCUIT DIAGRAM:

PROCEDURE:

6. Make the connections as per the circuit diagram.


7. Check the ground connection precisely before switching on the power supply.
8. Connect Micro USB Cable to PC.
9. Install i2c dev and mpu6050 libraries.
10. Arduino libraries to obtain the accelerometer / gyro data and handle all the calculations. They are
available as a zip file from here:
https://github.com/jrowberg/i2cdevlib/zipball/master
11. Find the Arduino folder within it and copy the two folders "I2Cdev" and "MPU6050" over to your
Arduino "libraries" folder in the following directory:
C:\Program Files (x86)\Arduino\libraries
12. Then open the Arduino IDE and in the examples section, you should find MPU6050_DMP6 within
MPU6050.
13. Open it, plug your arduino in, select the appropriate COM Port and upload the sketch.
14. In the Serial Window, select a baud rate of 115200. You should be prompted that the MPU6050
connection was successful.
15. You can test the data collection by typing anything in the text bar and pressing enter, the data should
start showing up.
16. Now we want to set the code to run the teapot demo to show the 3D simulation.
17. Close the serial window, then find and comment out the line #define
OUTPUT_READABLE_YAWPITCHROLL and uncomment the line //#define
OUTPUT_TEAPOT. Select "save as" and choose where you want to save the modified code. Upload
again but don't open the serial window this time.
18. Download & Install Latest Version of Processing &ToxicLibs Library.
19. The "libraries" folder of Processing can be found by following (starting from within the processing
folder): modes -> java -> libraries. Unzip ToxicLibs and place ALL the contents there.
20. Last of all, open the Processing application file and then: -File -> Open -> follow this directory
21. C:\Program Files
(x86)\Arduino\libraries\MPU6050\Examples\MPU6050_DMP6\Processing\MPUTeapot
22. and open the MPUTeapot file.
23. Click the play button and the system should calibrate for about 20-30 seconds, leave the gyro
stationary during that period.
24. Now pick up the gyro and test out the yaw / pitch / roll.

PRECAUTIONS:
1.Check the sensor is working properly.
2.Check the connections are properly connected.
3.See that there are no errors in the code.
4. Check whether Ground and VCC connections are connected properly.

RESULT:Successfully implemented and learned how to Control a 3d model with reference to


MPU6050 Orientation.

You might also like