ESP32 and DHT11: Master Beginner-Friendly Guide to Building Your First Temperature and Humidity Monitoring System

0b63979cd9494aa401d1fce2d73bb002
On: November 27, 2025
ESP32 and DHT11

Table of Contents

ESP32 and DHT11 guide for beginners. Learn wiring, code, setup, MQTT, Blynk, Bluetooth, Arduino Cloud, and build your own IoT temperature and humidity monitor.

If you’re getting into IoT, home automation, or just love experimenting with sensors, pairing the ESP32 and DHT11 is one of the simplest and most rewarding projects you can build. You don’t need advanced electronics knowledge. You don’t need expensive modules. Just a few wires, a sensor that costs less than a cup of coffee, and a board that packs Wi-Fi, Bluetooth, and serious processing power.

In this guide, we’ll walk through everything step by step how the DHT11 sensor works, how to connect DHT11 to ESP32, how to write the ESP32 and DHT11 code in Arduino IDE, and even how to take it further using MQTT, Blynk, MicroPython, Arduino Cloud, LoRa, LCD displays, and more.

By the end, you’ll be ready to build an IoT weather station, smart room monitor, or your own cloud-connected automation system.

Let’s start with the basics.

What Is the DHT11 Temperature and Humidity Sensor?

Before wiring anything, it’s good to know what you’re working with.

The DHT11 temperature and humidity sensor is a low-cost digital sensor that measures:

  • Temperature
  • Humidity

It uses a single-wire protocol, which means it sends data to your ESP32 using just one digital pin. That’s why beginners love it—it’s simple, cheap, and reliable enough for basic projects.

Key Features of DHT11

  • Temperature range: 0–50°C
  • Humidity range: 20–90%
  • Accuracy: Good enough for hobby projects
  • Operating voltage: 3.3V to 5V
  • Digital output (no analog reading required)

Difference Between DHT11 and DHT22 Sensor

A question many beginners ask is:
Should I use DHT11 or DHT22?

Here’s the quick difference:

FeatureDHT11DHT22
Temp Range0–50°C-40–80°C
AccuracyLowerHigher
Humidity Range20–90%0–100%
CostCheaperSlightly expensive
SpeedSlowerFaster

If you’re building an advanced weather station, go with DHT22.
If you’re learning or experimenting, DHT11 is perfect.

ESP32 and DHT11 Connection Guide

Now, let’s get practical. The ESP32 and DHT11 connection is simple because the sensor is digital.

If you’re completely new to BLE projects and want a beginner-friendly reference, you can also check this practical guide: ESP32 BLE App Control Building Your First Bluetooth Project which explains BLE basics clearly.

ESP32 DHT11 Pinout

If your DHT11 module has three pins, they are usually:

  1. VCC → connect to ESP32 3.3V
  2. DATA → connect to any ESP32 GPIO pin (e.g., GPIO 4)
  3. GND → connect to GND

That’s it.

Some DHT11 modules include a pull-up resistor. If yours doesn’t, you should use a 10k resistor between VCC and DATA, but most modules already include it.

ESP32 DHT11 Circuit Diagram

Here’s a simple layout you can follow on a breadboard:

DHT11 VCC  → ESP32 3.3V
DHT11 DATA → ESP32 GPIO 4
DHT11 GND  → ESP32 GND

If your board has 5V pin, avoid using it. ESP32 is a 3.3V device, and powering sensors with 5V can sometimes create inconsistent readings.

This is your basic ESP32 DHT11 circuit diagram—clean, beginner-friendly, and reliable.

ESP32 and DHT11 Code (Arduino IDE)

Let’s write simple code to read temperature and humidity.

Step 1: Install DHT Sensor Library

Open Arduino IDE → Tools → Manage Libraries
Search for:
“DHT sensor library” by Adafruit

Also install:
“Adafruit Unified Sensor”

Step 2: Upload This Code

#include 

#define DHTPIN 4
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  dht.begin();
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT11!");
    return;
  }

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" % | Temperature: ");
  Serial.print(t);
  Serial.println(" °C");

  delay(2000);
}

Now open the Serial Monitor.
You’ll see the values updating every 2 seconds.

This is your basic ESP32 DHT11 example.

ESP32 DHT11 Arduino IDE Setup

  • Use ESP32 Dev Module in board manager
  • Baud rate: 115200
  • Pin GPIO 4 is commonly used but you can use any digital pin
  • Don’t power the sensor with 5V

Connect DHT11 to ESP32 Using Arduino Cloud

If you want your data available online without complex setup, Arduino Cloud is the easiest path.

Workflow:

  1. Create an Arduino Cloud account
  2. Install the IoT Cloud Agent
  3. Add ESP32 as a device
  4. Create variables for temperature and humidity
  5. Upload auto-generated code
  6. Add DHT11 reading logic

You get:

  • Online dashboard
  • Charts
  • Mobile access

That means you can check your room temperature from anywhere.

ESP32 DHT11 Blynk IoT Project (Mobile Dashboard)

Want a cool mobile app without writing backend code?
Use Blynk.

Here’s what happens:

  • ESP32 reads DHT11 sensor values
  • Sends them to Blynk over Wi-Fi
  • You view temperature and humidity on your phone

Steps:

  1. Create a Blynk project
  2. Add two labeled value widgets
  3. Copy the auth token
  4. Use Blynk library in Arduino IDE
  5. Push data to virtual pins

This is a great ESP32 DHT11 project if you want a quick IoT prototype.

ESP32 DHT11 Bluetooth Project (Offline Monitoring)

If you don’t want Wi-Fi:

  • Send DHT11 readings over ESP32 Bluetooth
  • View them using a phone Bluetooth terminal app

This setup is perfect for:

  • Warehouses
  • Factories
  • Areas without reliable Wi-Fi

ESP32 CAM DHT11 Project (Camera + Sensor)

The ESP32-CAM can:

  • Stream video
  • Send photos
  • Read DHT11 data at the same time

Imagine:

  • Monitoring temperature of a greenhouse
  • Getting live camera feed
  • Getting humidity alerts

You simply connect the DHT11 data pin to GPIO 14 or GPIO 15 depending on your ESP32-CAM breakout board.

ESP32 DHT11 MicroPython Example

Not a fan of Arduino IDE?
Try MicroPython, which makes the code clean and readable.

Sample code:

from machine import Pin
import dht
import time

sensor = dht.DHT11(Pin(4))

while True:
    sensor.measure()
    print("Temp:", sensor.temperature(), "Humidity:", sensor.humidity())
    time.sleep(2)

If you want rapid development, MicroPython is fantastic.

ESP32 DHT11 MQTT Broker IoT Setup

MQTT is the backbone of modern IoT.
You can publish your DHT11 data to:

  • Mosquitto broker
  • HiveMQ
  • Home Assistant
  • Node-RED

Flow:

  1. Connect ESP32 to Wi-Fi
  2. Read DHT11
  3. Publish to topic like home/room1/temp
  4. Subscribe from phone or PC

This is ideal for automation systems.

ESP32 LoRa DHT11 (Long-Range IoT)

If you want long-range communication:
Use ESP32 LoRa + DHT11.

This setup works without Wi-Fi and can send data for several kilometers.

Use it for:

  • Farms
  • Remote weather stations
  • Environmental monitoring

The code sends temperature and humidity packets over LoRa, and a receiver ESP32 prints them.

ESP32 DHT11 LCD I2C Display

If you want a local offline display, connect an I2C LCD.

Benefits:

  • Instant readings
  • No phone or Wi-Fi needed

Wiring:

  • SDA → GPIO 21
  • SCL → GPIO 22
  • DHT11 → GPIO 4

You print values like this:

lcd.print("Temp: ");
lcd.print(t);
lcd.print("C");

ESP32 DHT11 Soil Sensor Combo

A popular beginner project is combining:

  • ESP32
  • DHT11
  • Soil moisture sensor

With these three sensors, you can build:

  • Smart plant watering system
  • Smart greenhouse controller
  • Fully automated garden IoT project

ESP32 reads:

  • Soil moisture
  • Temperature
  • Humidity

Then it:

  • Sends data to cloud
  • Triggers pump
  • Sends alerts

ESP32 DHT11 Case Ideas

If you want your project to look neat:

  • Use 3D-printed cases
  • Use ventilation holes for the sensor
  • Keep the DHT11 outside if possible to avoid heat influence

People often put ESP32 inside a box and mount DHT11 outside.

Troubleshooting ESP32 and DHT11

Here are common issues and quick fixes.

1. “Failed to read from DHT11” error

Fix:

  • Check wiring
  • Add 10k pull-up resistor
  • Try changing GPIO

2. Sensor always gives 0 values

Fix:

  • Use 3.3V instead of 5V
  • Don’t extend wires too long

3. Slow update rate

DHT11 updates once every 1–2 seconds.
This is normal.

4. Arduino IDE uploading errors

Fix:

  • Press BOOT button when uploading (for some ESP32 boards)

5. Sensor heating affects results

Solution:

  • Keep the ESP32 away from the sensor

ESP32 and DHT11 Project Ideas

Here are some fun and practical ideas:

  • Wi-Fi room climate monitor
  • MQTT smart home sensor
  • Blynk health dashboard
  • Bluetooth offline logger
  • ESP32-CAM weather station
  • LoRa remote environmental monitor
  • Plant care monitor
  • Arduino Cloud dashboard monitor
  • Local LCD-based weather display

Each project uses the same basics you learned in this article.

FAQ: ESP32 and DHT11

1. What is the ESP32 and DHT11 combination used for?

The ESP32 and DHT11 combination is commonly used to build temperature and humidity monitoring systems. Since the ESP32 supports Wi-Fi, Bluetooth, MQTT, and cloud platforms, you can turn the DHT11 sensor into an IoT device that sends real-time environmental data to your phone, dashboard, or automation system.

2. How do I connect the ESP32 and DHT11 sensor correctly?

To connect the ESP32 and DHT11, wire the DHT11 VCC to 3.3V, the DATA pin to any GPIO (commonly GPIO 4), and the GND pin to the ESP32 ground. Most DHT11 boards already include a pull-up resistor, so wiring is simple. This setup gives stable readings without requiring a complex circuit.

3. What code is required to run the ESP32 and DHT11 in Arduino IDE?

You need to install the “DHT sensor library” by Adafruit and write a small sketch that reads humidity and temperature. The ESP32 and DHT11 code usually defines the sensor type (DHT11) and uses digitalRead via the library. Beginners love this setup because it works with minimal code.

4. Why is the ESP32 and DHT11 not giving accurate readings?

The DHT11 sensor is known for being entry-level. If your ESP32 and DHT11 setup gives inconsistent readings, check wiring, avoid long jumper wires, and ensure the sensor is not close to the ESP32 board or heat sources. Also remember that DHT11 updates slowly—every 1–2 seconds.

5. What is the difference between DHT11 and DHT22 for ESP32 projects?

When comparing DHT11 and DHT22, the DHT22 provides a wider temperature range, better accuracy, and higher responsiveness. The DHT11 is cheaper and perfect for beginners. If you need precise monitoring or outdoor measurements, choose DHT22 for your ESP32 project.

6. Can I use ESP32 and DHT11 with Blynk or MQTT?

Yes, the ESP32 and DHT11 work great with Blynk and MQTT. You can send temperature and humidity data to Blynk’s mobile dashboard or publish MQTT topics like home/livingroom/temp and monitor values inside Home Assistant or Node-RED. This turns your project into a real IoT device.

7. Does the ESP32 and DHT11 work with MicroPython?

Absolutely. If you prefer Python-style coding, the ESP32 and DHT11 work smoothly with MicroPython. You only need the dht module and a few lines of code to read the temperature and humidity. MicroPython is great for quick prototyping and educational projects.

8. Why does my ESP32 and DHT11 show “Failed to read sensor” error?

This is one of the most common DHT11 issues. It happens when:

  • The DATA pin is not correctly connected
  • You’re using a pin that conflicts with ESP32 boot mode
  • The sensor isn’t powered correctly
  • The reading interval is too fast
    Try using GPIO 4, 15, 16, or 17 and add a slight delay between readings.

9. Can I connect ESP32 and DHT11 to Arduino Cloud?

Yes. The ESP32 and DHT11 work well with Arduino Cloud. You can create variables for humidity and temperature, sync them to a dashboard, and view the data from your phone or web browser. This setup is ideal for beginners who want a cloud dashboard without complex backend programming.

10. Can the ESP32 and DHT11 send data via Bluetooth instead of Wi-Fi?

Yes, the ESP32 can send DHT11 readings via Bluetooth Classic or BLE. This is useful if you want a completely offline system. By pairing your ESP32 and DHT11 with a BLE app like LightBlue or nRF Connect, you can view sensor data without needing a router.

11. How do I protect my ESP32 and DHT11 from heat or humidity interference?

Place the DHT11 sensor away from the ESP32 board because the microcontroller generates heat. Use a ventilated case that allows airflow but protects the electronics. If you’re making a weather station, mount the DHT11 outside the enclosure while keeping the ESP32 inside.

12. Can I use ESP32 and DHT11 for outdoor weather monitoring?

The DHT11 is not ideal for outdoor use because it has lower accuracy and isn’t waterproof. You can still use the ESP32 and DHT11 outdoors if you place the sensor in a shaded, ventilated housing like a Stevenson screen. For professional outdoor projects, use DHT22 or SHT31.

13. How do I combine ESP32 and DHT11 with a soil sensor for agriculture projects?

Many beginners build plant automation systems using the ESP32 and DHT11 together with a soil moisture sensor. The ESP32 reads temperature, humidity, and soil moisture, and can trigger a relay to water plants automatically. This is a great beginner smart-farming project.

14. Why is DHT11 slow compared to other sensors on ESP32?

The DHT11 can only provide new data every 1–2 seconds. This is not a problem for home monitoring but makes it unsuitable for high-frequency industrial sensing. If speed matters, consider pairing ESP32 with DHT22, BME280, or SHT31.

15. Can I connect multiple DHT11 sensors to one ESP32?

You can connect multiple DHT11 sensors to an ESP32, but each sensor must be connected to a different GPIO pin. The ESP32 and DHT11 design doesn’t allow daisy-chaining. If you need many sensors, consider using I2C-based sensors for easier wiring.

16. Can I use ESP32-CAM with DHT11 for video + sensor monitoring?

Yes. Many people build ESP32-CAM projects that stream video while reading DHT11 data. The ESP32 and DHT11 combination works even on ESP32-CAM boards as long as you choose a spare GPIO pin (like GPIO 14 or 15) to read sensor data without interrupting the camera.

ESP32 and DHT11 Troubleshooting Guide

This troubleshooting guide covers every common issue you’ll face while working with ESP32 and DHT11, including wiring errors, library conflicts, inaccurate readings, boot-mode problems, power issues, timing problems, Bluetooth/Wi-Fi conflicts, and MicroPython quirks.

1. Why is my ESP32 and DHT11 sensor not giving any readings at all?

If your ESP32 and DHT11 shows no data or prints only “nan” or “Failed to read sensor,” it usually means:

Possible causes

  • Wrong GPIO pin selected
  • Sensor not powered (3.3V not connected)
  • Faulty breadboard wires
  • Using a GPIO that affects ESP32 boot mode
  • No pull-up resistor on the Data pin (for 3-pin DHT11 modules)
  • DHT library not installed correctly

How to fix

  1. Connect DHT11 VCC → 3.3V, GND → GND, DATA → GPIO 4 (safest pin).
  2. If you’re using the raw 3-pin DHT11, add a 10K pull-up between DATA and VCC.
  3. Avoid GPIO 0, 2, 12, 15—they cause boot issues.
  4. Install the correct library:
    • Adafruit Unified Sensor
    • DHT Sensor Library

This alone solves 80% of “no reading” problems.

2. Why is my ESP32 and DHT11 showing “nan” humidity or temperature values?

The DHT11 sends data slowly (every 1–2s), and if you poll too fast, values show up as nan.

Fix

  • Add a delay of 2000 ms between readings
  • Keep the sensor stable at room temperature
  • Use shorter jumper wires
  • Power the DHT11 from 3.3V, not 5V

3. Why does the ESP32 restart when reading DHT11? (Watchdog Reset)

Your loop may be blocking the ESP32’s internal watchdog.

Causes

  • Delay too long
  • Blocking code reading DHT11
  • Wi-Fi or BLE tasks starving

Fix

Use non-blocking delay:

unsigned long lastRead = 0;
if (millis() - lastRead > 2000) {
    lastRead = millis();
    readDHT11();
}

This prevents WDT resets.

4. Why is my DHT11 reading jumping or inaccurate when connected to ESP32?

The ESP32 produces heat, which affects the DHT11.

Fix

  • Place the DHT11 away from ESP32 (≥5 cm).
  • Do not mount sensor inside the same case with ESP32.
  • Avoid direct sunlight / fans / power supplies.
  • Do not touch the sensor while reading—it increases temperature instantly.

If accuracy matters, upgrade to DHT22 or SHT31.

5. Why is my DHT11 not working on ESP32 while it works on Arduino Uno?

Reason

Some DHT11 modules expect 5V, but ESP32 runs at 3.3V logic.

Fix

  • Use 3.3V-compatible DHT11 module
  • Or add a level shifter (optional but recommended)
  • Or try powering DHT11 with 5V but keep DATA pin at 3.3V through a voltage divider

Most modern DHT11 modules work fine at 3.3V.

6. Why does the ESP32 freeze or hang after several DHT11 readings?

This happens due to timing issues inside the DHT library.

Fix

  • Update to the latest Adafruit DHT library
  • Reduce reading frequency (every 2–3 seconds)
  • Avoid using delay() inside Wi-Fi/Bluetooth loops

For large IoT applications, use FreeRTOS tasks for clean scheduling.

7. Why do I get “Timeout waiting for response from DHT11”?

The ESP32 is fast, but the DHT11 is slow.

Fix

  • Use DHT11 object type, not DHT22
  • Check wiring for loose ground
  • Use GPIO 4 or 15—they work best
  • Ensure humidity is below 90% (DHT11 fails in high moisture)

8. Why is my ESP32 not connecting to Wi-Fi when using DHT11?

DHT11 uses strict timing, and heavy Wi-Fi scans disrupt it.

Fix

Use Wi-Fi.begin() outside the main loop.

Example:

void setup() {
  WiFi.begin(ssid, password);
  while(WiFi.status() != WL_CONNECTED);
}

Then read DHT11 in loop or FreeRTOS task.

9. Why does my ESP32 and DHT11 show stable temperature but unstable humidity?

Humidity fluctuations are normal because DHT11 is not highly accurate.

Fix

  • Use slower reading intervals
  • Keep the sensor stationary
  • Shield from airflow
  • Avoid placing near AC ducts or open windows

For precision, switch to DHT22 / SHT21.

10. Why does ESP32 Bluetooth/BLE stop working when reading DHT11?

ESP32 has shared timing resources. Blocking delays break BLE connections.

Fix

  • Use non-blocking code
  • Avoid delay()
  • Run DHT11 reading in a separate FreeRTOS task

If using BLE projects, refer to this BLE guide for better timing structure:
https://embeddedprep.com/esp32-ble-app-control/

11. Why does MicroPython fail to read DHT11 accurately on ESP32?

MicroPython sometimes crashes when reading slow sensors like DHT11.

Fix

  • Use correct MicroPython firmware
  • Use machine.Pin() with pull-up
  • Add a delay of 2 seconds between reads
  • Try DHT22 if values are stuck

MicroPython + DHT11 = works, but fragile.

12. Why does ESP32 CAM not read DHT11 reliably?

ESP32-CAM has limited free GPIO pins and camera tasks interrupt timings.

Fix

  • Use GPIO 14 or 15 for DHT11
  • Add a power capacitor (100uF)
  • Use external 5V power supply
  • Reduce frame rate on ESP32-CAM

13. Why is my DHT11 reading “0°C / 0% humidity”?

This means the sensor is not communicating.

Fix

  • Try another GPIO
  • Ensure data pin uses a pull-up resistor
  • Replace sensor—many cheap DHT11 modules are defective
  • Check for moisture inside casing

14. Why does sensor work sometimes and fail sometimes?

This is classic floating DATA pin behaviour.

Fix

Add 10K resistor between VCC and DATA.

This ensures stable signal pulses.

15. Why is my DHT11 working on breadboard but not on PCB?

On PCB, traces might be too long or noisy.

Fix

  • Keep data line shorter than 20 cm
  • Use shielded cable if required
  • Add capacitor near sensor power pins
  • Add ground plane for stability

Leave a Comment