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.

Fix “Failed to read from DHT sensor!” (DHT22 / DHT11)

The DHT library got no valid reply. Check the data pin, the pull-up resistor, the sensor type in code, power, and the 2-second minimum between reads.

ESP32Arduino UnoESP8266Raspberry Pi PicoUpdated 31 Oct 2026

Community draft — report a mistake

What you see

OutputOutput
DHT22 on GPIO4 — first reading in 2 s
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!

The DHT22 talks over a single, timing-sensitive data wire. “Failed to read from DHT sensor!” means the reply was missing or corrupted. Almost every case is wiring (pin, pull-up, power) or reading too often.

Quick fix — try in order

  1. 1

    Check DHTTYPE matches the sensor

    DHT22 (white, AM2302) and DHT11 (blue) use different timing. #define DHTTYPE DHT22 for a DHT22.

  2. 2

    Check the data pin number

    The pin in DHT dht(PIN, DHTTYPE) must be the GPIO you wired, e.g. 4 for D4 on an ESP32 DevKit V1.

  3. 3

    Add the 10 kΩ pull-up (bare sensor)

    The 4-pin sensor needs 10 kΩ from DATA to VCC. 3-pin breakout boards already have it. See the DHT22 page.

  4. 4

    Wait at least 2 seconds between reads

    The DHT22 cannot be read faster than every 2 s; reading in a tight loop returns NaN.

  5. 5

    Power it from the same voltage as the board logic

    On ESP32 use 3V3, so the data line never exceeds 3.3 V. Keep wires under about 1 m without a stronger pull-up.

Why it happens

Why do I get NaN?

The library returns NaN when the 40-bit reply fails its checksum or never arrives. isnan(t) is how the example detects it and prints this message.

Wrong pin type on ESP32

Strapping pins (0, 2, 5, 12, 15) and input-only pins (34–39) cause trouble; GPIO4, 16, 17, 18 and 19 are reliable. Our guide uses DHT22 on GPIO4.

Library version

Use the Adafruit “DHT sensor library” plus “Adafruit Unified Sensor”; very old or fork libraries have timing bugs on ESP32.

Damaged or fake sensor

If a known-good sketch and wiring still fail, try another sensor — cheap DHT11s often fail early.

Board-specific notes

Arduino Uno: Power from 5V and use D2. See DHT22 with Uno.

Raspberry Pi Pico W: MicroPython’s dht module raises OSError: [Errno 110] ETIMEDOUT instead. See DHT22 with Pico W.

Parts: DHT22 · DHT11 — pinout, voltage and library notes.

↑↓ to move · Enter to open