Documentation

DHT22 Digital Temperature and Humidity Sensor Module with Cable
Documentation / DHT22 Digital Temperature and Humidity Sensor Module with Cable

DHT22 Digital Temperature and Humidity Sensor Module with Cable

Overview

The DHT22 (also known as AM2302) is a calibrated digital temperature and humidity sensor that combines a capacitive humidity element with a thermistor in a single 3-pin module. It outputs both readings on a single data line using a custom one-wire-like protocol, making it easy to use with virtually any microcontroller.

Compared to the older DHT11, the DHT22 offers a wider temperature range (-40°C to +80°C), better humidity accuracy (±2% RH), and finer resolution (0.1°C / 0.1% RH). The pre-soldered breakout board includes a 10k pull-up resistor on the data line and a stabilizing capacitor, so you can wire it directly to Arduino, ESP32, Raspberry Pi, or Pico without any external components.

At a Glance

Operating Voltage
3.3V - 5.5V
Temp Range
-40 to +80°C
Humidity Range
0 - 100% RH
Accuracy
±0.5°C / ±2% RH
Pin Count
3 pins
Pins
VCC, DATA, GND

Specifications

Parameter Value
Operating Voltage 3.3V - 5.5V DC
Operating Current 1.0 - 1.5 mA (measuring), 40 µA (standby)
Temperature Range -40°C to +80°C
Temperature Accuracy ±0.5°C
Humidity Range 0 - 100% RH
Humidity Accuracy ±2% RH (typical)
Resolution 0.1°C / 0.1% RH
Sampling Rate 0.5 Hz (one reading every 2 seconds)
Communication Protocol Single-wire digital (proprietary)
Onboard Pull-up 10kΩ on DATA line
Module Dimensions Approx. 22 x 28 mm

Pinout Diagram

DHT22 AM2302 pinout diagram showing VCC, DATA, and GND pins

Wiring Guide

Arduino Wiring

The DHT22 connects directly to any Arduino digital pin. The onboard 10k pull-up resistor handles signal idle-high, so no external components are needed.

DHT22 Pin Arduino Pin
VCC (+) 5V
DATA Digital Pin 2
GND GND
Tip: Use Adafruit's DHT sensor library for the easiest setup. Install it via the Arduino Library Manager (Sketch > Include Library > Manage Libraries).

ESP32 Wiring

ESP32 GPIO operates at 3.3V, and the DHT22 also works at 3.3V — no level shifting required. Power the module from the ESP32's 3V3 pin for cleanest signaling.

DHT22 Pin ESP32 Pin
VCC (+) 3V3
DATA GPIO 4
GND GND
Note: The DHT22 also runs fine on the ESP32's 5V/VIN rail, but powering it from 3V3 keeps the signal levels matched and avoids any input voltage concerns.

Raspberry Pi Wiring

The DHT22 works directly with Raspberry Pi 3.3V GPIO. Use any free GPIO pin for DATA. Software timing on Linux can occasionally miss frames, so consider using the Adafruit_DHT library which uses kernel-level timing.

DHT22 Pin Raspberry Pi Pin
VCC (+) Pin 1 (3.3V)
DATA Pin 7 (GPIO 4)
GND Pin 6 (GND)
Tip: If you see frequent CRC errors, retry the read after a short delay — the DHT22's strict timing sometimes drops frames under Linux scheduling jitter.

Raspberry Pi Pico Wiring

The Pico's 3.3V GPIO works perfectly with the DHT22. MicroPython has built-in DHT support via the dht module, so no external libraries are needed.

DHT22 Pin Pico Pin
VCC (+) 3V3 (OUT)
DATA GP15
GND GND

Code Examples

Arduino

dht22_arduino.ino
// DHT22 Temperature & Humidity Sensor - Arduino Example
// Requires Adafruit DHT sensor library

#include <DHT.h>

#define DHTPIN 2          // DATA pin connected to digital 2
#define DHTTYPE DHT22     // DHT 22 (AM2302)

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHT22 starting...");
  dht.begin();
}

void loop() {
  delay(2000);  // DHT22 needs ~2s between readings

  float h = dht.readHumidity();
  float t = dht.readTemperature();

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

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C");
}

Raspberry Pi (Python)

dht22_rpi.py
#!/usr/bin/env python3
# DHT22 - Raspberry Pi Example
# Install: pip install adafruit-circuitpython-dht
# Also: sudo apt install libgpiod2

import time
import board
import adafruit_dht

# DATA pin connected to GPIO 4 (physical pin 7)
dht = adafruit_dht.DHT22(board.D4)

while True:
    try:
        temp = dht.temperature
        humid = dht.humidity
        print(f"Temp: {temp:.1f} C  Humidity: {humid:.1f}%")
    except RuntimeError as e:
        # Reading failed (timing issue), just retry
        print("Read error:", e.args[0])
    time.sleep(2.0)

Raspberry Pi Pico (MicroPython)

dht22_pico.py
# DHT22 - Pico MicroPython Example
# Uses built-in dht module (no install needed)

from machine import Pin
import dht
import time

sensor = dht.DHT22(Pin(15))

while True:
    try:
        sensor.measure()
        t = sensor.temperature()
        h = sensor.humidity()
        print("Temp: {:.1f} C  Humidity: {:.1f}%".format(t, h))
    except OSError as e:
        print("Failed to read sensor:", e)
    time.sleep(2)

ESP32 (Arduino)

dht22_esp32.ino
// DHT22 - ESP32 Arduino Example
// Requires Adafruit DHT sensor library

#include <DHT.h>

#define DHTPIN 4          // DATA pin connected to GPIO 4
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

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

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println("DHT22 read failed");
    return;
  }
  Serial.printf("Temp: %.1f C  Humidity: %.1f%%\n", t, h);
}

Frequently Asked Questions

How is the DHT22 different from the DHT11?
The DHT22 has a wider temperature range (-40 to +80°C vs 0 to 50°C for DHT11), better humidity accuracy (±2% vs ±5%), and 0.1 resolution instead of 1. They use the same protocol, so you only change DHT11 to DHT22 in the library.
Do I need an external pull-up resistor?
No. This module already includes a 10kΩ pull-up resistor between DATA and VCC, plus a stabilizing capacitor. Wire VCC, DATA, and GND directly to your board.
Why am I getting NaN or "failed to read" errors?
Most often this means you read too quickly — the DHT22 needs at least 2 seconds between readings. Other causes: loose wiring, a power dip on the rail, or (on Raspberry Pi) Linux timing jitter. Add a delay(2000) between reads and check that VCC is solid 3.3V or 5V.
Can I run multiple DHT22 sensors on one microcontroller?
Yes. Each DHT22 needs its own digital data pin (the protocol isn't addressable like I2C). On Arduino, you'd create one DHT object per pin. ESP32 and Pico work the same way — just instantiate one sensor object per GPIO.
Will the DHT22 work outdoors?
The bare module is not weatherproof. For outdoor use, place it in a vented enclosure that protects it from rain and direct sun but still allows airflow over the sensor element. Avoid condensation — if water beads form on the housing, the readings will read 100% RH until it dries out.
Which library is best for the DHT22?
Arduino/ESP32: Adafruit's DHT sensor library is the standard. Raspberry Pi: use adafruit-circuitpython-dht with libgpiod for reliable timing. Pico: MicroPython has a built-in dht module — no install needed.

Related Tutorials