from machine import Pin, PWM
import time
import dht
dht_sensor = dht.DHT22(Pin(12))
servo_pin_bomba = PWM(Pin(23), freq=50)
servo_pin_ventana = PWM(Pin(22), freq=50)
leda_pin = Pin(21, Pin.OUT)
ledv_pin = Pin(2, Pin.OUT)
def ventana(angle):
duty = int(40 + (angle/180) * 75)
servo_pin_ventana.duty(duty)
def bomba(angle):
duty = int(40 + (angle/180) * 75)
servo_pin_bomba.duty(duty)
while True:
dht_sensor.measure()
temp = dht_sensor.temperature()
hume = dht_sensor.humidity()
print("Temperatura: ", temp,"C")
print("Humedad: ", hume,"%")
if(temp>40):
ventana(135)
ledv_pin.on()
else:
ventana(90)
ledv_pin.off()
if(hume<30):
bomba(0)
leda_pin.on()
else:
bomba(90)
leda_pin.off()
time.sleep(1)