Component Guide

Sensors Beginner

DHT22 Temperature & Humidity Sensor

Measures temperature and humidity in the air. Perfect for weather stations and room monitors.

DHT22 Temperature & Humidity Sensor

Explain Like I'm 12

Think of the DHT22 as a tiny weather reporter in a plastic box. It tells your ESP32 how warm the room is and how damp the air feels — like checking if your room is cozy or sticky after gym class.

Quick Facts

  • Measures Air temperature and humidity
  • Pins 3 wires — power, ground, data
  • Best for Weather stations and room monitors
  • Update speed New reading every 2 seconds

Technical Specifications

Arduino library: DHT sensor library by Adafruit

  • Temperature range: −40°C to 80°C
  • Humidity range: 0–100% RH
  • Operating voltage: 3.3 V (recommended for ESP32)
  • Single data pin with digital protocol
  • Sampling rate: 0.5 Hz (every 2 seconds)

Pinout

  • 1 · VCC Power ESP32 3.3 V Use 3.3 V for direct ESP32 wiring
  • 2 · DATA Signal ESP32 GPIO4 Add 10 kΩ pull-up to 3.3 V on bare sensors; many modules include one
  • 3 · GND Ground ESP32 GND Common ground with the ESP32

Wiring

A DHT22 module with three pins is the easiest way to start. Match each pin to the ESP32 as shown below.

Wiring Diagram DHT22 module — VCC to 3.3 V, GND to GND, DATA to GPIO4 on ESP32
  1. 1

    Unplug USB. Place the DHT22 module on your breadboard.

  2. 2

    Connect VCC on the module to 3.3 V on the ESP32.

  3. 3

    Connect GND on the module to GND on the ESP32.

  4. 4

    Connect DATA on the module to GPIO4 on the ESP32.

  5. 5

    Double-check — VCC to 3.3 V, GND to GND, DATA to GPIO4.

  6. 6

    Plug in USB. Your code must use the same GPIO number.

Code Example

Copy into Arduino IDE. Install the library listed above first.

dht22_read.ino
#include "DHT.h"

#define DHTPIN 4
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

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

void loop() {
  float temp = dht.readTemperature();
  float humidity = dht.readHumidity();

  if (isnan(temp) || isnan(humidity)) {
    Serial.println("Read failed — check wiring");
  } else {
    Serial.printf("Temp: %.1f C  Humidity: %.0f%%\n", temp, humidity);
  }

  delay(2000);
}

Expected Output

Open Serial Monitor at 115200 baud. Every 2 seconds you should see a line like:

Temp: 24.3 C Humidity: 55%

The numbers change when you breathe on the sensor or move it near a window.

Common Mistakes

  • Reading faster than every 2 seconds — the DHT22 needs time between reads.
  • DATA wire on a different GPIO than the code uses.
  • Forgetting a pull-up resistor on bare (non-module) sensors.
  • Loose jumper wires that look connected but are not.

Troubleshooting

  • Serial shows NaN or Read failed Check VCC, GND, and DATA wiring. Confirm GPIO4 in code matches your wire. Wait 2 seconds between reads.
  • Readings stuck at zero Verify the sensor has power at 3.3 V and the DATA pin is firmly seated in the breadboard.
  • Humidity jumps wildly Keep the sensor away from your breath, heaters, and hot electronics for a minute before trusting the number.

Related Guides

Related Projects

FAQ

Downloads

Official DHT22 datasheet (PDF) — helpful for teachers and advanced builders.

Download Datasheet (PDF)