100% found this document useful (1 vote)
548 views40 pages

IoT Lab Manual

This document contains a lab manual for the Internet of Things subject. It provides an introduction to the ESP-WROOM-32 development board and the Arduino IDE software. It describes the key components of the ESP-WROOM-32 board including the CPU, memory, I/O pins, and power supply. It also outlines 8 experiments involving interfacing different sensors and devices to the ESP-WROOM-32 board using the Arduino IDE. The experiments include turning on an LED based on sensor input and uploading sensor data to the cloud.

Uploaded by

rahul2480
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
548 views40 pages

IoT Lab Manual

This document contains a lab manual for the Internet of Things subject. It provides an introduction to the ESP-WROOM-32 development board and the Arduino IDE software. It describes the key components of the ESP-WROOM-32 board including the CPU, memory, I/O pins, and power supply. It also outlines 8 experiments involving interfacing different sensors and devices to the ESP-WROOM-32 board using the Arduino IDE. The experiments include turning on an LED based on sensor input and uploading sensor data to the cloud.

Uploaded by

rahul2480
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1

(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)


An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

LAB MANUAL
Session: 2022-23
Subject: Internet of Things
Sr.
Experiment Name
No.
1 Introduction to ESP 32 and Arduino IDE Software.
To interface Digital sensor (IR) with ESP-WROOM-32 and write a program to turn
2
ON LED at sensor detection
To interface LED with ESP-WROOM-32 and write a program to turn ON LED for 1 sec
3
after every 2 seconds
To interface Water level indicator with ESP-WROOM-32 and write a program to turn
4
ON LED at sensor detection
5 To interface DHT11 sensor with ESP-WROOM-32 and write a program to print
temperature and humidity readings on Serial monitor
Write a program on ESP-WROOM-32 to upload temperature and humidity data to the
6
cloud.
To interface Bluetooth with ESP-WROOM-32 and write a program to turn LED
7
ON/OFF when ‘1’/’0’ is received from smartphone using Bluetooth.
Write a program for making smart air pollution meters using IoT Kit and ThingSpeak
8
IoT cloud as GUI.

Subject Teacher: Dr. Rahul Pethe

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Experiment No. 1

Aim: Introduction to ESP 32 and Arduino IDE Software.

Objectives

● The concept of ESP 32 module


● The concept of Arduino IDE Software

Theory
The IoT Kit is the ideal solution for university students, providing state-of-the-art, hands-on incorporation of
IoT technology in an educational setting. It supports a lot of features which enables researchers and students to
explore different aspects and develop different applications in IoT field. The most popular protocols used for
the realization of IoT are MQTT, COAP, and HTTP. Sensors used with IoT Kit are the building blocks of the
system which can collect values of different parameters. On-Board Micro-Controller ESP32 transmits
information to cloud server, open-source IoT Platform. Cloud Server will make the values of collected
parameters available over the internet so that they are globally accessible. Download AICTE Model Curriculum
of Courses at UG Level in Emerging Areas: https://www.aicte-india.org/sites/default/files/UG_Emerging.pdf

What is ESP32?
ESP32-DevKitC V4 is a small-sized ESP32-based development board produced by Espressif. Most of
the I/O pins are broken out to the pin headers on both sides for easy interfacing. Developers can either
connect peripherals with jumper wires or mount ESP32-DevKitC V4 on a breadboard. To cover a
wide range of user requirements, the following versions of ESP-32 DevKitC v4 are available:
1. ESP-WROOM-32
2. ESP-WROOM-32D
3. ESP-WROOM-32U
4. ESP-SOLO-1
5. ESP-WROVER
6. ESP-WROVER-B
7. ESP-WROVER-I
8. ESP-WROVER-B(IPEX)
For more details on ESP-WROOM-32 click on the link
below- https://docs.espressif.com/projects/esp-idf/en/latest/hw-reference/get-started-devkitc.html

ESP-WROOM-32 Development Board

Features of Node MCU:


Department of First Year Engineering Internet of Things Lab
By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

 It is a Tensilica 32-bit RISC CPU Xtensa LX106 Microcontroller.


 Its Operating Voltage is 3.3V & Input Voltage is 7-12V.
 It’s having 16 Digital I/O Pins & 1 Analog Input Pin (ADC).
 It’s having Flash Memory of 4MB & SRAM 64KB. Node MCU having clock speed of 80
Mhz.
 Operating temperature range -40C ~ 125C.
 Modes of operation: Client, Access point, Client + Access point.

The interface of the module is mainly divided into two parts including both Firmware and Hardware

Key
Description
Component

ESP32-
A module with ESP32 at its core.
WROOM-32
EN Reset button.
Download button. Holding down Boot and then pressing EN initiates
Boot
Firmware Download mode for downloading firmware through the serial port.
USB-to-
Single USB-UART bridge chip provides transfer rates of up to 3 Mbps.
UART Bridge
Micro USB USB interface. Power supply for the board as well as the communication
Port interface between a computer and the ESP32 module.
5V Power On Turns on when the USB or an external 5V power supply is connected to the
LED board. For details see the schematics in Related Documents.
Most of the pins on the ESP module are broken out to the pin headers on the
I/O board. You can program ESP32 to enable multiple functions such as PWM,
ADC, DAC, I2C, I2S, SPI, etc.
where former runs on the ESP8266 Wi-Fi SoC and later is based on the ESP-12 module.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 4
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

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 Node MCU 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 Node MCU 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 Node MCU 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 Node MCU 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

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 5
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

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.

Arduino IDE Software


Given below is a snapshot of the Arduino IDE which is used to program the ESP-WROOM-32. To
download Arduino IDE click on the link below- https://www.arduino.cc/en/Main/Software
Once the file is downloaded, click on the file and install the software. When done with installing
software open the software and click on the tools option. Then select the board for which you are going
to write the code. After that select the port on which your ESP-WROOM-32 board is connected. You
can check the port in the device manager of your laptop or computer.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 6
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

The above screenshot is of a basic program of led blinking on arduino mega. Since we are using ESP32
so change the board to ESP32 and change the pin number to D26 for interfacing LED on IoT kit.
There are two important functions in arduino IDE:
 Void setup()- In this function, a user can declare the I/O pins as input or output. This function will
call the instructions written inside it on the start of ESP32 microcontroller or any other microcontroller
the user is using and will call only once. To declare a pin as an input or output “pinMode()” function
is used.
 Void loop()- In this function, the user can write the instructions which he/she wants to execute again
and again that are in loop. To give output to a pin “digitalWrite()” function is used and to take input
from a pin “digitalRead()” function is used.

Result
Thus we have successfully understood the concept of Node MCU 32 and Arduino IDE
Software.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 7
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Experiment No. 2

Aim To interface Digital sensor (IR) with ESP-WROOM-32 and write a program to
turn ON LED at sensor detection

Apparatus
IoT, Micro USB cable, LED, IR sensor module, jumper wires.

Theory
IR sensor is a digital sensor consisting of LM358 IC. The LM358 series consists of two independent,
high gain, internally frequency compensated operational amplifiers which were designed specifically
to operate from a single power supply over a wide range of voltages. Operation from split power
supplies is also possible and the low power supply current drain is independent of the magnitude of
the power supply voltage. Application areas include transducer amplifiers, DC gain blocks and all the
0power supply systems.

LM358 IC pin diagram


For more information on LM358 refer below link- http://www.ti.com/lit/ds/symlink/lm158-n.pdf

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 8
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

IR Sensor circuit diagram

In the IR sensor module two diodes are there, one is photodiode and other is ir diode. The IR diode
emits IR radiation and these radiations are absorbed by the photodiode, then the circuit is open circuit
and the IR sensor doesn’t give any output. When any obstacle comes in front of the IR diode and
photodiode stops absorbing radiation and the circuit becomes a closed circuit and the IR sensor gives
a digital output in the form of voltage. This output of the IR sensor is taken as digital input in the
ESP32 and when this input comes the led glows.

Circuit Diagram

IR sensor and led interfacing with ESP-32


Procedure
1. Connect ESP-WROOM-32 with your OS using a micro USB cable.
2. Follow the Steps No.2 to Step No.7 of Experiment No.2 to get installation and selection of Board.
3. Write the program given below.
Department of First Year Engineering Internet of Things Lab
By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 9
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

4. After the programming is complete click on ✓ button to compile the code so that if there is any error the
arduino IDE can detect it.

5. After compiling is done click on ⇾ button to upload the program in Arduino.


6. While uploading the code, long press the boot button on ESP32 otherwise the program will not upload in
microcontroller (ESP32).
7. Connect the circuit as shown in the circuit diagram above.
8. The Led positive leg (Longer Leg) is connected to pin D26 and the negative leg (Shorter leg) is connected to
GND and OUT pin of IR sensor to D34 of ESP-32 also VCC and GND connected to 3V3 and GND
respectively.
9. Press the EN button on ESP32 to reset ESP32.
10. Now you can see the LED glowing whenever there’s a signal from the IR sensor.
Program
#define led_pin D1
#define IR_pin D4
void setup()
{
pinMode(led_pin , OUTPUT);
pinMode(IR_pin, INPUT);
}
void loop()
{
if(digitalRead(IR_pin)==1)
{
digitalWrite(led_pin , HIGH);
}
else
{
digitalWrite(led_pin, LOW);
}
}

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Experiment No. 3
Aim
To interface LED with ESP-WROOM-32 and write a program to turn ON LED for 1
sec after every 2 seconds
Apparatus
IoT, laptop or computer, Arduino IDE, LED, micro USB cable, female to male jumper wires,
resistor.

Theory
ESP-WROOM-32 has 26 I/O pins. A simple led runs on a DC voltage signal by applying positive
voltage to positive leg (longer leg, which indicates the positive, anode pin) of led and negative voltage
to negative leg (shorter leg, which indicates negative, cathode pin) of led, that is giving high and low
voltages to led. In a digital system, logic ‘1’ means high and logic ‘0’ means low. When high signal
(logic ‘1’) is given to the positive leg of led from IoT with negative leg of led on ground of IoT then
the led glow and when low signal (logic ‘0’) is given then the led switches off.

Circuit Diagram

Procedure
1. Connect ESP-WROOM-32 with your OS using a micro USB cable.
2. Open Arduino IDE
3. Then go to the Tools/board/board manager option.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

4. Search and install ESP-32 boards.

5. Then select the port on which ESP-32 is connected to your OS. Users can cross check the port in the Device
Manager.
6. Write the program given below.
7. After the programming is completed click on ✓ button to compile the code so that if there is any error the
arduino IDE can detect it.

8. After compiling, click on ⇾ button to upload the program in Arduino.


9. While uploading the code, long press the boot button on ESP32 otherwise the program will not upload in
microcontroller (ESP32).
10. Connect the circuit as shown in the circuit diagram above.
Department of First Year Engineering Internet of Things Lab
By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

11. Led positive leg is connected to pin D26 and the negative leg is connected to the GND of ESP32.
12. Press the EN button on ESP32 to reset ESP32.
13. Once the program is uploaded you can see the bulb blinking.
Program

#define led_pin D1
void setup()
{
pinMode(led_pin , OUTPUT);
}

void loop()
{
digitalWrite(led_pin , HIGH);
delay(1000);
digitalWrite(led_pin , LOW);
delay(2000);
}

#define led_pin D1
void setup()
{
pinMode(led_pin , OUTPUT);
}

void loop()
{
digitalWrite(led_pin , HIGH);
delay(1000);
digitalWrite(led_pin , LOW);
delay(2000);
}

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Experiment No. 4
Aim
To interface Water level indicator with ESP-WROOM-32 and write a program to turn
ON LED at sensor detection
Apparatus:

 NODE MCU
 Water level sensor module
 LED
 Jumper wires

Software Requirements: Arduino IDE.

Theory:
In this project we will be building a water level indicator using Arduino & water sensor with the help
of LED to indicate that the tank is full.
The water level indicator circuits are used in factories, chemical plants, and electrical substations and
in other liquid storage systems. There are many possible uses for this simple system, examples include
monitoring a sump pit (to control pump activation), rainfall detection, and leakage detection.
Electronic water level circuits have the capability of alerting if there is a water leak somewhere in the
factory. When the water level is too high or too low or exceeds the higher limit, it can detect the water
level easily by hearing an alarm sound or from different colours of a light bulb. We can also measure
the fuel level in motor vehicles and the liquid level containers which are huge in the companies.
The circuit is designed to indicate levels of water stored in the tank: low level and full level. When
there is no water in the tank, the LEDs is off as an indication that the tank is completely empty. When
water level increases and touches the sensor, the LED will glow indicating that there is water within
the tank.
Procedure:
1. Make the connections as per the circuit diagram.
2. Check the ground connection precisely before switching on the power supply.
3. Connect USB Cable to PC.
4. Write the Code in. Arduino IDE
5. Compile Code in Arduino IDE
6. Upload the code on Node MCU
7. Observe the output.
Department of First Year Engineering Internet of Things Lab
By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

#define led D1
void setup()
{
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if(sensorValue>=30)
{
digitalWrite(led,HIGH);
}
else
{
digitalWrite(led,LOW);
}
delay(5000);
}

Results: Design and interface water level indicator using NODE MCU successfully implemented.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Experiment No. 5
Aim
To interface DHT11 sensor with ESP-WROOM-32 and write a program to print
temperature and humidity readings on Serial monitor

Apparatus
IoT, Micro USB cable, DHT11 temperature sensor, jumper wires.

Theory
DHT11 Temperature & Humidity Sensor features a temperature & humidity sensor complex with a
calibrated digital signal output. By using the exclusive digital-signal-acquisition technique and
temperature & humidity sensing technology, it ensures high reliability and excellent long-term
stability. This sensor includes a resistive-type humidity measurement component and an NTC
temperature measurement component, and connects to a high performance 8-bit microcontroller,
offering excellent quality, fast response, anti-interference ability and cost-effectiveness. The
calibration coefficients are stored as programmes in the OTP memory, which are used by the sensor’s
internal signal detecting process. The single-wire serial interface makes system integration quick and
easy. Its small size, low power consumption and up-to-20 meter signal transmission make it the best
choice for various applications, including those most demanding ones. When MCU sends a start signal,
DHT11 changes from the low-power-consumption mode to the running-mode, waiting for MCU to
complete the start signal. Once it is completed, DHT11 sends a response signal of 40-bit data that
includes the relative humidity and temperature information to MCU. Users can choose to collect (read)
some data. Without the start signal from MCU, DHT11 will not give the response signal to MCU.
Once data is collected, DHT11 will change to the low power-consumption mode until it receives a
start signal from MCU again.
For more information on DHT11 sensor click on the link
below- https://www.mouser.com/ds/2/758/DHT11-Technical-Data-Sheet-Translated-Version-
1143054.pdf
Circuit Diagram

DHT11 interfacing with ESP-WROOM-32

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Procedure
1. Connect ESP-WROOM-32 with your OS using a micro USB cable.
2. Follow the Steps No.2 to Step No.7 of Experiment No.2 for installation and selection of Board. If you have
already done these steps then continue from Step no.3.
3. For interfacing DHT11 sensor, you need to install a library of DHT11. To install the library, go to the
Sketch/Include library/Manage Libraries menu.

4. Search for DHT11 Sensor library in libraries list and install DHT Sensor library by Adafruit. This library
includes all types of DHT Sensors interfacing.

5. After installing the library, write the program given below.


6. After the programming is completed click on ✓ button to compile the code so that if there is any error the
Arduino IDE can detect it.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

7. After compiling, click on ⇾ button to upload the program in Arduino.


8. While uploading the code, long press the boot button on ESP32 otherwise the program will not upload in
microcontroller (ESP32).
9. Connect the circuit as shown in the circuit diagram above.
10. DHT11 sensor is connected on D21 pin of ESP32 and VCC to 3V3 and GND to GND Respectively.
11. After the program is uploaded click on Serial Monitor and set the baud rate same as written in the program to
see the readings of Temperature and Humidity.

Program

// Code for DHT11 Temperature and humidity sensor.


#include "DHT.h" // including the library of DHT11 temperature and humidity sensor
#define DHTPIN D1 // Selecting the pin at which we have connected DHT11
#define DHTTYPE DHT11 // Selecting the type of DHT sensors
DHT dht ( DHTPIN, DHTTYPE ) ;
void setup ( ) {
Serial.begin ( 9600 ) ;
dht.begin ( ) ; // The sensor will start working
}
void loop ( ) {
Department of First Year Engineering Internet of Things Lab
By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 1
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

//Reading temperature or humidity may take about 2 seconds because it is a very slow sensor.
float humidity = dht.readHumidity ( ) ; // Declaring humidity a variable and storing the humidity
in it.
float temp = dht.readTemperature ( ) ; // Declaring te a variable and storing the temperature in it.
// Checking if the output is correct. If these are NaN, then there is something in it.
if ( isnan (temp) || isnan (humidity) ) {
Serial.println ( " Sensor not working " ) ;
}

// Example testing sketch for various DHT humidity/temperature sensors


// Written by ladyada, public domain

// REQUIRES the following Arduino libraries:


// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include "DHT.h"

#define DHTPIN D1 // Digital pin connected to the DHT sensor


// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment whatever type you're using!


#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V


// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)
// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4
pins)
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.


// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

void setup()
{
Serial.begin(9600);
Serial.println(F("DHTxx test!"));

dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!


// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}

// Compute heat index in Fahrenheit (the default)


float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
Department of First Year Engineering Internet of Things Lab
By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Experiment No. 6
Aim Write a program on ESP-WROOM-32 to upload temperature and humidity data to
the cloud.

Apparatus
IoT Kit Box, micro usb cable, DHT11 Temperature sensor, jumper wires.

Theory
ESP32-DevKitC V4 is a small-sized ESP32-based development board produced by Espressif. Most
of the I/O pins are broken out to the pin headers on both sides for easy interfacing. Developers can
either connect peripherals with jumper wires or mount ESP32-DevKitC V4 on a breadboard.
To cover a wide range of user requirements, the following versions of ESP-32 DevKitC v4 are
available:
 ESP-WROOM-32
 ESP-WROOM-32D
 ESP-WROOM-32U
 ESP-SOLO-1
 ESP-WROVER

Key Description
Component

ESP32-
A module with ESP32 at its core.
WROOM-32

EN Reset button.

Download button. Holding down Boot and then pressing EN initiates


Boot
Firmware Download mode for downloading firmware through the serial port.

USB-to-UART
Single USB-UART bridge chip provides transfer rates of up to 3 Mbps.
Bridge

Micro USB USB interface. Power supply for the board as well as the communication
Port interface between a computer and the ESP32 module.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

5V Power On Turns on when the USB or an external 5V power supply is connected to the
LED
board. For details see the schematics in Related Documents.

Most of the pins on the ESP module are broken out to the pin headers on the
I/O board. You can program ESP32 to enable multiple functions such as PWM,
ADC, DAC, I2C, I2S, SPI, etc.

 ESP-WROVER-B
 ESP-WROVER-I
 ESP-WROVER-B(IPEX)

For more details on ESP-WROOM-32 click on the link


below- https://docs.espressif.com/projects/esp-idf/en/latest/hw-reference/get-started-devkitc.html

ESP-WROOM-32 Development Board


DHT11 Temperature & Humidity Sensor features a temperature & humidity sensor complex with a
calibrated digital signal output. By using the exclusive digital-signal-acquisition technique and
temperature & humidity sensing technology, it ensures high reliability and excellent long-term
stability. This sensor includes a resistive-type humidity measurement component and an NTC
temperature measurement component, and connects to a high performance 8-bit microcontroller,
offering excellent quality, fast response, anti-interference ability and cost-effectiveness. The
calibration coefficients are stored as programmes in the OTP memory, which are used by the sensor’s
internal signal detecting process. The single-wire serial interface makes system integration quick and
easy. Its small size, low power consumption and up-to-20 meter signal transmission make it the best
choice for various applications, including those most demanding ones. When MCU sends a start signal,
DHT11 changes from the low-power-consumption mode to the running-mode, waiting for MCU to
complete the start signal. Once it is completed, DHT11 sends a response signal of 40-bit data that
includes the relative humidity and temperature information to MCU. Users can choose to collect (read)
some data. Without the start signal from MCU, DHT11 will not give the response signal to MCU.
Once data is collected, DHT11 will change to the low power-consumption mode until it receives a
start signal from MCU again.
Department of First Year Engineering Internet of Things Lab
By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

For more information on DHT11 sensor click on the link


below- https://www.mouser.com/ds/2/758/DHT11-Technical-Data-Sheet-Translated-Version-
1143054.pdf

DHT11 Temperature Sensor

Circuit Diagram

DHT11 interfacing with ESP-WROOM-32

Procedure
1. Connect ESP-WROOM-32 with your OS using a micro USB cable.
2. Follow the Steps No.2 to Step No.7 of Experiment No.2 for installation and selection of Board. If you have
already done these steps then continue from Step no.3.
3. Download PubSubClient and arduino json library from the Library Manager.
4. Write the program given below.
5. Replace ssid and password with your wifi id and password.
6. To establish the communication between Hardware and Website go to the website api.thingspeak.com Now
click on Login.
7. Now click on the Sign Up button and create your personal account on the live server. It’s totally free.
8. After creating your account Login to the Website api.thingspeak.com and create the Channel.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Program
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

// REQUIRES the following Arduino libraries:


// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include "DHT.h"

#define DHTPIN D1 // Digital pin connected to the DHT sensor


// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment whatever type you're using!


#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V


// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins)
// Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor
has 4 pins)
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.


// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
Serial.begin(9600);
Serial.println(F("DHTxx test!"));

dht.begin();
}

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!


// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}

// Compute heat index in Fahrenheit (the default)


float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Experiment No. 7
Aim
To interface Bluetooth with ESP-WROOM-32 and write a program to turn LED
ON/OFF when ‘1’/’0’ is received from smartphone using Bluetooth.

Apparatus
IoT Kit, Micro USB cable, 5mm LED, HC-05 Bluetooth, Jumper wires.

Theory
HC‐05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent
wireless serial connection setup. The HC-05 Bluetooth Module can be used in a Master or Slave
configuration, making it a great solution for wireless communication. This serial port bluetooth
module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with
complete 2.4GHz radio transceiver and baseband. It uses CSR Bluecore 04‐External single chip
Bluetooth system with CMOS technology and with AFH (Adaptive Frequency Hopping Feature). The
Bluetooth module HC-05 is a MASTER/SLAVE module. By default, the factory setting is SLAVE.
The Role of the module (Master or Slave) can be configured only by AT COMMANDS. The slave
modules cannot initiate a connection to another Bluetooth device, but can accept connections. Master
module can initiate a connection to other devices. The user can simply use it for a serial port
replacement to establish connection between MCU and GPS, PC to your embedded project, etc.
Hardware Features
 Typical ‐80dBm sensitivity.
 Up to +4dBm RF transmit power.
 3.3 to 5 V I/O.
 PIO(Programmable Input/Output) control.
 UART interface with programmable baud rate.
 With an integrated antenna.
 With an edge connector.
Software Features
 Slave default Baud rate: 9600, Data bits:8, Stop bit:1,Parity: no parity.
 Auto‐connect to the last device on power as default.
 Permit pairing device to connect as default.
 Auto‐pairing Pin:”1234” as default.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 2
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

HC-05 Bluetooth
The HC-05 Bluetooth Module has 6 pins. They are as follows:
 ENABLE: When enable is pulled LOW, the module is disabled which means the module will not turn on and
it fails to communicate. When enable is left open or connected to 3.3V, the module is enabled i.e the module
remains on and communication also takes place.
 Vcc: Supply Voltage 3.3V to 5V
 GND: Ground pin
 TXD & RXD: These two pins acts as UART interface for communication
 STATE: It acts as a status indicator. When the module is not connected to / paired with any other bluetooth
device, the signal goes Low. At this low state, the led flashes continuously which denotes that the module is
not paired with other devices. When this module is connected to/paired with any other bluetooth device, the
signal goes High. At this high state, the led blinks with a constant delay, say for example 2s delay which
indicates that the module is paired.
 BUTTON SWITCH: This is used to switch the module into AT command mode. To enable AT command
mode, press the button switch for a second. With the help of AT commands, the user can change the
parameters of this module but only when the module is not paired with any other BT device. If the module is
connected to any other bluetooth device, it starts to communicate with that device and fails to work in AT
command mode.

Circuit Diagram
Department of First Year Engineering Internet of Things Lab
By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

HC-05 interfacing with ESP-WROOM-32


Procedure
1. Connect ESP-WROOM-32 with your OS using a micro USB cable.
2. Follow the Steps No.2 to Step No.7 of Experiment No.2 for installation and selection of Board. If you have
already done these steps then continue from Step no.3.
3. Write the program given below.
4. After the programming is complete click on ✓ button to compile the code so that if there is any error the
Arduino IDE can detect it.

5. After compiling is done click on ⇾ button to upload the program in Arduino.


6. While uploading the code, long press the boot button on ESP32 otherwise the program will not upload in
microcontroller (ESP32).
7. Connect the circuit as shown in the circuit diagram above.
8. Bluetooth is connected to the D22 and D23 pin and LED is connected on the D26 pin of ESP32 and VCC to
3V3, GND to GND for both the modules respectively.
9. Note that nothing should be connected to the Tx and Rx pins of the ESP32 while uploading the program as
this leads to failure of uploading of the program.
10. Press the EN button on ESP32 to reset ESP32.
11. Now Turn on your Bluetooth in your Smartphone and pair with the Bluetooth module HC-05.
12. Now open “My ThingSpeak Robot” Android Application on your smartphone.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

13. Click on MODES/BLUETOOTH TERMINAL menu and connect module HC-05 Bluetooth.

HC05 App
14. Now Type ‘1’ in BLUETOOTH TERMINAL then the LED will glow and if you type ‘0’ then the LED will
switch off.
Program
#include <HC05.h>

//#define led D1

//#include "BluetoothSerial.h"

void setup() {

// put your setup code here, to run once:

pinMode(D1,OUTPUT);

Serial.begin(9600);

void loop() {

// put your main code here, to run repeatedly:

if(Serial.available()).

char data;

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

data=Serial.read();

if(data=='x')

digitalWrite(D1, HIGH);

delay(1000);

else if(data=='y')

digitalWrite(D1, LOW);

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Experiment No. 8
Aim
Write a program for making smart air pollution meters using IoT Kit and ThingSpeak
IoT cloud as GUI.

Apparatus
IoT, Micro USB cable, Air Pollution Meter Sensor Box, Arduino IDE.

Theory
ESP32-DevKitC V4 is a small-sized ESP32-based development board produced by Espressif. Most
of the I/O pins are broken out to the pin headers on both sides for easy interfacing. Developers can
either connect peripherals with jumper wires or mount ESP32-DevKitC V4 on a breadboard.
To cover a wide range of user requirements, the following versions of ESP-32 DevKitC v4 are
available:
 ESP-WROOM-32
 ESP-WROOM-32D
 ESP-WROOM-32U
 ESP-SOLO-1
 ESP-WROVER
 ESP-WROVER-B
 ESP-WROVER-I
 ESP-WROVER-B(IPEX)
Key Component Description

ESP32-WROOM-32 A module with ESP32 at its core.

EN Reset button.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Download button. Holding down Boot and then pressing EN


Boot initiates Firmware Download mode for downloading firmware
through the serial port.

Single USB-UART bridge chip provides transfer rates of up to 3


USB-to-UART Bridge
Mbps.

USB interface. Power supply for the board as well as the


Micro USB Port communication interface between a computer and the ESP32
module.

Turns on when the USB or an external 5V power supply is


5V Power On LED
connected to the board. For details see the schematics in Related
Documents.

Most of the pins on the ESP module are broken out to the pin
I/O headers on the board. You can program ESP32 to enable multiple
functions such as PWM, ADC, DAC, I2C, I2S, SPI, etc.

For more details on ESP-WROOM-32 click on the link


below- https://docs.espressif.com/projects/esp-idf/en/latest/hw-reference/get-started-devkitc.html

ESP-WROOM-32 Development Board


A Dust Sensor is an infrared emitting diode (IRED) and a phototransistor is diagonally arranged into
this device. It detects the reflected light of dust in the air. It is effective to detect very fine particles
like cigarette smoke. In addition, it can distinguish smoke from house dust by the pulse pattern of the
output voltage.
The module is mainly used for dust removal equipment, alarm equipment, air purification equipment,
dust robots, fire alarm, etc. industry equipment can detect smoke particles, pollen spores, and other
particles.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Dust Sensor

Air quality sensor for detecting a wide range of gases, including NH3, NOx, alcohol, benzene, smoke
and CO2. Ideal for use in the office or factory. Air quality sensor has high sensitivity to Ammonia,
Sulfide and Benze steam, also sensitive to smoke and other harmful gases. It is low cost and
particularly suitable for Air quality monitoring application.

Air Quality Sensor

Sensitive material of the Carbon Monoxide sensor is SnO2, which has lower conductivity in clean air.
It makes detection by method of cycle high and low temperature, and detect CO when low temperature
(heated by 1.5V). The sensor’s conductivity is higher along with the gas concentration rising. When
high temperature (heated by 5.0V), it cleans the other gases adsorbed under low temperature. Please
use simple electro circuit, Convert change of conductivity to correspond output signal of gas
concentration. Carbon Monoxide sensor has high sensitivity to Carbon Monoxide. The sensor could
be used to detect different gases containing CO, it is low cost and suitable for different applications.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Carbon Monoxide Sensor

Circuit Diagram

Smart Air Pollution Meter sensor module with IoT Learning Box

Smart Air Pollution Meter Sensor Module Pins IoT Learning Box Pins

Dust Sensor

V-ILed First pin

GND GND

ILed Rx0

GND GND

A-Out Vp

Vcc 3V3

MQ7 Sensor

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

+5v 3V3

GND GND

A-Out D32

MQ135 Sensor

+5V 3V3

GND GND

A-Out D35

LM35 Sensor

+5V 3V3

GND GND

A-Out D34

Procedure
1. Connect ESP-WROOM-32 with your OS using a micro USB cable.
2. Follow the Steps No.2 to Step No.7 of Experiment No.2 for installation and selection of Board. If you have
already done these steps then continue from Step no.3.
3. Download the MQ7 sensor library from the Library Manager.
4. Write the program given below.
5. Replace ssid and password with your wifi id and password.
6. Login to the ThingSpeak IoT Portal and create the channel as shown in Experiment No. 9.

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

7. Open the Channel and copy the API Key and paste it in the program.
8. Now click on ✓ button to compile the program to check whether the code is error free or not.
9. Once the code is compiled and is error free then click on → button to upload the code in ESP32.

10. While uploading the code, long press the boot button on ESP32 otherwise the program will not upload in the
microcontroller (ESP32).
11. Connect the circuit as shown in the circuit diagram above.
12. Press the EN button available on ESP32 to reset ESP32.
13. Then click on the Chart and see data coming from the ESP32.
14. Field1 chart shows the Dust Density, Field2 chart shows the Mq7-CO content in air, Field3 chart shows the
Quality of Air using MQ135 sensor and Field4 chart shows the Temperature in Celsius.

Output

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 3
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

Program
#include <ESP8266WiFi.h>
String apiKey = "CVBKY4XEQNYQ31PF"; // Enter your Write API key from ThingSpeak
const char *ssid = "Ram"; // replace with your wifi ssid and wpa2 key
const char *pass = "Rahulram2";
const char* server = "api.thingspeak.com";
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(100);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
Department of First Year Engineering Internet of Things Lab
By: Dr. Rahul Pethe
G H RAISONI INSTITUTE OF ENGINEERING & TECHNOLOGY 4
(Approved by AICTE, New Delhi and Recognized by DTE, Maharashtra)
An Autonomous Institute Affiliated to Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
Accredited by NAAC with A+ Grade
Shraddha Park, B-37-39/1, MIDC, Hingna-Wadi Link Road, Nagpur-440016 (INDIA)
Phone Nos.: 07104-234501 Fax: +91-07104-234501
Email: - [email protected] Web: - www.ghrietn.raisoni.net
DEPARTMENT OF FIRST YEAR ENGINEERING

{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
float h = analogRead(A0);
if (isnan(h))
{
Serial.println("Failed to read from MQ-5 sensor!");
return;
}

if (client.connect(server, 80)) // "184.106.153.149" or api.thingspeak.com


{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(h/1023*100);
postStr += "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("Air Quality: ");
Serial.println(h/1023*100);
Serial.println("Data Send to Thingspeak");
}
delay(500);
client.stop();
Serial.println("Progress...");

// thingspeak needs minimum 15 sec delay between updates.


delay(1500);
}

Department of First Year Engineering Internet of Things Lab


By: Dr. Rahul Pethe

You might also like