from machine import I2C, Pin, PWM, ADC
from time import sleep
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)


buzzer = Pin(5, Pin.OUT, Pin.PULL_UP)  # set GP15 as digital output pin for buzzer
pir = Pin(19, Pin.IN, Pin.PULL_DOWN)  # set GP16 as digital input pin for PIR motion sensor


while True:
    if pir.value():  # when PIR detects motion
        print("Intruder is detected!")
        buzzer.low()  # make buzzer alarm
        lcd.move_to(5, 0)
        lcd.putstr("!!!Alert!!!")
        lcd.move_to(0, 1)
        lcd.putstr("IN RANGE")
        sleep(2)
        lcd.clear()
    else:
        buzzer.high()  # close buzzer alarm
        print("No Intruder!")
    sleep(1)

BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT