#importar modulos
#importar modulos
import network, time, urequests
from machine import Pin, ADC
from utime import sleep,sleep_ms
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#crear objetos
SensorI = Pin(12,Pin.IN)
ledRojo= Pin (25,Pin.OUT)
ledVerde=Pin (33,Pin.OUT)
zumbador = Pin(2,Pin.OUT)
rele = Pin(4, Pin.OUT)
rele2 = Pin(19,Pin.OUT)
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#conectando a la red con Wifi
def conectaWifi (red, password):
global miRed
miRed = network.WLAN(network.STA_IF)
if not miRed.isconnected(): #Si no está conectado…
miRed.active(True) #activa la interface
miRed.connect(red, password) #Intenta conectar con la red
print('Conectando a la red', red +"…")
timeout = time.time ()
while not miRed.isconnected(): #Mientras no se conecte..
if (time.ticks_diff (time.time (), timeout) > 10):
return False
return True
if conectaWifi ("Wokwi-GUEST", ""):
print ("Conexión exitosa!")
print('Datos de la red (IP/netmask/gw/DNS):', miRed.ifconfig())
url=" https://api.thingspeak.com/update?api_key=70GJCBYGM46TSWRB"
while True:
medicion = SensorI.value()
print(medicion)
if medicion == 1:
ledRojo.value(0)
ledVerde.value(1)
zumbador.value(1)
print("hay alguien")
time.sleep(1)
rele2.value(0)
rele.value(1)
print("se prende el motor para abrir puerta ")
time.sleep(3)
time.sleep(0)
elif medicion == 0:
ledRojo.value(1)
ledVerde.value(0)
zumbador.value(0)
print("hay alguien")
time.sleep(1)
rele.value(0)
rele2.value(1)
time.sleep(0)
print("se prende el motor para cerrar puerta ")
time.sleep(3)