from machine import Pin
import time
import dht
led = Pin(5, Pin.OUT)
led2 = Pin(18, Pin.OUT)
sensor = dht.DHT22(Pin(14))
'''
if the degree over 40C -> The light turns on
if the degree below 40C -> The light turns off
if the humidity is over 50% -> The second light (led2) turns on
if the humidity is below 50% -> The second light (led2) turns off
'''
while True:
sensor.measure() # read the parameters from the sensor
t = sensor.temperature()
h = sensor.humidity()
if t > 40:
led.on()
else:
led.off()
if h > 50:
led2.on() # Turn on the humidity LED
else:
led2.off() # Turn off the humidity LED
time.sleep(1)