from machine import Pin
from time import sleep_ms
import dht
d = dht.DHT11(Pin(23))
led1 = Pin(2, Pin.OUT)
led2 = Pin(4, Pin.OUT)
button = Pin(22, Pin.IN)
while True:
try:
sw = button.value()
d.measure()
temp = d.temperature()# ํC
humid = d.humidity() #%RH
print('Temp:', temp, 'Humid:', humid)
sleep_ms(1000)
#Auto system
if temp > 20 and humid > 40:
led1.on()
print('Normal.....')
else:
led1.off()
print('Warm....')
#Manual system
if sw == 1:
led2.on()
sleep_ms(500)
print('LED2 ON')
else:
led2.off()
sleep_ms(500)
print('LED2 OFF')
except OSError as e:
print('Failed to read sensor!')