Project - Smart Parking
Project - Smart Parking
NAME : ___________________________
CLASS : ____________________________
Content by:
www.aimsity.com Aimsity
TABLE OF CONTENT
ARDUINO BOARD........................................................................................................... 3
ARDUINO COMPONENT.................................................................................................7
PROJECT OUTCOME..................................................................................................... 8
FULL CODE................................................................................................................... 26
ARDUINO BOARD
COMPONENTS IN YOUR KIT
PROJECT : SMART PARKING SYSTEM
Introduction
This project uses Arduino to create an easy-to-use Smart Parking System. It
automates vehicle entry and exit, tracks available parking spots, and shows updates on
a screen.
Features:
1. Automatic Gates: Opens and closes automatically when a vehicle is detected.
2. Parking Spot Tracking: Counts the available spaces and stops entry when the
lot is full.
3. Real-Time Display: Shows available parking spots and gate status on an LCD.
Benefits:
● Makes parking management easier.
● Saves time and reduces manual effort.
● Ideal for small parking lots at homes or offices.
Learning Objectives
This project teaches the basics of automation and Arduino in a practical, hands-on way.
ARDUINO COMPONENT
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
Real-Life Applications
● Automatic Doors: Used in sliding doors at malls and airports for smooth
movement.
● Robotics: Used for controlling robotic arms and joints with high precision.
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
2. Initializing Hardware
LiquidCrystal_I2C lcd(0x27, 16, 2);
● 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
● 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);
gateServo.attach(3); // Attach servo
gateServo.write(180); // Gate closed position
lcd.init();
lcd.backlight();
lcd.print("Smart Parking");
delay(5000);
lcd.clear();
}
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();
}
}
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.
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 while the program is running for
debugging, which helps in development and troubleshooting.
FULL CODE
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
// Initialize the I2C LCD (adjust the address if necessary, typically
0x27 or 0x3F)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Servo motor for the gate
Servo gateServo;
// IR Sensor pins
int ir_entry = 34; // Entry gate IR sensor
int ir_exit = 36; // Exit gate IR sensor
// Parking slot IR sensor pins
int ir_p_1 = 38; // Parking slot 1 sensor
int ir_p_2 = 40; // Parking slot 2 sensor
int ir_p_3 = 42; // Parking slot 3 sensor
// Variables for parking slots
int total_slots = 3; // Total capacity of the parking lot
int available_slots = 3; // Available slots (initially all are
empty)
int slot1 = 0, slot2 = 0, slot3 = 0; // Status of parking slots: 0 =
Empty, 1 = Full
void setup() {
Serial.begin(9600); // Initialize Serial Monitor for debugging
// Set up IR sensors as inputs
pinMode(ir_entry, INPUT);
pinMode(ir_exit, INPUT);
pinMode(ir_p_1, INPUT);
pinMode(ir_p_2, INPUT);
pinMode(ir_p_3, INPUT);
// Attach the servo motor to its pin
gateServo.attach(3); // Gate servo motor
gateServo.write(180); // Default position: gate closed
// Initialize the I2C LCD
lcd.init();
lcd.backlight();
lcd.print("Smart Parking");
delay(5000); // Display the welcome message for 5 seconds
lcd.clear();
}
void loop() {
update_parking_status(); // Check parking slot status
// Display the parking slot availability and status
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"); // F = Full, E = Empty
lcd.print(" s2:");
lcd.print(slot2 == 1 ? "F" : "E");
lcd.print(" s3:");
lcd.print(slot3 == 1 ? "F" : "E");
// Gate logic for entry
if (digitalRead(ir_entry) == LOW) { // Car detected at entry
Serial.println("Car detected at entry gate");
if (available_slots > 0) { // Check if slots are available
openGate(); // Open the gate
delay(3000); // Wait for the car to pass through
closeGate(); // Close the gate
available_slots--; // Decrease available slots
} else {
// Display "Parking Full" message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Parking Full");
delay(1500);
lcd.clear();
}
}
// Gate logic for exit
if (digitalRead(ir_exit) == LOW) { // Car detected at exit
Serial.println("Car detected at exit gate");
openGate(); // Open the gate
delay(3000); // Wait for the car to pass through
closeGate(); // Close the gate
if (available_slots < total_slots) {
available_slots++; // Increase available slots
}
}
delay(10); // Small delay for stability
}
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
slot1 = digitalRead(ir_p_1) == LOW ? 1 : 0; // Slot 1: 1 = Full,
0 = Empty
slot2 = slot2_state == LOW ? 1 : 0; // Slot 2: 1 = Full, 0
= Empty
slot3 = digitalRead(ir_p_3) == LOW ? 1 : 0; // Slot 3: 1 = Full,
0 = Empty
// Debugging: Log all states
Serial.print("Slot 1: ");
Serial.print(slot1);
Serial.print(", Slot 2: ");
Serial.print(slot2);
Serial.print(", Slot 3: ");
Serial.println(slot3);
// Debug Slot 2 Sensor specifically if issues persist
if (slot2_state == HIGH || slot2_state == LOW) {
Serial.print("Slot 2 Sensor State: ");
Serial.println(slot2_state == LOW ? "Detected" : "Not
Detected");
} else {
Serial.println("Slot 2 Sensor Error: Check connections or
sensor.");
}
// Calculate available slots
int occupied_slots = slot1 + slot2 + slot3;
available_slots = total_slots - occupied_slots; // Calculate
available slots
}