Getting Started with DHT11/22 on Raspberry Pi Pico using MicroPython

Table of Contents
Abstract
In this article, a comprehensive step-by-step guide to interface DHT 11/22 temperature and humidity sensor with Raspberry Pi Pico board using MicroPython. Raspberry Pi Pico has 4 different variants (Pico, Pico 2, Pico W, Pico 2W) supporting micro-python. This articles lays the foundation for more advanced embedded system and IoT projects.
Pre-Request
- OS : Windows / Linux / Mac / Chrome
- Thonny IDE.
- MicroPython firmware in Raspberry Pi Pico / Pico 2 / Pico W / Pico 2W.
- For step by step procedure click here .
Hardware Required
- Raspberry Pi Pico / Pico 2 / Pico W / Pico 2W.
- DHT 11/22 sensor.
- BreadBoard.
- Micro USB Cable.
- Connecting wires.
- 5V DC power supply (Optional)
| Components | Purchase Link |
|---|---|
| Raspberry Pi Pico | link |
| Raspberry Pi Pico 2 | link |
| Raspberry Pi Pico W | link |
| Raspberry Pi Pico 2W | link |
| DHT 11/22 sensor | link |
| BreadBoard | large : small |
| Connecting Wires | link |
| Micro USB Cable | link |
| 5V DC Adaptor | link |
Don't own a hardware
No worries,
Still you can learn using simulation.
check out simulation part .
Connection Table
| DHT 11/22 | GPIO | Remarks |
|---|---|---|
| VCC (1) | +5 V | +5V of Board or External 5V DC Supply |
| Data (2) | 9 | Any GPIO pin can be used |
| NC (3) | - | No Connection |
| GND (4) | GND | Ground |
Note
- VCC (1) can be connected to external +5 V DC supply or to the VBUS pin number 40 of Raspberry Pi Pico Board.
- While using External 5 V supply for DHT 11/22 sensor, make sure ground pin of External Supply and Pico board is connected.

fig-Connection Diagram
Code
Code Explanation
Imports
timemodule for creating delay.dhtmodule for interacting with dht 11 or 22 sensor.
Initialize DHT 22 sensor.
- GPIO
9is connected to DHT 22 sensor Data pin2.
Continuous looping & measurement.
while Trueused for continuous looping.printstatement to display the measured temperature and humidity data on the terminal.sleep_ms(2000)2 second delay.
Read temperature and humidity data.
sensor.measure()used to initialize the sensor module to measure the parameters.sensor.temperature()reads temperature data from sensor.sensor.humidity()reads humidity data from sensor.
Simulation
Not able to view the simulation
- Desktop or Laptop : Reload this page ( Ctrl+R )
- Mobile : Use Landscape Mode and reload the page
Extras
Components details
- DHT 11 sensor : Data Sheet
- DHT 22 sensor : Data Sheet
- Raspberry Pi Pico / Pico 2 : Pin Diagram
- Raspberry Pi Pico : Data Sheet
- Raspberry Pi Pico 2 : Data Sheet
- Raspberry Pi Pico W : Data Sheet
- Raspberry Pi Pico 2 W : Data Sheet
Modules / Libraries Used
- time
timemodule provides functions related to date & time, measuring time intervals and generating delays.- More Details
- dht
- To interact with DHT 11/22 sensor.
- It is a built in library.
- More Details