Raspberry Pi Pico DHT22 Sensor: Wiring, Code and Simulator

To build this Raspberry Pi Pico DHT22 Sensor project you need a Raspberry Pi Pico and a DHT22 temperature & humidity sensor. MicroPython built-in dht module reads a DHT22 on GP15 every two seconds. Make the 3 connections in the wiring table, upload the MicroPython code, and move the temperature and humidity sliders; the next reading follows.

Open this circuit in the free Raspberry Pi Pico simulator

Parts list

QtyPartWhat it does
1Raspberry Pi Picothe microcontroller board
1DHT22 temperature & humidity sensorSDA (data) to a pin, VCC to 5V, GND to GND. Read it with the DHT library (type DHT22).

Wiring

#FromTo
1Raspberry Pi Pico 3V3DHT22 temperature & humidity sensor VCC
2Raspberry Pi Pico GP15DHT22 temperature & humidity sensor SDA
3Raspberry Pi Pico GNDDHT22 temperature & humidity sensor GND

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Raspberry Pi Pico. No install or account is needed.
  2. Add the parts. Add a DHT22 temperature & humidity sensor from the parts palette.
  3. Wire 1. Connect Raspberry Pi Pico 3V3 to DHT22 temperature & humidity sensor VCC.
  4. Wire 2. Connect Raspberry Pi Pico GP15 to DHT22 temperature & humidity sensor SDA.
  5. Wire 3. Connect Raspberry Pi Pico GND to DHT22 temperature & humidity sensor GND.
  6. Paste the MicroPython code. Paste the MicroPython code below into the code editor.
  7. Run it. Press Run. Move the temperature and humidity sliders; the next reading follows.

MicroPython code

# Weather station: a DHT22 on GP15, read with MicroPython's built-in dht module.
from machine import Pin
import dht
import time

sensor = dht.DHT22(Pin(15))

while True:
    try:
        sensor.measure()
        print("Temperature: {:.1f} C  Humidity: {:.1f} %".format(sensor.temperature(), sensor.humidity()))
    except OSError:
        print("DHT22 did not answer. Check the wiring.")
    time.sleep(2)

What to try

Move the temperature and humidity sliders; the next reading follows.

Frequently asked questions

How do I wire the DHT22 Sensor project on a Raspberry Pi Pico?

Make 3 connections: Raspberry Pi Pico 3V3 to DHT22 temperature & humidity sensor VCC; Raspberry Pi Pico GP15 to DHT22 temperature & humidity sensor SDA; Raspberry Pi Pico GND to DHT22 temperature & humidity sensor GND.

What parts do I need for this Raspberry Pi Pico project?

A Raspberry Pi Pico and a DHT22 temperature & humidity sensor.

Can I simulate this Raspberry Pi Pico project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and MicroPython code in your browser for free, with no install and no hardware. The RP2040 is emulated and runs the official firmware.

What does the code do?

MicroPython built-in dht module reads a DHT22 on GP15 every two seconds.

More Raspberry Pi Pico projects