0% found this document useful (0 votes)
11 views15 pages

Lab 2

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

Lab 2

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

CPEN 130 - Embedded Systems

Laboratory Activity 2

Arduino-Based Smart Parking Sensor with LED and Buzzer Alerts

Submitted by:
Miro G. Angeles
Deen Reiner B. Crusem
Julius Caezar R. Eugenio
BS CPE 4-1

Submitted to:
Prof. Aileen V. Rocillo

October 2024
Laboratory Activity 2
Arduino-Based Smart Parking Sensor with LED and Buzzer Alerts

OBJECTIVES
At the end of the experiment, the students should be able to:
1. Integrate an ultrasonic sensor with an Arduino to measure proximity.
2. Operate LEDs and a buzzer based on sensor data.
3. Develop a program for an automated parking assistance system.
4. Demonstrate the system's functionality by producing visual representation of smart
parking, incorporating sensors and Arduino components.

Introduction

With the goal of lowering human error and increasing parking operations' efficiency,
parking systems have emerged as an essential part of contemporary infrastructure.
Intelligent technologies that give drivers real-time guidance are being developed as a result
of the growing need for smart parking space management solutions brought on by
urbanization. The time spent looking for a parking place is decreased, traffic congestion and
emissions are reduced, and space use is optimized with the aid of these smart parking
systems. In order to give the driver real-time feedback, this concept uses an ultrasonic
sensor to determine the distance between a car and a wall. LEDs offer visual cues for the
car’s proximity, while a buzzer serves as an auditory alert when the vehicle is too close,
ensuring improved safety and convenience during parking (Jemmali et al., 2022).
The importance of smart parking systems in cities is highlighted by Abrar Fahim et al.
(2021), who point out that sensor-based technology is now essential for automating parking
procedures and enhancing user experience in general. Similarly, a 2019 study by Idris et al.
examines the development of smart parking systems, emphasizing how sensors and real-
time data processing might improve parking effectiveness. The system created for this
project is based on these technological developments, which enable precise and ongoing
monitoring of parking areas. The technology facilitates safer, more effective parking by
providing drivers with real-time visual and audio feedback. This is in line with the larger
objective of lowering human error and enhancing parking operations.

The system is controlled by an Arduino, a versatile microcontroller that acts as the


brain of the setup, managing both inputs and outputs. The primary input is provided by the
ultrasonic sensor (HC-SR04), which measures the distance between the vehicle and an
object, such as a wall, by emitting ultrasonic waves and calculating the time it takes for them
to bounce back. Based on these distance readings, the system uses three LEDs—green,
yellow, and red—to indicate the car’s proximity. The green LED lights up when the car is far
from the wall, the yellow LED turns on when the car is approaching closer, and the red LED
is activated when the vehicle is very close to the wall. Additionally, a buzzer serves as an
audible alert, sounding off when the car gets too close, enhancing the warning system
alongside the red LED.

Feedback control systems are used by the smart parking system to improve
responsiveness and performance. In this configuration, the system generates feedback in
the form of visual (LED) and audio (buzzer) messages, while the sensor supplies input data
(distance measurements). This setup is an example of a closed-loop control system, in
which inputs are received in real time and the system continuously modifies its outputs.
According to Haidekker (2020), feedback control systems are essential for automated
applications because they enable accurate performance improvements and changes. By
ensuring that the driver is aware of their closeness to impediments, this feedback
mechanism allows them to take appropriate remedial action. Additionally, the smart parking
system employs optical threshold logic to determine the appropriate response based on
distance measurements. This logic involves comparing sensor readings against predefined
distance thresholds to activate specific outputs. For instance, different distance ranges
correspond to distinct LED colors and buzzer signals, guiding the driver as they park. Optical
threshold logic is essential for making quick decisions based on sensor data, ensuring
efficient operation of the system. As Sarkar et al. (2021) discuss, such logic is vital for real-
time applications where immediate feedback is required to maintain safety and operational
efficiency.

Materials and Components


 Arduino UNO Board
 Ultrasonic Sensor (HC-SR04)
 LEDs (1 Red, 1 Yellow, 1 Green)
 Buzzer (3V/5V)
 Breadboard
 Jumper Wires
 Resistors (220Ω; led ,10Ω; buzzer)
CIRCUIT DIAGRAM

Fig 1. Wiring Diagram of the Smart Parking

Fig 2. Schematic Diagram of the Smart Parking

The circuit setup involves connecting an ultrasonic sensor to the Arduino to measure
distances, along with three LEDs (green, yellow, and red) and a buzzer to provide visual and
audio alerts based on proximity.
Procedure

Step 1. Connection of Components


1.1. Setting up the Breadboard
a. Connect the 5V pin of the Arduino to the positive (red) rail of the breadboard
using a jumper wire.
b. Connect the GND pin of the Arduino to the negative (blue) rail of the breadboard
using a jumper wire.
c. Connect the 2 power and ground of your top and bottom part of the breadboard

1.2. Connect the Ultrasonic Sensor


a. Place the ultrasonic sensor (HC-SR04) on the breadboard.
b. Connect the VCC pin of the sensor to the positive rail (5V) on the breadboard.
c. Connect the GND pin of the sensor to the negative rail (GND) on the breadboard.
d. Connect the TRIG pin of the sensor to digital pin 7 on the Arduino using a jumper
wire.
e. Connect the ECHO pin of the sensor to digital pin 6 on the Arduino using a
jumper wire.

1.3: Connect the LEDs


a. Place the green LED on the breadboard.
o Connect the positive (long) leg to digital pin 12 on the Arduino.
o Connect the negative (short) leg to a 220Ω resistor, and connect the
resistor to the negative rail (GND).
b. Place the yellow LED on the breadboard.
o Connect the positive leg to digital pin 10 on the Arduino.
o Connect the negative leg to a 220Ω resistor, and connect the resistor to
the negative rail (GND).
c. Place the red LED on the breadboard.
o Connect the positive leg to digital pin 8 on the Arduino.
o Connect the negative leg to a 220Ω resistor, and connect the resistor to
the negative rail (GND).

1.4: Connect the Buzzer


a. Place the buzzer on the breadboard.
b. Connect the positive pin of the buzzer to digital pin 3 on the Arduino.
c. Connect the negative pin of the buzzer to 10Ω and connect it to the negative rail
(GND) on the breadboard.

The table below provides a summary of the pin assignments for the various components
connected to the Arduino Uno board:
d.

Step 2. Code Development or Algorithm Design


a. Start writing the Arduino code to design the control of ultrasonic sensor and LEDs
based on distance feedback. It begins by defining the pins connected to the
Arduino UNO for the ultrasonic sensor, LEDs, and buzzer, facilitating clear and
efficient management of the components. Then, assign functions to each
component to enable effective communication, particularly between the sensors
and output devices. This setup allows the system to accurately measure distances
and respond appropriately by activating the corresponding LEDs and buzzer based
on the proximity of detected objects.

b. The algorithm is designed to:


 Measure the distance using the ultrasonic sensor.
 Light up specific LEDs (Green, Yellow, Red) based on the proximity of an
object.
 Sound the buzzer with varying tones and durations depending on the distance,
indicating safety (green), caution (yellow), and danger (red) zones.

Step 3. Explanation of Logic Used


a. Loop: The loop function continuously executes the ultrasonic sensor to measure
and calculate the distance of an object detected repeatedly.
b. Conditional Logic: The program uses a series of conditional statements (if-else)
to determine the appropriate actions based on the measured distance:
 Safe Distance (7-12 cm): When the measured distance is between 6 cm and
12 cm, the green LED lights up, indicating a safe condition. The buzzer emits a
sequence of short sounds to further signal safety, effectively alerting the user
that they are at a safe distance from an object.
 Caution Distance (4-6 cm): If the distance falls within the range of 3 cm to 6
cm, the yellow LED activates, signaling caution. The buzzer produces a single
sound of longer duration, indicating a potential hazard and prompting the user
to be more careful.
 Danger Distance (0-3 cm): For distances less than or equal to 3 cm, the red
LED turns on, indicating an immediate danger. The buzzer continuously
sounds, providing an urgent alert that the user is too close to an object and
should take immediate action.
 Out of Range - In the else condition, the code will display "out of range" in the
serial monitor and turn off both the LEDs and the buzzer.

Step 4. Uploading the Code and Testing the System


After carefully examining the Arduino code, upload it to the Arduino board and
perform several tests to verify that the system functions as expected. Adjust the
values of other component parameters as needed.

Code

#define trigPin 7 pinMode(trigPin, OUTPUT);


#define echoPin 6 pinMode(echoPin, INPUT);
#define led1 12 // Green LED (Safe pinMode(led1, OUTPUT);
distance) on pin 12 pinMode(led2, OUTPUT);
#define led2 10 // Yellow LED (Caution pinMode(led3, OUTPUT);
distance) on pin 10 pinMode(buzzer, OUTPUT);
#define led3 8 // Red LED (Danger }
distance) on pin 8 void loop() {
#define buzzer 3 // Buzzer for sound long duration, distance;
alerts
// Send ultrasonic pulse
void setup() { digitalWrite(trigPin, LOW);
Serial.begin(9600); delayMicroseconds(2);
digitalWrite(trigPin, HIGH); delay(250); // Longer sound
delayMicroseconds(10); for "teet"
digitalWrite(trigPin, LOW); noTone(buzzer);
delay(500); // Pause between
// Measure pulse duration and calculate beats
distance in cm
duration = pulseIn(echoPin, HIGH); // Print distance for yellow range
distance = (duration / 2) / 29.1; Serial.print(distance);
Serial.println(" cm");
// Logic for distance and LED control
if (distance > 6 && distance <= 12) { } else if (distance <= 3 && distance >
// Safe distance: Green LED 0) {
digitalWrite(led1, HIGH); // Danger distance: Red LED,
digitalWrite(led2, LOW); continuous "toot"
digitalWrite(led3, LOW); digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
// Green LED buzzer: FAST beats digitalWrite(led3, HIGH);
tone(buzzer, 1500); // Frequency for
green // Red LED buzzer: Continuous sound
delay(100); // Sound duration "toot"
noTone(buzzer); tone(buzzer, 1500); // Frequency for
delay(200); // Pause between red, continuously sounding
beats
// Print distance for red range
// Print distance for green range Serial.print(distance);
Serial.print(distance); Serial.println(" cm");
Serial.println(" cm");
} else {
} else if (distance > 3 && distance <= // Out of range: Turn off all LEDs
6) { and buzzer
// Caution distance: Yellow LED, 1 digitalWrite(led1, LOW);
beat per second (teet teet) digitalWrite(led2, LOW);
digitalWrite(led1, LOW); digitalWrite(led3, LOW);
digitalWrite(led2, HIGH); noTone(buzzer);
digitalWrite(led3, LOW); Serial.println("Out of range");
}
// Yellow LED buzzer: (1 beat per
second) delay(100); // Short delay for loop to
tone(buzzer, 1500); // Frequency for repeat
yellow }
Results

The outcomes of the Arduino-Based Smart Parking Sensor with LED and Buzzer
Alerts successfully aligned with our desired project's objective. The ultrasonic sensor
accurately measured distances within the specified ranges. When the distance exceeded 12
cm, the serial monitor displayed "out of reach." For distances ranging from 6 cm to 12 cm,
the green LED illuminated, accompanied by a sequence of rapid beats from the buzzer,
indicating a safe condition. In the range of 4 cm to 6 cm, the yellow LED activated, with the
buzzer producing a single beat per second to signal caution. When the measured distance
was 3 cm or less, the red LED turned on, and the buzzer emitted a continuous long sound,
signifying a dangerous condition. Although occasional misreadings were observed, likely due
to the ultrasonic sensor's previous use in multiple projects, the feedback mechanism
effectively communicated safe, caution, and danger zones, aligning well with the system's
intended design.

Fig 3. Output after testing


Fig 4. The Smart Parking System Model

Fig 5. Smart Parking from 9 cm away (Green light)

Fig 6. Smart Parking from 6 cm away (Yellow light)

Fig 7. Smart Parking from 3 cm away (Red light)


Discussions

The results from testing the Arduino-Based Smart Parking System demonstrated that
the ultrasonic sensor was able to measure proximity accurately, and the system effectively
signaled different distance thresholds using LEDs and buzzer alerts. The division of distance
ranges into safe (6-12 cm), caution (4-6 cm), and danger (0-3 cm) provided a clear and
functional response mechanism for each scenario. However, during the testing phase, a few
challenges and areas for improvement were identified.

One challenge encountered was occasional misreading of distance values. These


inconsistencies could be attributed to the ultrasonic sensor's previous extensive use in
various projects, leading to potential wear on the component. Additionally, aligning the
ultrasonic sensor at the correct angle for the parking lot proved to be difficult. This
misalignment affected the sensor's ability to achieve optimal accuracy, making it more
challenging to consistently detect distances as expected. Ensuring proper sensor alignment
is critical to maximize the accuracy and performance of the system, particularly in the
confined space of a parking lot where small variations in angle can impact readings
significantly.

Proposed Improvements:

1. Incorporating a Button to Silence the Red Alarm: One practical improvement would
be the addition of a manual override button to silence the red alarm (buzzer) when a
danger zone is detected. This would prevent continuous noise in cases where the
user is already aware of the issue, providing a more user-friendly experience without
compromising safety.

2. Motion Detection Integration: Another enhancement would be the use of a motion


detector that can automatically stop the red alarm when the detected object (e.g., a
vehicle) halts. This approach would eliminate the need for manual intervention,
ensuring that the system is responsive to real-time movement and further enhancing
usability.

Conclusion
In conclusion, the project objectives were achieved successfully. The integration of
an ultrasonic sensor with the Arduino was accomplished, allowing the system to measure
proximity with precision. The sensor effectively captured real-time distance data, which was
used to control both LEDs and a buzzer, offering clear visual and auditory feedback at
specific distance thresholds. This functionality allowed the system to indicate safe, caution,
and danger zones, fulfilling the primary requirement of the smart parking assistance system.

Moreover, a custom program was developed to automate the process, ensuring that
the appropriate LED indicators and buzzer alerts were triggered according to the proximity
data. This automation not only improved the system's reliability but also minimized the need
for manual intervention, streamlining the parking assistance process.

Lastly, the overall functionality of the system was successfully demonstrated through
a visual representation of a working smart parking system. The combination of sensors,
Arduino components, and programming illustrated how these technologies can be integrated
into a practical, real-world application. The project serves as a strong example of how
automation and sensor technology can work together to enhance parking systems, providing
an efficient and reliable solution for monitoring vehicle proximity in confined spaces.
References

Idris, M. I., Leng, Y. Y., Tamil, E. M., Noor, N. M., & Razak, Z. (2019). Car park system: A
review of smart parking system and its technology. Information technology journal,
8(2), 101-113.

Abrar Fahim, Mehedi Hasan, Muhtasim Alam Chowdhury, Smart parking systems:
comprehensive review based on various aspects, Heliyon, Volume 7, Issue 5, 2021,
E07050, ISSN 2405-8440, https://doi.org/10.1016/j.heliyon.2021.e07050.

Jemmali, M., Melhim, L.K.B., Alharbi, M.T. et al. Smart-parking management algorithms in
smart city. Sci Rep 12, 6533 (2022). https://doi.org/10.1038/s41598-022-10076-4

Mark A. Haidekker, 1 - Introduction to linear feedback controls, Editor(s): Mark A. Haidekker,


Linear Feedback Controls (Second Edition), Elsevier, 2020, Pages 1-13, ISBN
9780128187784, https://doi.org/10.1016/B978-0-12-818778-4.00009-1.

Sarkar3, M., Chakraborty1, R., Taki1, G. S., Chakraborty2, A. K., & https://orcid.org/0000-
0002-7717-9294, M. S. (2021, July 26). Design of basic logic gates using optical
threshold logic. Engineering Research Express.
https://iopscience.iop.org/article/10.1088/2631-8695/ac1903

Ramos, S. (n.d.). Exploring piezo buzzer integration with Arduino: A comprehensive guide .
Arduino Intro. https://arduinointro.com/articles/projects/exploring-piezo-buzzer-
integration-with-arduino-a-comprehensive-guide

Latha, N. A., Murthy, B. R., & Kumar, K. B. (2016). Distance sensing with ultrasonic sensor
and Arduino. International Journal of Advance Research, Ideas and Innovations in
Technology, 2(5), 1-5.
Appendices

Fig 5. Members wiring the components.

Fig 6. Members working on coding and testing the smart parking system.
Table 2. HC-SR04 Ultrasonic Sensor Datasheet
Parameters Details/Value
Model HC-SR04
Type Ultrasonic Ranging Module
Application Distance measurement, object detection
Operating Voltage 3.3Vdc ~ 5Vdc
Quiescent Current <2mA
Operating Current 15mA
Operating Frequency 40KHz
Operating Range & Accuracy 2cm ~ 400cm (1in ~ 13ft) ±3mm
Sensitivity -65dB min
Sound Pressure 112dB
Effective Angle 15°
Connector 4-pins header with 2.54mm pitch
Dimensions 45mm x 20mm x 15mm
Weight 9g
Operating Temperature -15°C to 70°C
Storage Temperature -20°C to 80°C

You might also like