from machine import Pin
from dht import DHT22
from time import sleep
dht = DHT22(Pin(14))
led = Pin(23, Pin.OUT)
temp_threshold = 30
hmd_threshold = 40
while True:
sleep(0.02)
dht.measure()
temp = dht.temperature()
hmd = dht.humidity()
print(f"Temperature: {temp}°C")
print(f"Humidity: {hmd}%")
if temp > temp_threshold or hmd < hmd_threshold:
led.value(1)
sleep(0.2)
led.value(0)
sleep(0.2)
print("Attention!, Abnormal Temperature or Humidity")
else:
led.off()
sleep(1)