print("This program will detect motion from PIR sensors")
print("Date : 28/11/23")
print("By : MUHAMMAD ARIEF BIN WAIZI")
#Import all necessary libraries
from machine import Pin,SoftI2C,
from utime import sleep
import ssd1306
#Pin declaration
buzzer = Pin (32, Pin.OUT)
pir_sensor = Pin(13,Pin.IN)
led_merah = Pin(2,Pin.OUT)
i2c_oled = SoftI2C(scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
#Create the object name for sensor with library ---> LIBRARYNAME.CLASSNAME
skrin = ssd1306.SSD1306_I2C(width=oled_width,height=oled_height, i2c=i2c_oled)
#Parameter declaration
#Main program
#1 is code for WHITE
while True:
status_of_pir = pir_sensor.value() #The value will
if status_of_pir == True:
skrin.fill(1)
skrin.text("ADA ORANG WOII",2,20,0) #Text, Collum
skrin.show()
for u in range (10):
led_merah.on()
sleep(0.5)
led_merah.off()
sleep(0.3)
buzzer.value(1) #the buzzer sounds
sleep(2)
else:
skrin.fill(1)
skrin.text("OK CLEAR",2,20,0) #Text, Collum
skrin.show()
led_merah.off()
status_of_pir = False
led_merah.off()
sleep(2)
buzzer.value(0) #the buzzer stops ringing
sleep(2)