Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

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

CategorySensor
InterfaceSingle-wire
Voltage3.3–6 V
Typical price₹280

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

PinWhat it does
1 VCC3.3–6 V supply
2 DATASingle-wire data. Needs a 4.7–10 kΩ pull-up to VCC — 3-pin modules already have it on the board.
3 NCNot connected — leave it free
4 GNDGround, 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

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.

↑↓ to move · Enter to open