Skip to content

Sensing Temperature and Humidity with the DHT11 Sensor

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from machine import Pin
import utime as time
from dht import DHT11, InvalidChecksum

DHT_PIN = 15
# this is a bit odd, since although it is an input, we need a pull down set
dhtSensor = DHT11(Pin(DHT_PIN, Pin.OUT, Pin.PULL_DOWN))

while True:
    temp = dhtSensor.temperature
    humidity = dhtSensor.humidity/100
    print("Temp: {}°C".format(temp),  "| Hum: {0:.1%}".format(humidity))

References