ESP32+DHT11 Temperature & Humidity Sensor Project

by mansiramteke139 in Circuits > Sensors

1660 Views, 0 Favorites, 0 Comments

ESP32+DHT11 Temperature & Humidity Sensor Project

20260313_174604[1].jpg

In this project, I built a simple temperature and humidity monitoring system using ESP32 and DHT11 sensor. The ESP32 reads environmental data from the sensor and display on the serial monitor. This project is useful for beginners who want ti learn how sensors work with ESP32.

Supplies

Screenshot 2026-03-13 175021.png
Screenshot 2026-03-13 175154.png

Components Required:

  1. ESP32 DEV Module
  2. DHT11 Temperature and Humidity Sensor
  3. Jumper Wires
  4. Breadboard
  5. USB Cable
  6. Arduino IDE (Software)

Circuit Diagram

Screenshot 2026-03-13 140301.png

ESP32

┌───────────┐

│ │

3.3V ──────── +

GPIO4 ─────── OUT [DHT11 Sensor Module]

GND ──────── -

│ │

└───────────┘

CODE

Screenshot 2026-03-13 144030.png
Screenshot 2026-03-13 175346.png

CODE EXPLAIN

#include <DHT.h>

  1. This line imports the DHT Sensor Library


#define DHTPIN 4

#define DHTTYPE DHT11

  1. First line defines the GPIO pin where the data pin is connected.
  2. Second line tells the program which sensor being used.


DHT dht(DHTPIN, DHTTYPE);

  1. This shows an object name.


void setup() {

Serial.begin(115200);

Serial.println("DHT11 Sensor Starting...");

dht.begin();

delay(2000);

}

  1. serial begin starts serial communication between ESP32 and the Comupter. and baud rate set to 115200.
  2. next line prints a massage in the serial monitor when program start.
  3. After next line, initializes the DHT11 sensor.
  4. delay shows that, wait for 2 sec. before starting measurement.


void loop() {


float h = dht.readHumidity();

float t = dht.readTemperature();


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

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

}

else {

Serial.print("Temperature: ");

Serial.print(t);

Serial.print(" °C Humidity: ");

Serial.print(h);

Serial.println(" %");

}


delay(2000);

}

  1. float h - line reads the humidity value from the sensor. and result will show in h variable.
  2. float t - line read the temperature in celsius. and result will show in t variable.
  3. if line shows the 'It is not the number'
  4. in the else section it will print humidity value.

Downloads

Working Code

  1. The DHT11 sensor measures the temperature and humidity of the surrounding environment.
  2. The sensor send this dada as a digital signals to the ESP32 Microcontroller through the data pin (Pin4)
  3. The ESP32 read the data using the DHT library and processes the temperature and humidity values.
  4. After reading the data, the ESP32 displays the result on the Serial Monitor in the Arduino IDE.
  5. The ESP32 repeats this process every 2 Sec.
  6. So, the temperature and humidity values keep updating in real time.
  7. This allows us to monitor environmental conditions using the ESP32 and DHT11 sensor.

OutPut

Screenshot 2026-03-13 152531.png
Temperature: 38.00 °C Humidity: 10.00 %
Temperature: 38.00 °C Humidity: 10.00 %
Temperature: 38.00 °C Humidity: 10.00 %
Temperature: 38.00 °C Humidity: 10.00 %
Temperature: 38.00 °C Humidity: 10.00 %
Temperature: 38.00 °C Humidity: 10.00 %

Serial Monitor shows data like this.

Error I Faced

Screenshot 2026-03-13 151601.png
Screenshot 2026-03-13 144046.png

The solution:

  1. Check Pin connections
  2. Check wiring Connection
  3. Check code

Conclusion

This project demonstrate how to interface a DHT11 sensor with ESP32 to measure temperature and humidity. It is simple beginner-friendly IoT project and can be further expanded to display data on an LCD or send data to the cloud.

-In the next blog I will share how to display on an LCD or send data to the cloud.