Build it step by step
0 of 6 doneWire the sensor
VCC to 3V3(OUT), GND, data to GP15 with a 10 kilo-ohm pull-up to 3V3(OUT).
Wire the display
SDA to GP0, SCL to GP1, power at 3.3 V.
Install the ssd1306 module
Using Thonny packages.
Save the program as main.py
On the Pico.
Run it
Temperature, humidity and a word appear.
Breathe gently near the sensor
Humidity rises and the word may change.
How do you build a pico comfort meter?
A Pico reads a DHT22 and shows temperature and humidity with a plain word for how the air feels: dry, comfortable or damp. You need Raspberry Pi Pico H, DHT22 Sensor, Resistor 10 kΩ, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 6 steps and about 130 minutes.
- Level
- Intermediate
- Time
- About 130 min
- Parts
- 5
Parts list
- Development BoardsBuy
- SensorsBuyDHT22 Sensor × 1
- PassivesBuyResistor 10 kΩ × 1
- DisplaysBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| DHT22 VCC | Pico 3V3(OUT) pin 36 | Power at 3.3 V |
| DHT22 GND | Pico GND pin 38 | Ground |
| DHT22 data | Pico GP15 pin 20 | Data line |
| 10 kilo-ohm resistor | Between data and 3V3(OUT) | Pull-up |
| OLED VCC and GND | Pico 3V3(OUT) and GND | Power at 3.3 V |
| OLED SDA and SCL | Pico GP0 pin 1 and GP1 pin 2 | I2C data and clock |
Code
The DHT22 measures humidity with a small capacitor whose value changes with moisture, and temperature with a thermistor, and sends both as numbers over one data wire. MicroPython has a dht module that does the timing for you. The sensor is slow, so it is read about every two seconds, and a read can fail, which the program catches and reports. The comfort word is a simple rule: under 30 percent is dry, 30 to 60 is comfortable and above 60 is damp. That is a rough guide for a living room and not advice about health or building damp. Readings are indicative only: a breath or a kettle moves them quickly, and the sensor is a few percent off at best. Keep it away from heat sources and direct sun so the temperature is honest.
import time
import dht
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
sensor = dht.DHT22(Pin(15))
def feel(h):
if h < 30:
return "Dry"
if h <= 60:
return "Comfortable"
return "Damp"
while True:
try:
sensor.measure()
t = sensor.temperature()
h = sensor.humidity()
oled.fill(0)
oled.text("Comfort meter", 0, 0)
oled.text("Temp: {:.1f} C".format(t), 0, 18)
oled.text("Humid: {:.0f} %".format(h), 0, 32)
oled.text(feel(h), 0, 50)
except OSError:
oled.fill(0)
oled.text("Sensor read failed", 0, 24)
oled.show()
time.sleep(2) # the sensor needs about 2 s between readsTest checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Room air | Plausible values and a word |
| Breath near the sensor | Humidity rises briefly |
| Unplug the data wire | Sensor read failed message |
| Dry air below 30 percent | Word shows Dry |
| Above 60 percent | Word shows Damp |
If it does not work
Sensor read failed
Check the data pin GP15, the pull-up and 3.3 V power.
ImportError for ssd1306
Install the micropython-ssd1306 package.
Blank screen
Check the OLED address 0x3C and the GP0 and GP1 wires.
Values jump
Keep the sensor away from heat and air flow.
Program does not start on power-up
Save it on the Pico as main.py.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the pico comfort meter?
Raspberry Pi Pico H, DHT22 Sensor, Resistor 10 kΩ, SSD1306 OLED Display and Breadboard 830 Tie Points.
How long does the pico comfort meter take to build?
About 130 minutes for a intermediate maker, in 6 steps.
How do I know the pico comfort meter works?
Room air: Plausible values and a word. Breath near the sensor: Humidity rises briefly. Unplug the data wire: Sensor read failed message.
Sensor read failed: what should I check?
Check the data pin GP15, the pull-up and 3.3 V power.
ImportError for ssd1306: what should I check?
Install the micropython-ssd1306 package.
Blank screen: what should I check?
Check the OLED address 0x3C and the GP0 and GP1 wires.
Values jump: what should I check?
Keep the sensor away from heat and air flow.
