# Project objectives:
# Read temperature and humidity values from the DHT22 sensor
# Display the sensor readings in the console
#
# Hardware connections used:
# DHT22 VCC Pin to 3.3V
# DHT22 SDA Pin to GPIO Pin 15
# 10k ohm pull-up resistor from DHT22 SDA Pin to 3.3V
# DHT22 GND Pin to GND
#
# Programmer: Adrian Josele G. Quional
# modules
from machine import Pin, PWM, I2C
from time import sleep
from dht import DHT22
import i2c_lcd
# Buzzer function
def buzzerFunc():
buzzer = PWM(Pin(26))
buzzer.freq(500)
buzzer.duty_u16(1000)
sleep(1)
buzzer.duty_u16(0)
# DHT22 aur LCD setup
dht = DHT22(Pin(22))
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
I2C_ADDR = i2c.scan()[0]
lcd = i2c_lcd.I2cLcd(i2c, I2C_ADDR, 2, 16)
# Loop to get sensor readings
while True:
dht.measure()
sleep(1)
temp = dht.temperature()
hum = dht.humidity()
print(f"Temperature: {temp}°C Humidity: {hum}% ")
lcd.putstr(f" Temp: {temp}°C Humty: {hum}% ")
sleep(5)
lcd.clear()
sleep(1)
# Buzzer alert agar temp/humidity limit se zyada hai
if(temp > 20 or hum > 30):
buzzerFunc()
else: