print('\nThis program is for an Automatic Parking Monitoring System using ESP32, SG90 Servo Motor, HC-05 Ultrasonic Sensor, Buzzer, LED & Favoriot Platform\n')
# Import all necessary libraries
import Ultrasonic # This is Ultrasonic Library (TAK PERLU .PY)
import Servo
from machine import Pin, PWM,
from utime import sleep
# Declare Pin
Trig = Pin(25, Pin.OUT) # Ultrasonic
Echo = Pin(27, Pin.IN) # Ultrasonic
led_red = Pin(2, Pin.OUT)
servo = Pin(14, Pin.OUT)
buzzer = PWM(Pin(26), Pin.OUT)
# Create the object name for the sensor with the library --> LIBRARYNAME.CLASSNAME
# Give a name = Import Library Name.Class Name (trigger_pin, echo_pin,)
sonic = Ultrasonic.HCSR04(trigger_pin=Trig, echo_pin=Echo)
gate = Servo.Servo(pin=servo)
# Main Program
while True:
# ULTRASONIC PART
led_red.on()
sleep(0.2)
print("=== SILA PASTIKAN KENDERAAN ANDA BERADA DIDALAM PETAK ===\n")
sleep(4)
# Parameter (create your own name) = give name.function(define)
distance_in_cm = sonic.distance_cm()
if distance_in_cm <= 3: # Palang bukak (kereta datang)
gate.move(90)
sleep(1)
gate.move(0)
sleep(5)
buzzer.freq(1000) # Adjust frequency
buzzer.duty(1023) # Adjust duration 0-1023
sleep(0.5)
buzzer.freq(1000) # Adjust frequency
buzzer.duty(1023) # Adjust duration 0-1023
sleep(0.5)
buzzer.freq(1000) # Adjust frequency
buzzer.duty(1023) # Adjust duration 0-1023
sleep(0.5)
buzzer.freq(1)
buzzer.duty(10)
sleep(0.5)
gate.move(90)
sleep(1)
else:
gate.move(90)
for i in range(10):
buzzer.freq(1000) # Adjust frequency
buzzer.duty(200) # Adjust duration
sleep(0.1)
buzzer.freq(1)
buzzer.duty(10)
sleep(0.1)
led_red.off()
sleep(0.2)
sleep(2) # In every 2 seconds, ultrasonic will sense new incoming distance. Set counter until 5