import machine
from machine import Pin, PWM, I2C
import time
from time import sleep
import i2c_lcd
from i2c_lcd import I2cLcd
PIR = Pin(14, Pin.IN)
led = Pin(12, Pin.OUT)
buzzer = PWM(Pin(23))
buzzer.freq(1000)
buzzer.duty(0)
PIRStatus = False
LCDAdd = 0x27
i2c = I2C(scl = Pin(22), sda = Pin(21), freq=10000)
lcd = I2cLcd(i2c, LCDAdd, 2, 16)
lcd.move_to(0, 0)
lcd.putstr('Initializing')
time.sleep(0.5)
lcd.move_to(0,1)
lcd.putstr('Turning On')
time.sleep(2)
lcd.clear()
while True:
print(PIR.value())
if PIR.value() == 1:
led.value(1)
buzzer.duty(512)
lcd.move_to(0,1)
lcd.putstr('Motion Detected!')
time.sleep(2)
lcd.clear()
lcd.move_to(0,0)
lcd.putstr('Warning!')
lcd.move_to(0,1)
lcd.putstr('Warning!')
time.sleep(2)
lcd.clear()
PIRStatus = True
else:
led.value(0)
buzzer.duty(0)
lcd.move_to(0,1)
lcd.putstr('No Motion')
time.sleep(2)
lcd.clear()
lcd.move_to(0,1)
lcd.putstr('All Clear...')
time.sleep(2)
PIRStatus = False