#Use the PIR sensor to detect a movemnet
#VCC of PIR to 3.3V Pico
#GND of PIR to GND Pico
#D Pin of PIR to pin 16 Pico
#modules
from machine import Pin, I2C
from time import sleep
from pico_i2c_lcd import I2cLcd
#create the pir object, IN
pir = Pin(16, Pin.IN)
# PIR sensor setup
pir = Pin(16, Pin.IN)
# I2C LCD setup
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
I2C_ADDR = i2c.scan()[0] # auto-detect I2C address
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16) # 2 rows, 16 columns
#continous read from the sensor
#print a message if a movemENt was detected
while True:
if pir.value() == 1:
print("PIR: 1 - Motion Detected!")
lcd.clear()
lcd.putstr("Motion Detected")
else:
print("PIR: 0 - No Motion")
lcd.clear()
lcd.putstr("No Motion")
sleep(1)