In this experiment, we learn how to read temperature and humidity values from a DHT22 sensor using a Raspberry Pi Pico. The measured data is displayed on a 16×2 I2C LCD, and a buzzer alert is triggered when the temperature or humidity exceeds set thresholds.
Buy Basic Raspberry Pi Pico Kit
Note:
If you’re using a DHT11 sensor, make sure to change `DHT22` to `DHT11` in the code.
Items Required:
- Raspberry Pi Pico – 1 Nos.
- DHT11 Temperature and Humidity Sensor – 1 Nos.
- 16×2 I2C LCD Module – 1 Nos.
- Active Buzzer – 1 Nos.(Optional)
- Jumper wires (M/M) – as needed
- Breadboard – 1 Nos. (optional)
- USB cable Micro B– 1 Nos.
Connections:
DHT22 → GPIO 22 (Pico)
I2C LCD SDA → GPIO 0 (Pico)
I2C LCD SCL → GPIO 1 (Pico)
Buzzer → GPIO 26 (Pico)(optional)
VCC and GND for all components appropriately


Result:
The Raspberry Pi Pico reads the temperature and humidity values every few seconds from the DHT22 sensor. These values are displayed on the 16×2 LCD. If the temperature exceeds 20°C or humidity exceeds 30%, the buzzer will beep as an alert.