from machine import Pin
from time import sleep
import dht
from utime import sleep
sensor = dht.DHT22(Pin(15))
ledRojo = Pin(27, Pin.OUT)
ledNaranja = Pin(32, Pin.OUT)
ledAzul = Pin(26, Pin.OUT)
while True:
try:
sleep(2)
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
temp_f=temp * (9/5)+32.0
print('Temperature: %3.1f' %temp)
print('Temperature: %3.1f'%temp_f)
print('Humidity: %3.1f %%' %hum)
if temp>35.0:
print('temperatura alta')
ledNaranja.off()
ledAzul.off()
ledRojo.on()
sleep(0.5)
ledRojo.off()
sleep(0.5)
elif temp<=35 and temp>=20:
ledNaranja.off()
ledAzul.off()
print('temperatura agradable')
ledNaranja.on()
elif temp<20:
ledNaranja.off()
ledAzul.off()
ledAzul.on()
print('temperatura fria')
except OSError as e:
print('Failed to read sensor.')