from machine import Pin, I2C
from i2c_lcd import I2cLcd
import utime
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
I2C_ADDR = 0x27
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
pir = Pin(2, Pin.IN)
lcd.clear()
lcd.putstr("Starting...")
utime.sleep(2)
while True:
motion = pir.value()
lcd.clear()
lcd.move_to(0, 0)
if motion == 1:
lcd.putstr("Motion Detected")
lcd.move_to(0, 1)
lcd.putstr("Alert!")
else:
lcd.putstr("No Motion")
lcd.move_to(0, 1)
lcd.putstr("Monitoring...")
utime.sleep(1)