from machine import I2C,Pin
from i2c_lcd import I2cLcd
from time import sleep
import dht
sensor=dht.DHT22(Pin(33))
AddressOfLcd=0X27
i2c=I2C(scl=Pin(22),sda=Pin(21),freq=400000)
lcd=I2cLcd(i2c,AddressOfLcd,2,16)
led1 = Pin(32,Pin.OUT)
led2 = Pin(25,Pin.OUT)
led3 = Pin(26,Pin.OUT)
while True:
try:
sleep(2)
sensor.measure()
temp=sensor.temperature()
lcd.move_to(3,0)
lcd.putstr('Tempertura')
if temp < 10:
lcd.move_to(0,1)
lcd.putstr("Frio")
led1.value(1)
sleep(0.5)
elif temp > 10 and temp < 20:
lcd.move_to(0,1)
lcd.putstr("Tibio")
led2.value(1)
sleep(0.5)
else:
lcd.move_to(0,1)
lcd.putstr("Caliente")
led3.value(1)
sleep(0.5)
led1.value(0)
led2.value(0)
led3.value(0)
sleep(0.5)
except OSError as e:
print("Failed to read sensor!!!")