print("This program will test PIR sensor")
print("Create by:Alif")
print('Date: 1/4/2024')
#Import libraries
from utime import sleep
from machine import Pin,SoftI2C
import library_oled
#Pin declaration
PIR_sensor = Pin(12,Pin.IN)
Red_led = Pin(5,Pin.OUT)
Blue_led = Pin(18,Pin.OUT)
Buzzer_Pin = PWM(Pin(2,Pin.OUT))
oled_pin = SoftI2C(scl=Pin(22), sda=Pin(21))
#Parameter declaration
Buzzer_Pin.init(freq=1500, duty=0)
display = library_oled.SSD1306_I2C(width=128, height=64, i2c=oled_pin, external_vcc=False)
#Main program
while True:
Blue_led.off()
Red_led.off()#to initialize
Buzzer_Pin.init(freq=1500, duty=0)
motion_status = PIR_sensor.value() #To read the digital value of the sensor ( 0 or 1 )
print('The value of PIR sensor is',motion_status)#optional
if motion_status ==True:
Red_led.on()
Blue_led.off()
Buzzer_Pin.on()
else:
Red_led.off()
Blue_led.on()
Buzzer_Pin.off()
motion_status = 0
sleep(2)
display.fill(1)
display.text("Hello everyone!",x=0,y=30,col=0)
display.text("Good morning!",x=0,y=40,col=0)
display.text("Welcome to my house",x=0,y=50,col=0)
display.show()