import dht
import time
from machine import Pin
sensor = dht.DHT22(Pin(2))
led = Pin(16, Pin.OUT)
while True:
try:
sensor.measure()
temp = sensor.temperature()
umid = sensor.humidity()
print("Temperatura:" , temp)
print("ºC | Umidade:" , umid, "%")
if temp > 28:
led.on()
print("Temperatura:", temp, "ºC -> Led LIGADO")
else:
led.off()
print("Temperatura:", temp, " ºC -> LED DESLIGADO")
except OSError as e:
print("Falha ao ler o DHT22:", e)
time.sleep(2)