#Smart Parking System Using Micropython ESP32...
#Created by Alif Iman
#5/12/2023
#Import
from machine import SoftI2C, Pin, PWM
from utime import sleep, sleep_ms
from time import sleep
import ssd1306_library, #Library
#Pin declare for LED
green_led = Pin(25, Pin.OUT)
red_led = Pin(32, Pin.OUT)
# initialize the PIR sensor on pin 34, LED on pin 12, and servo motor on pin 21
PIR_sensor =Pin(34, Pin.IN)
bar= PWM(Pin(23,Pin.OUT)) #PWM servo toll bar
bar.freq(50)
#declare pin on oled board
i2c_oled = SoftI2C(scl=Pin(2), sda=Pin(4))
#define OLED basic parameter
oled_width = 140
oled_height = 70
#Called oled with take from library
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c_oled)
#Move the servo motor to a specific angle
def move_servo(angle):
# map the angle to the duty cycle for the servo motor
duty_cycle = int((angle / 180) * 50)
servo_motor.duty(duty_cycle)
#Get loop/repeat
while True
# check if motion is detected by the PIR sensor
if PIR_sensor.value() == 1:
print("HAVE CAR!")
red_led.on()
sleep(2)
red_led.off()
sleep(1)
#display the distance value on Oled screen
oled.fill(1)#1 for background white 0 for background black
oled.text('Have car', 0, 0,0) #1st 0 is x-axis, 2nd 0 y axis,
oled.show()
sleep(2)
else PIR_sensor.value() == 0:
print("YEAYYY...YOU ARE READY TO GO!")
green_led.on()
sleep(2)
green_led.off()
sleep(1)
#display the distance value on Oled screen
oled.fill(1)#1 for background white 0 for background black
oled.text('HONDA CITY', 0, 0,0) #1st 0 is x-axis, 2nd 0 y axis,
oled.text('PEARL WHITE', 0, 10,0)
oled.show()
sleep(2)
oled.text('HAVE A NICE DAY!!!', 0, 40, 0)
oled.show()
# move the servo motor to 180 degrees
bar.duty_u16(1638)
sleep(1)
# wait for 10 seconds
sleep(10)
# move the servo motor back to 0 degrees
bar.duty_u16(4860)
sleep(1)
print("NO CAR.")
# wait for a short time to reduce CPU usage
sleep_ms(10)
Loading
ssd1306
ssd1306