from machine import I2C,Pin
from picozero import Speaker
from time import sleep
from dht import DHT22
from pico_i2c_lcd import I2cLcd
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
I2C_ADDR = i2c.scan()[0]
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
dht = DHT22(Pin(15))
speaker = Speaker(5)
LED1 = Pin(8, Pin.OUT)
LED2 = Pin(20,Pin.OUT)
while True:
dht.measure()
temp = dht.temperature()
hum = dht.humidity()
print(f"Temperature: {temp}°C Humidity: {hum}% ")
lcd.move_to(0,0)
lcd.putstr(f"T: {temp}°C")
lcd.move_to(0,1)
lcd.putstr(f"H: {hum}%")
if(temp>20):
LED2.off()
LED1.on()
speaker.on()
sleep(1)
speaker.off()
sleep(1)
else:
LED1.off()
LED2.on()
sleep(2)