from machine import Pin
from time import sleep_ms
import dht
d = dht.DHT11(Pin(23))
led = Pin(2, Pin.OUT)
while True:
try:
d.measure()
temp = d.temperature() # ํC
humid = d.humidity() # %RH
print('Temp:', temp, 'Humid:', humid)
sleep_ms(1000)
if temp > 20 and humid > 50:
led.on()
print('Normal.....')
else:
led.off()
print('Warm.....')
except OSError as e:
print('Failed to read sensor!')