1. Activity Name:
Smart Parking System Using Arduino
2. Materials Required:
b) 4 Ultrasonic Sensors (HC-SR04)
c) OLED Display (SSD1306, 128x64)
d) Jumper Wires
e) Breadboard
f) Power Supply (5V)
3. Explanation:
This Smart Parking System detects the availability of parking slots using ultrasonic sensors. Each sensor monitors a parking space and determines whether it is occupied or available based on the distance measured. The results are displayed on an OLED screen, showing the number of available slots in real time.
Working Principle:
Each ultrasonic sensor measures the distance to check if a car is present.
If the measured distance is less than a threshold (e.g., 15 cm), the slot is marked as occupied.
The total number of available slots is calculated and displayed on the OLED screen.
As cars enter or leave, the display updates dynamically.
4. Connections:
Circuit Diagram
(You can use Fritzing to create a diagram.)
Connection Table:
Component |
Arduino Pin |
Other Connections |
Ultrasonic Sensor 1 Trig |
D2 |
- |
Ultrasonic Sensor 1 Echo |
D3 |
- |
Ultrasonic Sensor 2 Trig |
D4 |
- |
Ultrasonic Sensor 2 Echo |
D5 |
- |
Ultrasonic Sensor 3 Trig |
D6 |
- |
Ultrasonic Sensor 3 Echo |
D7 |
- |
Ultrasonic Sensor 4 Trig |
D8 |
- |
Ultrasonic Sensor 4 Echo |
D9 |
- |
OLED Display SDA |
A4 |
- |
OLED Display SCL |
A5 |
- |
OLED Display VCC |
5V |
- |
OLED Display GND |
GND |
- |
5. Arduino Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Ultrasonic Sensor Pins
const int trigPins[4] = {2, 4, 6, 8}; // Trig Pins for 4 sensors
const int echoPins[4] = {3, 5, 7, 9}; // Echo Pins for 4 sensors
void setup() {
Serial.begin(9600);
for (int i = 0; i < 4; i++) {
pinMode(trigPins[i], OUTPUT);
pinMode(echoPins[i], INPUT);
}
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
}
void loop() {
int availableSlots = 4; // Start with all slots available
for (int i = 0; i < 4; i++) {
float distance = getDistance(trigPins[i], echoPins[i]);
Serial.print("Slot ");
Serial.print(i + 1);
Serial.print(" Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (distance < 15) { // If object detected within 15 cm
availableSlots--;
}
}
// Display Available Slots on OLED
display.clearDisplay();
display.setCursor(10, 20);
display.setTextSize(2);
display.print("Slots: ");
display.print(availableSlots);
display.display();
delay(1000);
}
// Function to Measure Distance
float getDistance(int trigPin, int echoPin) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
float distance = (duration * 0.0343) / 2; // Convert to cm
return distance;
}
6. Conclusion:
This Smart Parking System provides a real-time display of available parking slots. It helps in efficient parking management by reducing the time required to find an empty space. The students learned sensor integration, real-time data processing, and display control using Arduino and OLED.