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 with Raspberry Pi Pico W — MicroPython wiring and code

Wire a DHT22 / AM2302 to a Raspberry Pi Pico W on GP15 at 3.3 V and read temperature and humidity with the built-in MicroPython dht module.

MicroPythonVerified — micropython (mpy-cross v1.29.0), 3 Nov 2026Compile-only

Community draft — report a mistake

MicroPython on the Pico W ships with a dht driver, so reading a DHT22 takes about ten lines and no libraries.

Wire the sensor to 3V3 and GP15 (physical pin 20). The script measures every two seconds and prints the result; if the sensor doesn’t answer, it reports the error and tries again instead of crashing.

Wiring

Raspberry Pi Pico WOnly the pins used are shown · 3.3 V logicDHT22 (AM2302)10k → 3V3GNDGP153V31 VCC2 DATA3 NC (not connected)4 GND
Every connection
Raspberry Pi Pico WDHT22 (AM2302)WireNotes
3V31 VCCred3V3 is physical pin 36
GP152 DATAyellowPhysical pin 20
3V32 DATAredVia 10 kΩ — Pull-up for the bare 4-pin sensor. 3-pin breakouts already have it — skip this wire.
GND4 GNDblack

3.3–6 V part, 3.3 V board. 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.

Board quirks

  • Use 3V3 (pin 36), not VBUS or VSYS — those carry 5 V on USB, and the Pico’s pins are 3.3 V only.
  • The dht module is built into MicroPython for the Pico W; there is nothing to install.
  • Save the file as main.py on the board so it runs at power-up without Thonny.

Code

main.pyMicroPython
# DHT22 temperature + humidity on a Raspberry Pi Pico W (MicroPython).
# DATA -> GP15, VCC -> 3V3 (pin 36), GND -> GND, 10 kOhm pull-up DATA -> 3V3 (breakouts have one).
from machine import Pin
import dht
import time

sensor = dht.DHT22(Pin(15))
print("DHT22 on GP15 - first reading in 2 s")

while True:
    time.sleep(2)  # the DHT22 can't be read faster than once every 2 s
    try:
        sensor.measure()
    except OSError:
        print("Failed to read from DHT sensor - check wiring and pull-up")
        continue
    t = sensor.temperature()
    h = sensor.humidity()
    print("Temp {:.1f} C  Humidity {:.1f} %".format(t, h))

Expected serial output

REPL / Thonny shellOutput
DHT22 on GP15 - first reading in 2 s
Temp 27.6 C  Humidity 62.3 %
Temp 27.6 C  Humidity 62.1 %

Common errors

OSError: [Errno 110] ETIMEDOUT

The sensor did not answer. Check the pull-up on a bare sensor, that DATA is on GP15 (physical pin 20), and the 3V3 supply.

ImportError: no module named dht

The official MicroPython builds for every Raspberry Pi Pico board include dht, so you are on a very old or third-party firmware, or a file named dht.py on the board is hiding the built-in one. Reflash the RPI_PICO_W build from micropython.org and delete any dht.py you copied over.

↑↓ to move · Enter to open