Smart Car Parking System Using Ultrasonic Sensor and Arduino

Ultrasonic Car Parking System


Introduction:

In limited places, parking can be challenging, especially when drivers can't tell how far away their car is from nearby obstacles. To solve this, I built a smart parking system using an Arduino UNO and an ultrasonic sensor. When this system detects the distance of an object, like a wall or another car, it alerts the driver with a buzzer and LED indicators.

Despite being a small experiment, it demonstrates how sensor-based technology is utilized for automation and safety in modern cars.

Components Used:

  • Arduino UNO

  • HC-SR04 Ultrasonic Sensor

  • Breadboard

  • Jumper Wires

  • Buzzer

  • LED 

Principle of Operation:

The HC-SR04 ultrasonic sensor emits high-frequency sound waves and measures the time it takes for the echo to return after hitting an object. This is how the Arduino calculates the distance. If the car is far away (beyond a safe distance), there is no alert. As the automobile approaches, the LED illuminates. If the car is too close, the buzzer will sound fast to warn the driver.

Circuit Connection: 

The ultrasonic sensor is connected as follows:

  • VCC → 5V

  • GND → GND

  • Trig → D9

  • Echo → D10


Arduino Code: 

#define trigPin 9
#define echoPin 10
#define buzzer 7

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  long duration, distance;
  
  // Trigger ultrasonic pulse
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Read echo
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;  // Convert to cm

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  // Buzzer alerts based on distance
  if (distance <= 10) {
    digitalWrite(buzzer, HIGH);   // Continuous beep (too close)
  } 
  else if (distance > 10 && distance <= 20) {
    digitalWrite(buzzer, HIGH);   // Short beep
    delay(100);
    digitalWrite(buzzer, LOW);
    delay(100);
  } 
  else if (distance > 20 && distance <= 40) {
    digitalWrite(buzzer, HIGH);   // Slow beep
    delay(300);
    digitalWrite(buzzer, LOW);
    delay(300);
  } 
  else {
    digitalWrite(buzzer, LOW);    // Safe zone
  }
}

Applications in Real Life:

1) Assistance with parking
2) Robotic obstacle detection
3) Systems for industrial safety
4) Smart garage solutions

Conclusion:

This project shows how to use an Arduino and a simple ultrasonic sensor to build a low-cost parking assistance system. Advanced driving-assistance systems (ADAS), which are used in modern cars, are made possible by these systems, which also improve driver safety and prevent collisions.

Setup of project:

Comments