from machine import Pin, I2C
from time import sleep
from pico_i2c_lcd import I2cLcd
# PIR sensor setup on GPIO 16
pir = Pin(16, Pin.IN)
# I2C setup for LCD (SDA = GP4, SCL = GP5)
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
# Scan I2C address and initialize LCD
i2c_address = i2c.scan()[0]
lcd = I2cLcd(i2c, i2c_address, 2, 16)
lcd.clear()
while True:
if pir.value() == 1:
lcd.clear()
lcd.putstr("Motion detected!")
print(f"PIR value: {pir.value()} Status: Motion detected!")
else:
lcd.clear()
lcd.putstr("Waiting for move...")
print(f"PIR value: {pir.value()} Status: Waiting for movement...")
sleep(1)