# modules
from machine import Pin,PWM
from time import sleep
from dht import DHT22
from machine import I2C, Pin
from pico_i2c_lcd import I2cLcd
def buzzerFunc():
buzzer= PWM(Pin(26))
buzzer.freq(500)
buzzer.duty_u16(1000)
sleep(1)
buzzer.duty_u16(0)
# creating a DHT object
# change DHT22 to DHT11 if DHT11 is used
dht = DHT22(Pin(22))
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
# getting I2C address
I2C_ADDR = i2c.scan()[0]
# creating an LCD object using the I2C address and specifying number of rows and columns in the LCD
# LCD number of rows = 2, number of columns = 16
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
# continuously get sensor readings while the board has power
while True:
# getting sensor readings
dht.measure()
temp = dht.temperature()
# displaying values to the console
print(f"Temperature: {temp}°C ")
lcd.putstr(f" Temp: {temp}°C")
sleep(300) # "Hello world!" text would be displayed for 5 secs
lcd.clear()
sleep(1) # clear the text for 1 sec then print the text again
# format method or string concatenation may also be used
#print("Temperature: {}°C ".format(temp))
#print("Temperature: " + str(temp) + "°C" )
# delay of 2 secs because DHT22 takes a reading once every 2 secs
sleep(2)
if(temp > 20):
buzzerFunc()
else:
None