print("\nThis program will test PIR Sensor")
print("Created by: Danial Hafiz bin Abdullah")
print("Date: 1/4/2024\n")
#Import libraries/module
from machine import Pin,PWM
from utime import sleep
import oled_library #This is oled_library
from machine import Pin, SoftI2C
#Pin declaration
oled_pin = SoftI2C(scl=Pin(22), sda=Pin (21))
#Parameter declaration
PIR_pin = Pin(12, Pin.IN)
REd_LED_pin = Pin(5, Pin.OUT)
Green_LED_pin = Pin(18, Pin.OUT)
Buzzer_pin = PWM(Pin(4, Pin.OUT))
#Create an OBJECT name for module with library
# OBJECT name = library name.class name ()
skrin = oled_library.SSD1306_I2C(width=128, height=64, i2c=oled_pin)
#Main declaration
while True:
REd_LED_pin.off() #initalize
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)
if motion_status == True:
for a in range (10):
REd_LED_pin.on()
Buzzer_pin.init(freq=1500 , duty=100 )
sleep(0.5)
REd_LED_pin.off()
Buzzer_pin.init(freq=1500 , duty=0 )
sleep(0.5)
#By default color code is white (1)
skrin.fill(0)
skrin.text ("Hello everyone!", 4, 10, 1)
skrin.text ("Nice to know you!", 4, 20, 1)
skrin.show()
Green_LED_pin.off()
else:
Green_LED_pin.on()
REd_LED_pin.off()
sleep(0.5) #system delay
Loading
esp32-devkit-v1
esp32-devkit-v1