Datasheet

If you are using a DHT11, change the code to use a adafruit_dht.DHT11(board.D2) object.
Open the REPL to see the output! Breathe on the sensor to see it move temperature and humidity up (unless you are a
White Walker in which case the temperature will go down)
import time
import adafruit_dht
import board
dht = adafruit_dht.DHT22(board.D2)
while True:
try:
temperature = dht.temperature
humidity = dht.humidity
# Print what we got to the REPL
print("Temp: {:.1f} *C \t Humidity: {}%".format(temperature, humidity))
except RuntimeError as e:
# Reading doesn't always work! Just print error and we'll try again
print("Reading from DHT failure: ", e.args)
time.sleep(1)
© Adafruit Industries https://learn.adafruit.com/adafruit-gemma-m0 Page 136 of 186