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
| Qty | Part | What it does |
|---|---|---|
| 1 | Raspberry Pi Pico | the microcontroller board |
| 1 | DHT22 temperature & humidity sensor | SDA (data) to a pin, VCC to 5V, GND to GND. Read it with the DHT library (type DHT22). |
Wiring
| # | From | To |
|---|---|---|
| 1 | Raspberry Pi Pico 3V3 | DHT22 temperature & humidity sensor VCC |
| 2 | Raspberry Pi Pico GP15 | DHT22 temperature & humidity sensor SDA |
| 3 | Raspberry Pi Pico GND | DHT22 temperature & humidity sensor GND |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Raspberry Pi Pico. No install or account is needed.
- Add the parts. Add a DHT22 temperature & humidity sensor from the parts palette.
- Wire 1. Connect Raspberry Pi Pico 3V3 to DHT22 temperature & humidity sensor VCC.
- Wire 2. Connect Raspberry Pi Pico GP15 to DHT22 temperature & humidity sensor SDA.
- Wire 3. Connect Raspberry Pi Pico GND to DHT22 temperature & humidity sensor GND.
- Paste the MicroPython code. Paste the MicroPython code below into the code editor.
- 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
- Raspberry Pi Pico LED Blink: Wiring, Code and Simulator
- Raspberry Pi Pico Push Button: Wiring, Code and Simulator
- Raspberry Pi Pico ADC + PWM LED Dimmer: Wiring, Code and Simulator
- Raspberry Pi Pico NeoPixel Ring: Wiring, Code and Simulator
- Raspberry Pi Pico I2C LCD: Wiring, Code and Simulator
- Raspberry Pi Pico LED Blink: Wiring, Code and Simulator