"""
MicroPython IoT Weather Station Example for Wokwi.com
Now click on the DHT22 sensor in the simulation,
change the temperature/humidity, and you should see
LEDs change color like:
Izquierdo (Temperatura)
AZUL = temperature < 0
VERDE = temperature >= 0 and temperature < 30
ROJO = cualquier otro valor de temperatura
Derecho (Humedad)
AZUL = humedad < 25
VERDE = humedad >= 25 and humedad < 80
ROJO = cualquier otro valor de humedad
"""
import time
from machine import Pin
import dht
LedR = Pin(25, Pin.OUT, value=0) # create output pin on GPIO25 inicializado en 0
LedB = Pin(26, Pin.OUT, value=0) # create output pin on GPIO25 inicializado en 0
LedG = Pin(27, Pin.OUT, value=0) # create output pin on GPIO25 inicializado en 0
LedR_H = Pin(18, Pin.OUT, value=0) # create output pin on GPIO25 inicializado en 0
LedB_H = Pin(17, Pin.OUT, value=0) # create output pin on GPIO25 inicializado en 0
LedG_H = Pin(5, Pin.OUT, value=0) # create output pin on GPIO25 inicializado en 0
sensor = dht.DHT22(Pin(33))
prev_weather = ""
while True:
print("Measuring weather conditions... ", end="")
sensor.measure()
temperature = sensor.temperature()
humedad = sensor.humidity()
message = "temp: {}, humedad: {}".format(temperature, humedad)
if temperature < 5:
LedG.off()
LedR.off()
LedB.on()
elif temperature >= 5 and temperature < 30:
LedG.on()
LedR.off()
LedB.off()
else:
LedG.off()
LedB.off()
LedR.on()
if humedad < 25:
LedG_H.off()
LedR_H.off()
LedB_H.on()
elif humedad >= 25 and humedad < 80:
LedG_H.on()
LedR_H.off()
LedB_H.off()
else:
LedG_H.off()
LedB_H.off()
LedR_H.on()
if message != prev_weather:
print("Updated!")
print('Reporting update: {}'.format(message))
prev_weather = message
else:
print("No change")
time.sleep(0.25)