# modulos
from machine import I2C, Pin
from time import sleep
from pico_i2c_lcd import I2cLcd
from dht import DHT22
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
# direccion I2C
I2C_ADDR = i2c.scan()[0]
# crear objeto tipo lcd
dht = DHT22(Pin(5))
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
rele = Pin(16, Pin.OUT)
rele.value(0) # Inicia apagado
# loop
while True:
dht.measure()
temp = dht.temperature()
hum = dht.humidity()
print("Temperature: {}°C Humidity: {:.1f}% ".format(temp, hum))
lcd.clear()
lcd.putstr('Temp: ' + str(temp) + " C")
lcd.move_to(0,1)
lcd.putstr('Hum: ' + str(hum) + "%")
sleep(2)
def control_rele(temp):
if temp > 40: # Umbral de 40°C para activar
rele.value(1)
return "ON"
else:
rele.value(0)
return "OFF"
while True:
temp, hum = leer_sensor()
if temp is not None and hum is not None:
estado = control_rele(temp)
actualizar_lcd(temp, hum, estado)
rele = Pin(16, Pin.OUT)
while True:
rele.value(1) # Activa el relevador (LED ENCENDIDO)
time.sleep(2) # Espera 2 segundos
rele.value(0) # Desactiva el relevador (LED APAGADO)
time.sleep(2) # Espera 2 segundos