from machine import Pin, PWM, ADC
from dht import DHT22
from time import sleep
import time
import utime
def main():
#Declaracion del sensor de movimienton con su respectivo servomotor
servo1 = PWM(Pin(21), freq = 50)
sensorm = ADC (Pin(13))
#Declaracion de pines del sensor de temperatura y su servomotor
servo2 = PWM(Pin(19), freq = 50)
sensordht = DHT22(Pin(15))
convert1 = 180.0
convert2 = 90.0
#Declaracion de pines del la fotoresistencia
sensorf = ADC(Pin(2))
led = Pin(2, Pin.OUT)
sensorf.width(ADC.WIDTH_12BIT)
sensorf.atten(ADC.ATTN_11BD)
while True:
dato = int(sensorm.read())
convert = dato * 180/4095
print("Dato del sensor: ",dato)
time.sleep(1)
if convert >= 0 and convert <=180:
duty = ((3.06084 * convert ** 2 + 10278 * convert + 550000))
conversion = duty/1000000
mili = int(conversion * 1023/20)
servo1.duty(mili)
else:
print("Por favor digite un angulo entre o y 180: ")
#while True:
sensordht.measure()
tem = int(sensordht.temperature())
hum = int(sensordht.humidity())
time.sleep(1)
print("Valor de la temperatura: ",tem,"Valor de la humedad: " ,hum)
if tem >= 0 and tem <= 26:
duty1 = ((3.06084 * convert1 ** 2 + 10278 * convert1 + 550000))
conversion1 = duty1/1000000
mili1 = int(conversion1 * 1023/20)
servo2.duty(mili1)
else:
duty1 = ((3.06084 * convert2 ** 2 + 10278 * convert2 + 550000))
conversion1 = duty1/1000000
mili1 = int(conversion1 * 1023 / 20)
servo2.duty(mili1)
lectura = int (sensorf.read())
print(lectura)
utime.sleep(0.5)
if lectura >= 1000:
led.value(1)
print("Led encedido")
utime.sleep("2")
else:
led.value(0)
print("Led apagado")
utime.sleep(2)
if __name__ == '__main__':
main()