0% found this document useful (0 votes)
31 views

Practical 4 - ESP32 DHT Ultrasonic

Uploaded by

black hello
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Practical 4 - ESP32 DHT Ultrasonic

Uploaded by

black hello
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

BAIT2123 INTERNET OF THINGS Jul 2024

Practical 4

Extend the NodeMCU ESP32 embedded system to read analog input and write analog output.

Objective
Understand how to use NodeMCU ESP32 for setting up a simple IOT solution with Digital
Humidity & Temperature sensor and ultrasonic sensor.

Background

The Digital Humidity and Temperature (DHT11) module is a basic, low-cost


digital sensor that measures both the relative humidity and temperature of the
surrounding environment. It's a popular choice for simple projects due to its
affordability and ease of use, with the following specifications and datasheet:

Min/Max Operating Voltage: 3.3V to 5V


Humidity Range: 20% to 80% RH
Humidity Accuracy: ±5% RH
Temperature Range: 0°C to 50°C
Temperature Accuracy: ±2°C
Sampling Rate: 1 Hz (one reading per second)

An ultrasonic sensor module (HC-SR04) is an electronic device


that measures the distance to an object by emitting high-frequency
sound waves (ultrasound) and measuring the time it takes for the
echo to return. It operates on the principle of sonar, similar to how
bats navigate and locate objects. Here is the specification and the
datasheet:

Operating Voltage: 5V DC
Operating Current: 15mA
Measure Angle: 15°
Ranging Distance: 2cm - 4m

Procedure

Step 1: Set up the NodeMCU ESP32 on two pieces of breadboard


* Take note that the width size of NodeMCU ESP32 pins are not able to fit into one breadboard.
BAIT2123 INTERNET OF THINGS Jul 2024

Step 2: Connect one LED with resistors and one push button on NodeMCU ESP32 pins
- Use 1 Blue LED and 1kΩ registers and connect them to the Pin D25. Negative (-ve) pin
of the LED connects to the common GND.
- Use 1 White LED and 1kΩ registers and connect them to the Pin D5. Negative (-ve) pin
of the LED connects to the common GND.
- Use 1 push button and connect it to the Pin D4. Connect the other pin of the push button
to the common GND.
- Connect the GND to NodeMCU ESP32 GND pin.

Step 3: Connect one DHT sensor module, one active piezo buzzer module, one gas
sensor MQ-2 and one ultrasonic module on NodeMCU ESP32 pins
- Use 1 DHT sensor module and connect it to the Pin D21. The Vcc (+) pin of the DHT
sensor module connects to the common 5v and the GND (-ve) pin of the DHT sensor
module connects to the common GND.
* Wrong connected GND and Vcc will cause the DHT sensor to overheat and melt.

- Use 1 ultrasonic module and connect the TRIG pin to the D23; ECHO pin to the D22.
The Vcc (+) pin of the ultrasonic module connects to the common 5v and the GND (-ve)
pin of the ultrasonic module connects to the common GND.

- Connect the common +ve lines (red) lines to the Raspberry Pi PIN1 3.3V.

- Connect the common -ve GND (blue) lines to the NodeMCU ESP32 GND pin, and to the
Raspberry Pi PIN9 GND pin
BAIT2123 INTERNET OF THINGS Jul 2024

- .

Step 4: In Arduino IDE, install the DHT sensor Library:


- Tools > Manage Libraries... >
Search for "DHT sensor library"
Select DHT sensor library by Adafruit and Click Install
BAIT2123 INTERNET OF THINGS Jul 2024

Step 5: Modify the default *.ino code to the following codes:


BAIT2123 INTERNET OF THINGS Jul 2024

Step 6: Add in functions for


- readUltrasonic
BAIT2123 INTERNET OF THINGS Jul 2024

- readDHT

Step 7: Upload the compiled code to NodeMCU ESP32 Module and observe the result.
- Click Sketch > Verify / Compile and Sketch > Upload to compile this modified code and
upload to the NodeMCU ESP32 module.
- Check if all sensors values are sent to the Serial Monitor display
- Check if the Buzzer at PIN26 is responding to the push button or not.

You might also like