print("This is smart parking and gate system")
print("Date: 5/12/2023")
print("By: MSA")
#Import all necessery library
from machine import Pin, ADC, SoftI2C, PWM
from utime import sleep
import Lib_Ultrasonic
import Lib_servo
import SSD1306
#Pin Declaration
LDR_Pin = ADC(Pin(12, Pin.IN))
Light = Pin(2, Pin.OUT)
TRIG = Pin(13, Pin.IN)
ECHO = Pin(14, Pin.OUT)
Led_Green = Pin(5, Pin.OUT)
Led_Red = Pin(19, Pin.OUT)
TRIG1 = Pin(26, Pin.IN)
ECHO1 = Pin(25, Pin.OUT)
Servo1 = Pin(33, Pin.OUT)
i2c_oled = SoftI2C(scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
#Create the object name for sensor with library --> LIBRARYNAME.CLASSNAME
sensor_U1 = Lib_Ultrasonic.HCSR04(trigger_pin=TRIG, echo_pin=ECHO)
sensor_U2 = Lib_Ultrasonic.HCSR04(trigger_pin=TRIG1, echo_pin=ECHO1)
mod_servo = Lib_servo.Servo(pin=Servo1)
screen = SSD1306.SSD1306_I2C(width=oled_width, height=oled_height, i2c=i2c_oled)
#Parameter Declaration
#Main Program
while True:
#Parking Lamp Part
light_intensity = LDR_Pin.read()
voltage = light_intensity / 4096*5.0
print('The voltage detected is: ', voltage, 'V')
if 0 < voltage < 0.83:
Light.off()
print('Light is OFF!')
screen.fill(0) #Text, Column, row, colour code
screen.text("Light is OFF", 15, 5, 1)
screen.show()
sleep(3)
else:
Light.on()
print('Light is ON!')
screen.fill(0) #Text, Column, row, colour code
screen.text("Light is ON", 15, 5, 1)
screen.show()
sleep(3)
#Parking_Lot Part
distance_in_cm = sensor_U1.distance_cm()
print('An incoming object is at : ', distance_in_cm, 'cm' )
if distance_in_cm < 50:
Led_Red.on()
Led_Green.off()
print('Full Parking Lot!')
screen.fill(0) #Text, Column, row, colour code
screen.text("Parking Full!", 0, 25, 1)
screen.show()
sleep(3)
else:
Led_Green.on()
Led_Red.off()
print('Empty Parking Lot!')
screen.fill(0) #Text, Column, row, colour code
screen.text("Parking Emmty!", 0, 25, 1)
screen.show()
sleep(3)
#Parking Gate Part
distance_in_cm = sensor_U2.distance_cm()
if distance_in_cm < 100:
screen.fill(0) #Text, Column, row, colour code
screen.text("Gate Open!", 0, 40, 1)
screen.show()
mod_servo.move(0)
sleep(0.3)
mod_servo.move(90)
sleep(5)
screen.fill(0) #Text, Column, row, colour code
screen.text("Gate Open!", 0, 40, 1)
screen.show()
mod_servo.move(0)
sleep(0.3)
else:
mod_servo.move(0)
screen.fill(0) #Text, Column, row, colour code
screen.text("Gate Close!", 0, 40, 1)
screen.show()
sleep(1)