Blog
ESP32 DHT22: Wiring, Readings, Fixes
DHT22 wiring is three wires and a pull-up resistor — the failures are where everyone spends the evening. Here’s what to connect where, and what to do when the readings come back wrong.
How to Connect DHT22 to ESP32?
Three wires: VCC→3V3, DATA→a GPIO, GND→GND, with a 10k pull-up between DATA and VCC — most breakout modules already solder that on, bare sensors don’t. Avoid GPIO0, 2, 12, and 15 for DATA; they’re strapping pins and can fight the boot process. First read happens roughly one second after power-on; the sensor needs that time to start.
How to Connect DHT11 to ESP32?
Identical wiring, one difference: DHT11 tops out at one reading per second, so don’t hammer it in a loop. VCC→3V3, DATA→GPIO, GND→GND, pull-up included on most modules. If you’re choosing, the DHT22 costs a little more and reads four times the precision; the DHT11 is the budget part.
How to Connect DHT11 Sensor to ESP32?
Same three-pin story as the DHT22: VCC→3V3, DATA→a free GPIO, GND→GND, and a 10k pull-up if your module lacks one. The DHT11 sensor module with the onboard LED is fine to use; the LED just blinks on data traffic. Power the sensor from the same 3V3 rail as the chip — mixing rails is where weird readings start.
What’s the difference between DHT11 and DHT22?
Accuracy and speed. DHT22 reads ±0.5°C and ±2% RH at 0.5Hz; DHT11 does ±2°C and ±5% RH at 1Hz, and its humidity floor stops at 20%. For a greenhouse or a heater controller the DHT22 is worth the extra dollar; for “is the room hot” the DHT11 suffices.
Why does my DHT22 return NaN or 0?
Nine times out of ten it’s wiring or the pull-up; a distant tenth is the pin choice. I chased NaN for an hour on an ESP32-C3 Mini before moving DATA off GPIO12 — a strapping pin that boots low and confuses the sensor’s handshake. Serial.println() the raw read error code; the DHT libraries tell you exactly which step failed.
Do I need a pull-up resistor for DHT22?
With a breakout module, no — check for one of the two little SMD resistors near DATA. With a bare DHT22, yes: 10k between DATA and VCC is the standard value, and 4.7k also works. Wire runs over 50cm start needing a smaller pull-up; the official docs are thin on this, so treat it as “mostly works at 10k, test yours”.
Which library should I use for DHT on ESP32?
Adafruit DHT sensor library plus Adafruit Unified Sensor is the common pair; SimpleDHT is fine when you want zero dependencies. Both return error codes instead of garbage, which beats hand-rolling the 40-bit protocol. Example sketches for both libraries are here.
Why do my DHT22 readings jump around?
Power and timing, in that order. Wi-Fi transmit spikes can drop the rail mid-read; the DHT bit-bangs 40 bits over ~20ms and a brownout mid-word reads as nonsense. Wait the full 2 seconds between reads (DHT22 spec) and watch the supply if it’s battery-powered. Longer jumper wires also stretch the timing margins — depends on your board, so shorten them first.
Can I power DHT22 from 3.3V?
Yes — DHT22 officially runs 3.3-5.5V, so 3V3 is inside spec and keeps the DATA line safely at logic level. Feeding it 5V is fine too, but then the DATA high sits at 5V into a 3.3V pin; it usually survives, though a divider is the polite approach. Keep the pull-up on the same rail as VCC, whatever you choose.
How often can I read DHT22?
Every 2 seconds, max — DHT22’s datasheet says 0.5Hz, and asking faster mostly returns stale data or NaN. DHT11 is 1Hz. That’s a hard floor, not a suggestion; plenty of projects have melted their sanity trying to read faster. For 20Hz+ sensing you want a digital sensor like a BME280 or SHT3x instead. The power FAQ covers running sensors long-term.
Read a DHT22 on ESP32 Right Now — In Your Browser
You do not need hardware to try this — our free simulator runs the real sketch, compiled by arduino-cli, on an emulated ESP32:
- DHT22 temperature & humidity on ESP32 — full wiring table, sketch and expected output.
The Serial Monitor behaves exactly like the bench does:
ESP32 DHT22 ready!
Temp: 24.3 C Humidity: 47.5 %
Temp: 24.2 C Humidity: 47.8 %
Right after the sensor appears you may see one DHT22: waiting for sensor... line — that is the NaN branch firing on the first read, the same harmless checksum hiccup you meet on real hardware. The example also covers the 10 kΩ pull-up and the two-second polling limit, so the FAQ above maps one-to-one onto something you just ran.