print("This program will test PIR sensor")
print("created by luqman")
print("Date : 1/4/2024")
#Import libraries
from utime import sleep
from machine import Pin, PWM
from machine import Pin, SoftI2C
import Library_OLED
#Parameter declaration
#Pin declaration
PIR_sensor = Pin(26,Pin.IN)
Red_led = Pin(4,Pin.OUT)
Green_led = Pin(5,Pin.OUT)
Buzzer = PWM(Pin(18,Pin.OUT))
oled_pin = SoftI2C(scl=Pin(22), sda=Pin(21))
#create an object name for sensor with library
#Object name = library_name.class_name(.......)
display = Library_OLED.SSD1306_I2C(width=128, height=64, i2c=oled_pin, external_vcc=False)
#Main program
while True:
Green_led.off()
Red_led.off()
Buzzer.init(freq=500 , duty=0)
motion_status = PIR_sensor.value()
print("The value of PIR sensor is ", motion_status)
if motion_status == True:
for m in range(5):
Red_led.on()
Buzzer.init(freq=1000 ,duty=50)
sleep(0.4)
Red_led.off()
Buzzer.init(freq=500 ,duty=0)
sleep(0.4)
display.fill(1)
display.text('PENCURI', x=5, y=20, col=0)
display.show()
Green_led.off()
else:
Red_led.off()
Green_led.on()
display.fill(1)
display.text('PENCURI LARI', x=5, y=20, col=0)
display.show()
motion_status = 0
sleep(2) #for system delay