from machine import Pin
from time import sleep
import dht
sensor = dht.DHT22(Pin(22))
#sensor = dht.DHT11(Pin(22))
def check_conditions():
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('Humidity: %3.1f %%' %hum)
if temp > 25 and hum > 60:
print("Temperature and humidity are both high.")
elif temp > 25:
print("Temperature is high.")
elif hum > 60:
print("Humidity is high.")
else:
print("Temperature and humidity are both good.")
except OSError as e:
print('Failed to read sensor.')
while True:
check_conditions()