import dht
from time import sleep
from machine import Pin, PWM, I2C
from pico_i2c_lcd import I2cLcd

i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)


# Set the GPIO pin where the DHT22 is connected
DHT_PIN = 28  # Use the GPIO number, not the physical pin number


# Initialize the DHT22 sensor
dht_sensor = dht.DHT22(machine.Pin(DHT_PIN))

def buzzerFunc():
  buzzer = PWM(Pin(22))
  buzzer.freq(500)
  buzzer.duty_u16(1000)
  sleep(1)
  buzzer.duty_u16(0)


# 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)

while True:
  dht_sensor.measure()
  temperature = dht_sensor.temperature()
  humidity = dht_sensor.humidity()
        
  print("Temperature: {:.2f}°C, Humidity: {:.2f}%".format(temperature, humidity))

  lcd.putstr("Temp:")
  lcd.putstr(str(temperature))
  lcd.putstr(" C")

  lcd.putstr("\n")
  lcd.putstr("Hum:")
  lcd.putstr(str(humidity))
  lcd.putstr("%")
  sleep(5) 
  lcd.clear()
  sleep(1)        
  

  if(temperature > 20 and humidity > 30):
    buzzerFunc()
  else:
    None
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND
bz1:1
bz1:2
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL