#Smart Parking System Using Micropython ESP32
#Created by Alif Iman
#5/12/2023
from machine import Pin, PWM, SoftI2C
from utime import sleep, sleep_ms
import oled
import time
import network
import urequests
#Declare LED & Buzzer Pin
led_green = Pin(12, Pin.OUT)
led_red = Pin(26, Pin.OUT)
buzzer = PWM(Pin(14), Pin.OUT) # Assuming pin 14 for the buzzer
#Pin Declaration for oled
Pin_scl_sda = SoftI2C(scl=Pin(22), sda=Pin(23))
#create an object name using opp (object oriented programming)
# library nama.class name
skrin = oled.SSD1306_I2C(width=128, height=64, i2c=Pin_scl_sda)
# initialize the PIR sensor on pin 27, LED on pin 12, buzzer on pin 14, and servo motor on pin 21
pir_sensor = Pin(27, Pin.IN)
sg90 = PWM(Pin(21, mode=Pin.OUT)) # SERVO MOTOR = TOLL BAR
sg90.freq(50)
# initialize the PIR sensor on pin 27, LED on pin 12, buzzer on pin 14, and servo motor on pin 21
sg901 = PWM(Pin(19, mode=Pin.OUT)) # SERVO MOTOR = TOLL BAR
sg901.freq(50)
# Blynk Auth Token
BLYNK_AUTH = "Your_Blynk_Auth_Token"
# Connect to Blynk server
def connect_to_blynk():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('Your_WiFi_SSID', 'Your_WiFi_Password')
while not wlan.isconnected():
pass
print("Connected to SMART TEC CAR")
sleep(1)
print("Connecting to Blynk...")
sleep(1)
# Make a GET request to Blynk server to establish connection
urequests.get('http://blynk-cloud.com/' + BLYNK_AUTH + '/isHardwareConnected')
print("Connected to Blynk")
# loop forever
while True:
led_red.on() #during the toll bar is closed
led_green.off() #during the toll bar is open
# check if motion is detected by the PIR sensor
if pir_sensor.value() == 1:
skrin.fill(1)
skrin.text("DEAR OWNER",0,10,0)
skrin.text(" OBJECTED DETECTED",0,20,0)
skrin.text("PLS ENSURE SAFTY",0,30,0)
skrin.show() #a must
for i in range (2):
buzzer.init(freq=1500, duty = 400)
sleep(0.5)
buzzer.init(freq=1, duty = 0)
sleep(0.5)
led_red.on()
# Connect to Blynk
connect_to_blynk()
#Move the servo motor to 180 degrees
le