from machine import Pin, I2C
from pico_i2c_lcd import I2cLcd
import time
# LCD Setup
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
addr = i2c.scan()[0]
lcd = I2cLcd(i2c, addr, 2, 16)
lcd.putstr("System Ready")
# Room PIR sensors
pir1 = Pin(2, Pin.IN)
pir2 = Pin(3, Pin.IN)
pir3 = Pin(4, Pin.IN)
# Handler functions for motion detection
def motion_room1(pin):
lcd.clear()
lcd.putstr("Motion: Room 1")
print("Motion detected in Room 1")
def motion_room2(pin):
lcd.clear()
lcd.putstr("Motion: Room 2")
print("Motion detected in Room 2")
def motion_room3(pin):
lcd.clear()
lcd.putstr("Motion: Room 3")
print("Motion detected in Room 3")
# Attach IRQs (FALLING or RISING depends on PIR module output)
pir1.irq(trigger=Pin.IRQ_RISING, handler=motion_room1)
pir2.irq(trigger=Pin.IRQ_RISING, handler=motion_room2)
pir3.irq(trigger=Pin.IRQ_RISING, handler=motion_room3)
# Keep running
while True:
time.sleep(1) # Just keeping main loop alive