Project - Smart Parking
Project - Smart Parking
NAME : ___________________________
CLASS : ____________________________
Content by:
www.aimsity.com Aimsity
Table of Content
ARDUINO BOARD........................................................................................................................3
Arduino Components.................................................................................................................. 7
Project outcome...........................................................................................................................8
Full Code.................................................................................................................................... 21
ARDUINO BOARD
PARTS IN YOUR KIT
PROJECT : SMART PARKING SYSTEM
Introduction
Features:
Benefits:
Learning Objectives
This project teaches the basics of automation and Arduino in a practical, hands-on way.
Arduino Components
Project outcome
Step 1 : Connect the LCD 12C
VCC 5V
GND GND
SDA Pin 20
SCL Pin 21
Step 2 : Connect the servo motor
Signal Pin 3
VCC 5V
GND GND
Step 3 : Connect the entry IR Sensor
VCC 5V
GND GND
Step 4 : Connect the exit IR Sensor
VCC 5V
GND GND
Step 5 : Connect the IR Sensor for parking slot 1
VCC 5V
GND GND
Step 6 : Connect the IR Sensor for parking slot 2
VCC 5V
GND GND
Step 7 : Connect the IR Sensor for parking slot 3
VCC 5V
GND GND
Step 8 : Open software and connect arduino to laptop
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
2. Initializing Hardware
● LCD Initialization: The LCD is set up with the address 0x27, 16 columns, and 2
rows
Servo gateServo;
gateServo.attach(3);
gateServo.write(180);
● Servo Initialization: The servo is connected to pin 3, and its default position is
set to closed (180 degrees).
● IR Sensor Pins: The IR sensors are assigned to pins to detect vehicles at the
entry and exit gates and parking slots.
3. Variables for Parking Management
int total_slots = 3;
int available_slots = 3;
● Total Slots and Available Slots: Keeps track of the total and available parking
slots.
● Slot Status: Tracks whether each parking slot is full (1) or empty (0).
4. Setup Function
void setup() {
Serial.begin(9600); // For debugging
pinMode(ir_entry, INPUT);
pinMode(ir_exit, INPUT);
pinMode(ir_p_1, INPUT);
pinMode(ir_p_2, INPUT);
pinMode(ir_p_3, INPUT);
lcd.init();
lcd.backlight();
lcd.print("Smart Parking");
delay(5000);
lcd.clear();
}
void update_parking_status() {
slot1 = digitalRead(ir_p_1) == LOW ? 1 : 0;
slot2 = digitalRead(ir_p_2) == LOW ? 1 : 0;
slot3 = digitalRead(ir_p_3) == LOW ? 1 : 0;
● Reads the status of each parking slot sensor. If the sensor detects a car (LOW),
the slot is marked as full.
● Updates available_slots based on the status of all slots.
Entry Gate
if (digitalRead(ir_entry) == LOW) {
if (available_slots > 0) {
openGate();
delay(3000);
closeGate();
available_slots--;
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Parking Full");
delay(1500);
lcd.clear();
}
}
● If a car is detected at the entry gate (sensor reads LOW), the system checks if
slots are available.
● If a slot is available, the gate opens for 3 seconds and then closes. The
available_slots count decreases.
Exit Gate
if (digitalRead(ir_exit) == LOW) {
openGate();
delay(3000);
closeGate();
if (available_slots < total_slots) {
available_slots++;
}
}
● If a car is detected at the exit gate (sensor reads LOW), the gate opens for 3
seconds and then closes.
● The available_slots count increases if less than the total slots.
LCD Display
lcd.setCursor(0, 0);
lcd.print("Slots Avail:");
lcd.print(available_slots);
lcd.setCursor(0, 1);
lcd.print("s1:");
lcd.print(slot1 == 1 ? "F" : "E");
lcd.print(" s2:");
lcd.print(slot2 == 1 ? "F" : "E");
lcd.print(" s3:");
lcd.print(slot3 == 1 ? "F" : "E");
D. Display Status on LCD The LCD shows the available slots and the status of each
parking slot (F for Full, E for Empty).
6. Gate control Functions
void openGate() {
gateServo.write(90);
Serial.println("Gate opened");
}
void closeGate() {
gateServo.write(180);
Serial.println("Gate closed");
}
How It Works
1. Setup Phase:
○ Initializes all components (LCD, servo, sensors).
○ Displays "Smart Parking" on the LCD for 5 seconds.
2. Monitoring and Control:
○ Continuously checks the IR sensors for car detection at entry, exit, and
parking slots.
○ Updates parking slot status based on sensor inputs.
○ Opens and closes the gate as needed.
3. User Feedback:
○ Displays parking availability and slot status on the LCD.
○ Displays "Parking Full" if no slots are available.
Debugging
Serial.print("Slot 1: ");
Serial.print(slot1);
Serial.print(", Slot 2: ");
Serial.print(slot2);
Serial.print(", Slot 3: ");
Serial.println(slot3);
● Serial Monitor logs all actions and sensor states for debugging.
Full Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
// IR Sensor pins
int ir_entry = 34; // Entry gate IR sensor
int ir_exit = 36; // Exit gate IR sensor
void setup() {
Serial.begin(9600); // Initialize Serial Monitor for debugging
void loop() {
update_parking_status(); // Check parking slot status
lcd.setCursor(0, 1);
lcd.print("s1:");
lcd.print(slot1 == 1 ? "F" : "E"); // F = Full, E = Empty
lcd.print(" s2:");
lcd.print(slot2 == 1 ? "F" : "E");
lcd.print(" s3:");
lcd.print(slot3 == 1 ? "F" : "E");
void openGate() {
gateServo.write(90); // Open the gate
Serial.println("Gate opened");
}
void closeGate() {
gateServo.write(180); // Close the gate
Serial.println("Gate closed");
}
void update_parking_status() {
// Read parking slot sensors and debug their states
int slot2_state = digitalRead(ir_p_2); // Read Slot 2 sensor
state