Introduction: How to Make an Arduino Ultra-Sound Car Parking Sensor

About: I'm a university student in England currently studying for a masters degree in electrical and electronic engineering.

So this project is pretty much exactly as specified in the title, a parking sensor. What was my inspiration for this project? That's a good question, as truth be told there was none. I was messing about with the ultra-sound board and seeing if i could use it to change the frequency of a flashing LED when I thought "oo if I replace the LED with a buzzer I could make it into a parking sensor". So I did.


What is a parking sensor? The basic premise is that the closer a reversing car gets to an object, the greater the frequency of beeps from a buzzer. Eventually if the car gets too close to an object, the buzzer will remain on continuously.

Step 1: Construction!

Now this project is very simple, and only requires a handful of cheap components. All of which are pictured above.

  • So first of all, rather unsurprisingly is the Arduino itself. You'll find it relatively difficult to complete and Arduino project without this.
  • Next up on the list we have a HC-SR04 board. This project uses ultrasound to detect distance, and hence this will come in very handy.
  • A breadboard. My girlfriend probably wouldn't agree but for this project the size doesn't really matter.
  • The final real component is an active buzzer.

Along with these ensure that you have a decent number of connector leads, and a lead to connect your Arduino to your computer.

OK, so that's everything we need, now lets get down to building this thing.

First of all I would advice connecting the power supply leads to the breadboard's positive and negative lines (that's the + and - symbols for those of you unfortunate enough to be educated in the States).

Connect the 5V pin to the positive line, and one of the GND pins to the negative line.

Fortunately we have been saved a lot of trouble when it comes to the HC-SR04 as all four of the pins are clearly labelled. You have the Vcc pin, the Trig pin, the Echo pin and finally the GND pin. The Vcc pin should be connected to the positive line on the breadboard, and the GND pin to, you guessed it, the negative line.

For this project, the trig pin is to be connected to pin 5 of the Arduino, whilst the echo pin is to be connected to pin 6.

Now last but by no means least, we have the active buzzer. You will rarely find a component easier to install than this. You will find that you have two pins coming out the bottom, the longer of the two is the positive and the shorter the negative. Place it in the breadboard and connect the negative pin to the ground line, and the positive pin to pin 4 on the Arduino.

Step 2: The Program!

We are done constructing! Hopefully after that strenuous construction you are still with me, as now it is time to move onto the program that we shall use.

// defines pins numbers
#define IN4 4 const int trigPin = 5; const int echoPin = 6; // defines variables long duration; int distance = 0; void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input pinMode(4, OUTPUT); Serial.begin(9600); // Starts the serial communication }
void loop() {
if ((distance <50)&&(distance > 0)) { digitalWrite(IN4, HIGH); // turn the LED on (HIGH is the voltage level) } else if ((distance > 51)&&(distance < 150)) { digitalWrite(IN4, HIGH); // turn the LED on (HIGH is the voltage level) delay(10*(distance-50)); digitalWrite(IN4, LOW); // turn the LED on (HIGH is the voltage level) delay(10*(distance-50));// wait for a set time } else if ((distance > 151)&&(distance < 200)) { digitalWrite(IN4, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); digitalWrite(IN4, LOW); // turn the LED on (HIGH is the voltage level) delay(1000); } else if (distance > 200){ digitalWrite(IN4, LOW); } delayMicroseconds(10); // Clears the trigPin digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculating the distance distance= duration*0.034/2; // Prints the distance on the Serial Monitor Serial.print("Distance: "); Serial.println(distance); //distance is the returned integer, it is the distance in cm }

All the code is right there above in blue, because everyone likes blue right?
I've tried to include as many accurate comments as I can, but if you find that I have missed out anything monumental (or anything at all for that matter) that would help you understand the program, or if you have any questions in general then feel free to ask away.

If you have managed to soldier through my dyslexic ramblings this far then I admire your commitment and hope you have found this how-to helpful. Happy Building!

Step 3: Testing!

If you want to see this project in action, check out the video at the top of this page!

Step 4: Finished!

If you have managed to soldier through my dyslexic ramblings this far then I admire your commitment and hope you have found this how-to helpful. I've tried to steer away from the average and more formal instructions as to make it a bit more bearable to read. I'd love to hear your thoughts on the execution as I currently have 3 more projects in the draft stages. In the future would you advice sticking with this style or stop wasting time and keep things as short and to the point as possible? Once again I hope you've enjoyed and Happy Building!