#Por Erick Bocardo
from machine import Pin, ADC, PWM
from time import sleep
import dht
sensor_dht = dht.DHT22(Pin(28))
pot_max = ADC(Pin(26))
pot_min = ADC(Pin(27))
buzzer = PWM(Pin(15))
buzzer.freq(1000)
relevador = Pin(14, Pin.OUT)
def pot_a_temp(valor_pot):
return int((valor_pot / 65535) * 120-40)
while True:
# Lee la temperatura y humedad desde el DHT22
sensor_dht.measure()
temp_actual = sensor_dht.temperature() # Temperatura en °C
# Lee los valores de los potenciómetros
temp_max = pot_a_temp(pot_max.read_u16())
temp_min = pot_a_temp(pot_min.read_u16())
# Activa el buzzer si la temperatura supera el máximo
if temp_actual > temp_max:
buzzer.duty_u16(30000)
else:
buzzer.duty_u16(0)
# Activa el relevador si la temperatura está por debajo del mínimo
if temp_actual < temp_min:
relevador.value(1)
else:
relevador.value(0)
print("Temp Mínima:", temp_min, "°C, Temp Máxima:", temp_max, "°C, Temp Actual:", temp_actual, "°C")
sleep(1)