Smart Parking Gate Security System Using Arduino
by 1025657 in Circuits > Arduino
98 Views, 4 Favorites, 0 Comments
Smart Parking Gate Security System Using Arduino
For my final Computer Engineering project, I designed and built a Smart Parking Gate Security System using an Arduino Uno. The purpose of this project is to control access to a parking area by requiring drivers to solve a math challenge before entering.
When a vehicle approaches the gate, an ultrasonic distance sensor detects its presence. The Arduino then generates a random math question and displays it on an LCD screen. The user enters their answer using a keypad. If the answer is correct, the gate opens using a servo motor. If the answer is incorrect, an alarm sounds and the RGB LED displays a warning color.
This project combines sensors, displays, motors, LEDs, sound outputs, and programming concepts learned throughout the semester.
Before building the project, I researched Arduino security systems, automatic gates, ultrasonic sensors, LCD displays, and keypad-controlled access systems. I wanted to create a project that used both hardware and software while solving a realistic problem.
Many parking lots use automated gates to control access. My project demonstrates a simplified version of this concept using Arduino components and a math-based security challenge.
Supplies
Arduino Uno 1 - The main controller of the system. It processes all sensor inputs, controls the outputs, and executes the parking gate security program.
LCD I2C Display 1- Used to display instructions, math questions, user input, system status messages, and the number of vehicles that have successfully entered.
Ultrasonic Sensor HC-SR04 1 - Detects when a vehicle approaches the gate. When an object is detected within a specified distance, the security challenge begins.
Servo Motor SG90 1 - Acts as the parking gate arm. The servo rotates to open the gate when the correct answer is entered and returns to its original position after a short delay.
RGB LED 1 - Provides visual feedback to the user. Green indicates a correct answer, red indicates an incorrect answer, and blue indicates keypad activity.
4x4 Keypad 1 - Allows users to enter answers to the math questions displayed on the LCD screen.
Buzzer 1 - Produces audio feedback. A short tone is played when keys are pressed, while an alarm sounds when an incorrect answer is entered.
Resistors 330Ω 1 - Used to limit current flowing through the RGB LED to protect it from damage and ensure proper operation.
Breadboard 1 and many Jumper Wires - Used to connect all electronic components together without permanent soldering, making circuit construction and troubleshooting easier.
Push Button 1 - Used as a manual reset button for the system. If the user wants to restart the Smart Parking Gate Security System, pressing the button resets the Arduino and returns the program to its starting state. This is similar to the reset buttons found on many electronic devices and computers.
Planning the Project
Step 1: Planning the Project
When I started this project, I wanted to create something that used many of the components we learned about during the semester instead of building a simple circuit with only LEDs. I decided to create a Smart Parking Gate Security System because it allowed me to combine sensors, motors, displays, sound outputs, and user input devices into one project.
The main idea is that a vehicle approaches a parking gate and must complete a challenge before being allowed to enter. I chose a math challenge because it was simple to program, interactive for the user, and required the keypad and LCD display to work together.
The project works as follows:
- A vehicle approaches the gate.
- The ultrasonic sensor detects the vehicle.
- The LCD screen displays a random math question.
- The user enters the answer using the keypad.
- If the answer is correct, the RGB LED turns green and the servo motor opens the gate.
- If the answer is incorrect, the RGB LED turns red and the buzzer sounds an alarm.
- The system resets and waits for the next vehicle.
This project allowed me to use many of the hardware and programming concepts learned throughout the course, including sensors, motors, LEDs, functions, arrays, loops, and Arduino libraries.
Connecting the Ultrasonic Sensor
The ultrasonic sensor is responsible for detecting when a vehicle approaches the gate. This sensor works by sending out ultrasonic sound waves and measuring how long it takes for the echo to return after bouncing off an object.
The sensor has four pins:
• VCC
• TRIG
• ECHO
• GND
Connections:
• VCC → Arduino 5V
• GND → Arduino GND
• TRIG → Arduino A0
• ECHO → Arduino A1
The Arduino continuously checks the distance measured by the sensor. When an object is detected within approximately 5 cm of the sensor, the security system activates and displays a math question on the LCD screen.
The distance is calculated using the following formula:
Distance = (Time × Speed of Sound) ÷ 2
The division by 2 is necessary because the sound wave travels to the object and then back to the sensor.
This component serves as the primary input device for the project because it automatically detects the presence of a vehicle without requiring the user to press any buttons.
Connecting the LCD Display
The LCD display is used to communicate with the user throughout the project. It displays messages, math questions, answers entered by the user, and the final result of the challenge.
I used a 16x2 LCD display with an I2C module attached to the back. The I2C module reduces the number of wires needed to connect the display to the Arduino.
The LCD has four connections:
• VCC
• GND
• SDA
• SCL
Connections:
• VCC → Arduino 5V
• GND → Arduino GND
• SDA → Arduino SDA
• SCL → Arduino SCL
On the Arduino Uno, the SDA and SCL pins are located beside the AREF pin. They can also be accessed through the corresponding I2C pins on the board.
The LCD is responsible for displaying:
• "Waiting Car" when the system is idle
• Random math questions
• User input from the keypad
• "Correct!" when the answer is correct
• "Wrong!" when the answer is incorrect
• The total number of vehicles that have successfully entered
I used the LiquidCrystal_I2C library to control the display because it simplifies communication between the Arduino and the LCD screen.
Connecting the Keypad
The keypad is the main input device in the system. It lets the user enter answers to the math questions shown on the LCD. The Arduino reads each button press and builds the full number before checking if the answer is correct.
I used a 4x4 membrane keypad. It has 8 pins in total. These pins are connected to digital pins on the Arduino.
Wiring:
Keypad pins → Arduino pins
• Pin 1 → D9
• Pin 2 → D8
• Pin 3 → D7
• Pin 4 → D6
• Pin 5 → D5
• Pin 6 → D4
• Pin 7 → D3
• Pin 8 → D2
The order matters because the keypad works in a matrix. Rows and columns are scanned by the Arduino to detect which button is pressed.
Code setup:
I used the Keypad library to simplify reading input. It allows the Arduino to detect which key is pressed without manually scanning rows and columns.
- Key parts of the code:
char keys[4][4] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
This defines what each button represents.
- Row and column pins
byte rowPins[4] = {9, 8, 7, 6};
byte colPins[4] = {5, 4, 3, 2};
These match the wiring to the Arduino.
- Keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, 4, 4);
This creates the keypad controller that reads input.
How it works in the system:
- When a key is pressed, Arduino detects it instantly
- Numbers are stored into a variable like a string or integer
- When “#” is pressed, the system submits the answer
- When “*” is pressed, it clears the current input
Programming concept used:
Arrays are used to store:
- keypad layout (2D array)
- row and column pin mapping
This helps organize the system and makes the code easier to expand.
Generating Math Questions and Checking Answers
This part controls the logic of the system. It decides what question to show, reads the user input from the keypad, checks the answer, and updates the LCD display.
The Arduino creates random math questions using basic operators like addition, subtraction, and multiplication.
- Generating random numbers
I used the random() function to create two numbers:
int num1 = random(1, 10);
int num2 = random(1, 10);
These values change every round so the questions are different each time.
- Choosing the operator
I used a variable to select the operation:
char op;
op can be:
• '+'
• '-'
• '*'
The operator can also be selected using random values.
- Calculating the correct answer
The Arduino calculates the correct answer before showing it to the user:
int correctAnswer;
if (op == '+') {
correctAnswer = num1 + num2;
}
else if (op == '-') {
correctAnswer = num1 - num2;
}
else if (op == '*') {
correctAnswer = num1 * num2;
}
This value is stored for later comparison.
- Displaying the question
The LCD shows the question:
lcd.print(num1);
lcd.print(op);
lcd.print(num2);
Example output:
7 + 3
- Reading user input
The keypad input is stored as a string or number:
String input = "";
Each key press is added:
input += key;
When the user presses #, the system submits the answer.
- Checking the answer
The input is converted into an integer:
int userAnswer = input.toInt();
Then compared:
if (userAnswer == correctAnswer) {
lcd.clear();
lcd.print("Correct!");
}
else {
lcd.clear();
lcd.print("Wrong!");
}
- Reset system for next round
After showing the result:
• input is cleared
• a new question is generated
• LCD returns to waiting state briefly
Connecting RGB LED System
The RGB LED gives visual feedback using one component instead of three separate LEDs. It contains red, green, and blue channels inside a single unit. Each channel is controlled separately from the Arduino.
This system shows:
• Green for correct answers
• Red for wrong answers
• Blue for input or system activity
- Wiring the RGB LED
An RGB LED has four pins:
• Red pin
• Green pin
• Blue pin
• Common GND or VCC (depends on type)
If you used a common cathode RGB LED:
• Common pin → GND
Connections:
• Red pin → D11
• Green pin → D10
• Blue pin → D12
• Common → GND
Each color pin connects through a resistor.
1 . Setting up pins in code
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
2 . Turning colors ON and OFF
RGB LEDs work by mixing signals:
Red (wrong answer):
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(12, LOW);
Green (correct answer):
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
Blue (input feedback):
digitalWrite(12, HIGH);
delay(200);
digitalWrite(12, LOW);
3 . Important control rule
Only one color should be active at a time.
Before switching colors, reset all pins:
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
This prevents mixed colors or incorrect lighting.
4 . Fixing the “blue LED always on” issue
This happens when:
• Blue pin is left HIGH outside a condition
• No reset before loop starts
• Multiple conditions overlap
Fix:
void loop() {
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
Then only turn blue ON briefly inside keypad input detection.
5 . How it connects to the system
• Keypad press triggers blue flash
• Correct answer triggers green light
• Wrong answer triggers red light
• LCD still shows full text feedback
Programming concepts used
• digital output control
• state reset before loop
• conditional logic
• hardware control using one output module
Connecting Servo Motor
Purpose in the project
• Correct answer → servo moves (open or activate)
• Wrong answer → servo stays still or resets
This gives a clear physical output.
1 . Wiring
Servo has three wires:
• Red to 5V
• Brown to GND
• Signal → pin 9
2 . Code setup
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(9);
myServo.write(0);
}
3 . Control logic
Correct answer:
myServo.write(90);
delay(1000);
myServo.write(0);
Wrong answer:
myServo.write(0);
4 . How it fits in system
Inside your answer check:
if (userAnswer == correctAnswer) {
myServo.write(90);
}
else {
myServo.write(0);
}
Buzzer System
The buzzer adds sound feedback to the system. It helps the user know if their answer is correct or wrong without looking at the screen.
Purpose in the project
• Correct answer → short beep sound
• Wrong answer → longer beep sound
It improves user feedback speed.
1 . Wiring
The buzzer has two pins:
• Positive → Digital pin (D13)
• Negative → GND
- Code setup
pinMode(13, OUTPUT);
2 . Correct answer sound
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
This creates a short beep.
3 . Wrong answer sound
digitalWrite(13, HIGH);
delay(600);
digitalWrite(13, LOW);
This creates a longer beep.
4 . Integration with system logic
Inside your answer check:
if (userAnswer == correctAnswer) {
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
}
else {
digitalWrite(13, HIGH);
delay(600);
digitalWrite(13, LOW);
}
5 . System behavior
When user answers:
• LCD shows result
• RGB LED changes color
• Servo moves or resets
• Buzzer plays sound
All outputs happen at the same time based on one condition.
Arduino Code – System Logic and Control
The Arduino code controls the full system. It connects all components including the LCD, keypad, RGB LED, servo motor, and buzzer into one working program. The code manages question generation, user input, answer checking, and feedback output.
First, the code defines all required libraries for the LCD, keypad, and servo motor. It also assigns the correct Arduino pins for the RGB LED, buzzer, and servo. This setup ensures each component is properly connected and ready to use.
Next, the system generates random math questions using two numbers and a selected operator. The correct answer is calculated immediately and stored in memory for comparison later. The LCD displays the question so the user can respond using the keypad.
The main loop continuously checks for keypad input. Each pressed key is added to an input string. When the user presses the submit key, the program converts the input into a number and compares it to the correct answer.
If the answer is correct, the system activates multiple outputs at the same time. The LCD displays “Correct”, the RGB LED turns green, the servo motor moves to its active position, and the buzzer plays a short beep.
If the answer is wrong, the LCD displays “Wrong”, the RGB LED turns red, the servo returns to its default position, and the buzzer plays a longer sound.
After each round, the system resets the input, clears the LCD, and generates a new question. The loop then repeats, allowing continuous gameplay.
This code structure uses conditionals, loops, string handling, and hardware control to manage all parts of the system in real time.