View Categories

DHT11/DHT22 – RPI Pico

Wiring #

DS18B20Raspberry Pi Pico
GNDGND
DataAny digital GPIO (we’ll be using GPIO22);
you also need to connect a 4.7KOhm resistor between the data line and VCC
VDD3V3(OUT)

Read DHT11/22 sensor (micropython) #

from machine import Pin
from time import sleep
import dht 

sensor = dht.DHT22(Pin(22))
#sensor = dht.DHT11(Pin(22))

while True:
  try:
    sleep(2)
    sensor.measure()
    temp = sensor.temperature()
    hum = sensor.humidity()
    temp_f = temp * (9/5) + 32.0
    print('Temperature: %3.1f C' %temp)
    print('Temperature: %3.1f F' %temp_f)
    print('Humidity: %3.1f %%' %hum)
  except OSError as e:
    print('Failed to read sensor.')

Thonny output


Products #


Source #