print("This program will test PIR sensor")
print('Created by: MZAMS')
print('Date : 1/4/2024')
#Import libraries
from utime import sleep
from machine import Pin, PWM, Pin, SoftI2C
import library_oled
#Pin declaration
PIR_sensor = Pin(25,Pin.IN)
Red_led = Pin(4,Pin.OUT)
Green_led = Pin(2,Pin.OUT)
Buzzer = PWM(Pin(18,Pin.OUT))
oled_pin = SoftI2C(scl=Pin(22), sda=Pin(21))
#Parameter declaration
##Create an object name for component 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() #to initialize
Red_led.off() #to initialize
Buzzer.init(freq=1 ,duty=0)
motion_status = PIR_sensor.value() #To read the digital value of the sensor
print("The value of PIR sensor is ", motion_status) #optional
if motion_status == True:
for m in range(5):
Red_led.on()
Buzzer.init(freq=500 ,duty=200)
sleep(0.4)
Red_led.off()
Buzzer.init(freq=500 ,duty=0)
sleep(0.4)
display.fill(1)
display.text("ADA", x=2, y=10, col=0)
display.text("PENCURI", x=5, y=30, col=0)
display.show()
Green_led.off()
else:
Red_led.off()
Green_led.on()
display.fill(1)
display.text("TIADA", x=2, y=10, col=0)
display.text("PENCURI", x=5, y=30, col=0)
display.show()
motion_status = 0
sleep(3) #for system delay
#Color code: 0 --> Black, 1 --> White
Loading
esp32-devkit-v1
esp32-devkit-v1