0% found this document useful (0 votes)
31 views29 pages

Project - Smart Parking

The document provides a comprehensive guide for creating a Smart Parking System using Arduino, detailing components, connections, and coding steps. It outlines the project's features, benefits, and learning objectives, emphasizing automation and real-time monitoring of parking slots. The guide includes specific instructions for connecting various sensors and components, as well as the complete Arduino code for implementation.

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)
31 views29 pages

Project - Smart Parking

The document provides a comprehensive guide for creating a Smart Parking System using Arduino, detailing components, connections, and coding steps. It outlines the project's features, benefits, and learning objectives, emphasizing automation and real-time monitoring of parking slots. The guide includes specific instructions for connecting various sensors and components, as well as the complete Arduino code for implementation.

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

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 COMPONENT.................................................................................................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............................................................ 12

STEP 4 : CONNECT THE EXIT IR SENSOR................................................................ 13

STEP 5 : CONNECT THE IR SENSOR FOR PARKING SLOT 1.................................. 14

STEP 6 : CONNECT THE IR SENSOR FOR PARKING SLOT 2.................................. 15

STEP 7 : CONNECT THE IR SENSOR FOR PARKING SLOT 3.................................. 16

STEP 8 : OPEN SOFTWARE AND CONNECT ARDUINO TO LAPTOP......................17

STEP 9 : START CODING............................................................................................. 21

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.

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 COMPONENT
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

What is a Servo Motor?


A servo motor is a type of motor designed for precise control of angular or linear
position, speed, and acceleration. It is widely used in applications requiring controlled
motion, such as robotics, CNC machines, and remote-controlled systems.
Typical Servo Motor Pins and Their Functions

1.​ Signal (Control):


○​ Purpose: Receives pulse width modulation (PWM) signals from the
microcontroller to control the motor's position.
○​ Connected to: The microcontroller or signal source (e.g., Pin 3 on the
Arduino Mega).

2.​ Power (VCC):


○​ Purpose: Provides power to the servo motor.
○​ Connected to: A 5V power source (e.g., the Arduino Mega's 5V pin).

3.​ Ground (GND):


○​ Purpose: Provides a return path for the current.
○​ Connected to: The circuit ground (e.g., GND pin on the Arduino Mega).

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

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

You might also like