DHT22 (AM2302)
DHT22 / AM2302 pinout, 3.3 V vs 5 V wiring, the pull-up it needs, the 2-second read limit and fixes for "Failed to read from DHT sensor".
Community draft — report a mistake
3.3 V or 5 V? Works at 3.3 V and 5 V. Power it from the same voltage as your board (3.3 V on ESP32 and Pico, 5 V on Uno), so the data line never exceeds the GPIO limit.
The DHT22 (sold as the AM2302 when it comes in the wired case) measures −40 to 80 °C to ±0.5 °C and 0–100 % relative humidity to ±2–5 %. It’s slow — one new reading every 2 seconds at most — but cheap and good enough for rooms, greenhouses and weather boxes.
It talks over its own single-wire protocol, not I2C or 1-Wire, so it needs one free GPIO and the Adafruit library.
Two versions are sold. The bare sensor has 4 pins (VCC, DATA, NC, GND) and needs an external pull-up. The red or blue 3-pin breakout already has the resistor and only brings out VCC, DATA and GND — read the labels printed on it, because the pin order varies between makers.
Pinout
| Pin | What it does |
|---|---|
1 VCC | 3.3–6 V supply |
2 DATA | Single-wire data. Needs a 4.7–10 kΩ pull-up to VCC — 3-pin modules already have it on the board. |
3 NC | Not connected — leave it free |
4 GND | Ground, shared with the board |
Library
DHT sensor library by Adafruit (also install Adafruit Unified Sensor)
Arduino IDE → Library Manager → search the name above. Each guide lists the exact version we compile against.
Use it with
- DHT22 (AM2302) with Arduino Mega 2560 Arduino C++
- DHT22 (AM2302) with Arduino Nano Arduino C++
- DHT22 (AM2302) with Arduino Nano ESP32 Arduino C++
- DHT22 (AM2302) with Arduino Pro Mini (5 V) Arduino C++
- DHT22 (AM2302) with Arduino Uno R3 Arduino C++
- DHT22 (AM2302) with ESP32-C3 SuperMini Arduino C++
- DHT22 (AM2302) with ESP32-C6-DevKitC-1 Arduino C++
- DHT22 (AM2302) with ESP32 DevKit V1 Arduino C++
- DHT22 (AM2302) with ESP32 DevKitC (38-pin) Arduino C++
- DHT22 (AM2302) with ESP32-S3-DevKitC-1 Arduino C++
- DHT22 (AM2302) with LOLIN S2 Mini Arduino C++
- DHT22 (AM2302) with NodeMCU ESP8266 Arduino C++
- DHT22 (AM2302) with Raspberry Pi Pico W MicroPython
- DHT22 (AM2302) with Wemos D1 mini Arduino C++
- DHT22 (AM2302) with XIAO ESP32C3 Arduino C++
- DHT22 (AM2302) with XIAO ESP32S3 Arduino C++
Common errors
“Failed to read from DHT sensor!” or NaN readings
Check the pull-up on DATA (bare 4-pin sensors need one), the pin number in DHTPIN, and that you read no faster than once every 2 seconds.
Readings stuck or jumping by several degrees
The sensor warms up if it sits next to the regulator or the ESP32 module. Mount it on a short cable away from the board and from direct sun.
Works on the bench, fails on a long cable
Keep the cable under about 3 m and use a stronger pull-up (4.7 kΩ). For longer runs, switch to an I2C sensor such as the BME280 or SHT31.