print("\nThis program will test PIR Sensor")
print("Created by : Muhammad Qusyairie")
print("Date: 1/4/2024\n")
# Import Libraries/modules
from machine import Pin
from utime import sleep
from machine import PWM
import oled_library #this is oled library
from machine import Pin, SoftI2C
# Pin Declaration
PIR_pin = Pin(12, Pin.IN)
Red_LED_pin = Pin(5, Pin.OUT)
Green_LED_pin = Pin(19, Pin.OUT)
Buzzer_pin = PWM(Pin(4, Pin.OUT))
oled_pin = SoftI2C(scl=Pin (22), sda=Pin(21))
#create an OBJECT name for module with library
#OBJECT NAME --> library name.class name()
screen = oled_library.SSD1306_I2C(width=128, height=64, i2c=oled_pin)
# Main Program
while True:
Red_LED_pin.off() #Initialize
Green_LED_pin.off() #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)
screen.fill(1)
screen.text("WARNING!!", 5 , 10, 0) # 1= colour white code for word
screen.text("movement detected", 5 , 30, 0) # 1= colour white code for word
screen.show()
if motion_status == True:
for a in range(6):
Red_LED_pin.on()
Buzzer_pin.init(freq=500 , duty=100) #Initialize
sleep(0.5)
Buzzer_pin.init(freq=330 , duty=100) #Initialize
sleep(0.5)
Buzzer_pin.init(freq=500 , duty=100) #Initialize
sleep(0.5)
Buzzer_pin.init(freq=335 , duty=100) #Initialize
sleep(0.5)
Buzzer_pin.init(freq=550 , duty=100) #Initialize
sleep(0.5)
Buzzer_pin.init(freq=330 , duty=100) #Initialize
sleep(0.5)
Buzzer_pin.init(freq=500 , duty=100) #Initialize
sleep(0.5)
Buzzer_pin.init(freq=300 , duty=100) #Initialize
sleep(0.5)
Red_LED_pin.off()
Buzzer_pin.init(freq=1500 , duty=0)
sleep(0.5)
Green_LED_pin.off()
else:
Green_LED_pin.off()
Red_LED_pin.on()
screen.fill(1)
screen.text("safe", 5 , 10, 0)
screen.show()
sleep(1)