0% found this document useful (0 votes)
37 views25 pages

Project - Smart Parking

The document outlines a project to create a Smart Parking System using Arduino, which automates vehicle entry and exit, tracks available parking spots, and displays updates on an LCD. It includes detailed steps for connecting components, coding, and managing parking slots with IR sensors and a servo motor. The project aims to simplify parking management and enhance learning in automation with Arduino.

Uploaded by

Nurul Afiqah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views25 pages

Project - Smart Parking

The document outlines a project to create a Smart Parking System using Arduino, which automates vehicle entry and exit, tracks available parking spots, and displays updates on an LCD. It includes detailed steps for connecting components, coding, and managing parking slots with IR sensors and a servo motor. The project aims to simplify parking management and enhance learning in automation with Arduino.

Uploaded by

Nurul Afiqah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Arduino

NAME : ___________________________

CLASS : ____________________________

Content by:

www.aimsity.com Aimsity
Table of Content

ARDUINO BOARD........................................................................................................................3

PARTS IN YOUR KIT.................................................................................................................... 4

PROJECT : SMART PARKING SYSTEM.....................................................................................6

Arduino Components.................................................................................................................. 7

Project outcome...........................................................................................................................8

Step 1 : Connect the LCD 12C.................................................................................................... 9

Step 2 : Connect the servo motor............................................................................................ 10

Step 3 : Connect the entry IR Sensor.......................................................................................11

Step 4 : Connect the exit IR Sensor......................................................................................... 12

Step 5 : Connect the IR Sensor for parking slot 1.................................................................. 13

Step 6 : Connect the IR Sensor for parking slot 2.................................................................. 14

Step 7 : Connect the IR Sensor for parking slot 3.................................................................. 15

Step 8 : Open software and connect arduino to laptop......................................................... 16

Step 9 : Start Coding................................................................................................................. 17

Full Code.................................................................................................................................... 21
ARDUINO BOARD
PARTS 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.

A simple and practical way to learn automation with Arduino

Learning Objectives

By completing this project, you will learn:

● How to use IR sensors to detect vehicles.


● How to control a servo motor to automate gate movements.
● How to use an I2C LCD to display real-time information.
● How to automate tasks like gate control and parking slot updates using
sensors.
● How to write Arduino code for real-world applications.
● How to monitor and manage parking spaces efficiently.

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

12C LCD Pin Arduino Mega Pin

VCC 5V

GND GND

SDA Pin 20

SCL Pin 21
Step 2 : Connect the servo motor

Servo Wire Arduino Mega Pin

Signal Pin 3

VCC 5V

GND GND
Step 3 : Connect the entry IR Sensor

IR Sensor Arduino Mega Pin

DAT / OUT Pin 34

VCC 5V

GND GND
Step 4 : Connect the exit IR Sensor

IR Sensor Arduino Mega Pin

DAT / OUT Pin 36

VCC 5V

GND GND
Step 5 : Connect the IR Sensor for parking slot 1

IR Sensor Arduino Mega Pin

DAT / OUT Pin 38

VCC 5V

GND GND
Step 6 : Connect the IR Sensor for parking slot 2

IR Sensor Arduino Mega Pin

DAT / OUT Pin 40

VCC 5V

GND GND
Step 7 : Connect the IR Sensor for parking slot 3

IR Sensor Arduino Mega Pin

DAT / OUT Pin 40

VCC 5V

GND GND
Step 8 : Open software and connect arduino to laptop

1. Open your ‘Arduino IDE’

Step 1: Start the Arduino IDE

● Turn on your laptop and connect your Arduino Mega to


the USB port.
● Locate the Arduino IDE icon on your desktop or in your
applications menu and double-click it to open.

Step 2: Create a New Sketch

● In the Arduino IDE, click on File in the top menu.


● Select New Sketch from the dropdown menu.

Step 3: Select the Board

● Click on Tools in the top menu.


● Navigate to Board, then select Arduino Mega from the list.

Step 4: Select the Port

● Click on Tools in the top menu.


● Navigate to Port, then choose the port labeled as COM ‘#’ (where ‘#’ is
any number that the port assigned to your Arduino).

Step 5: Select the Programmer

● Click on Tools in the top menu.


● Navigate to Programmer, then select AVR ISP from the list.
Step 9 : Start Coding
1. Libraries and Initialization

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>

● Wire.h: Provides communication between Arduino and I2C devices.


● LiquidCrystal_I2C.h: Manages the LCD display connected via I2C protocol.
● Servo.h: Controls the servo motor for the gate.

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).

int ir_entry = 34;


int ir_exit = 36;
int ir_p_1 = 38;
int ir_p_2 = 40;
int ir_p_3 = 42;

● 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.

int slot1 = 0, slot2 = 0, slot3 = 0;

● 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();
}

● Initializes the hardware and displays a welcome message on the LCD.


5. Main Loop

Updating Slot Status

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;

int occupied_slots = slot1 + slot2 + slot3;


available_slots = total_slots - occupied_slots;
}

A. Update Parking Slot Status

● 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();
}
}

B. Entry Gate Logic

● 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++;
}
}

C. Exit Gate Logic

● 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");
}

● openGate(): Opens the gate by moving the servo to 90 degrees.


● closeGate(): Closes the gate by moving the servo to 180 degrees.

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>

// 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
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy