print("\nThis Program Will Test PIR Sensor")
print("Created By : MUHAMMAD ASYRAAF BIN ASRI")
print("Date: 1/4/2024\n")
#Import libraries/modules
from machine import Pin, PWM, SoftI2C
from utime import sleep
import oled_library
#Pin declaration
PIR_pin = Pin(12,Pin.IN)
Red_led = Pin(18,Pin.OUT)
Green_led = Pin(2,Pin.OUT)
Buzzer_pin = PWM(Pin(4,Pin.OUT))
oled_pin = SoftI2C(scl=Pin(22), sda=Pin(21))
#Parameter declaration
#Create an OBJECT name for module with library
screen = oled_library.SSD1306_I2C(width=128, height=64, i2c=oled_pin)
#main program
while True:
Red_led.off() #initialize
Green_led.on() #initialize
Buzzer_pin.init(freq=1500, duty=0) #initialize
motion_status = PIR_pin.value() #.value (read digital value (1 or 0))
print("The motion status is",motion_status)
if motion_status == True:
Green_led.off()
for a in range (5):
Red_led.on()
Buzzer_pin.init(freq=1500 , duty=500 )
sleep(0.5)
Red_led.off()
Buzzer_pin.init(freq=1500 , duty=0 )
sleep(0.5)
screen.fill(0)
screen.text("NO ENTRY!!!", 20, 30, 1)
screen.show()
else :
Green_led.on()
Red_led.off()
screen.fill(0)
screen.text("RESTRICTED AREA", 5, 0, 1)
screen.text("TRESPASSERS WILL", 0, 20, 1)
screen.text("BE PROSECUTED", 10, 30, 1)
screen.show()
sleep(1) #system delay