# Parking Sensor With Arduino Uno

9,765

55

Hello everyone!!!!!My name is orestman and I would like to introduce to you the way I made MY Parking Sensor.
Ok I know that it's not a new concept and this site is full of these things but since it was my first instructable I found that it was a pretty good project to start with as a beginner. The idea came to me as I was looking around to this website to be honest. I made it first on a breadboard and then I decided that I wanted to keep it permanent so here it is.

Part needed :
1. Arduino uno (or any other type of Arduino)
2. A wire cutter (to cut the wires and remove the plastic around them)
3. Soldering Iron
4. A protoboard (if you want to keep it permanent) or a small breadboard
5. An electric screwdriver
6. A buzzer
7. 6LEDs
8. 7 resistors(6 220Ω for the leds and 1 for the buzzer, that depends from how many resistance your buzzer is going to have )
9. A HC-SR04 Ultrasonic distance sensor
10. Jumper wires
11. A 9v battery and a switch
12. A hobby box to put your finished project in
13.A piece of plexiglass
14. A lot of patience

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: A Few Things to Understand Before We Start!

So how the ultrasonic sensor works????

Well this more easy than it sounds like. This tutorial helped me a lot to understand the mechanism so I totally recommend  it to you!!

So basically what this Sensor does is to send an ultrasonic wave from the Trigger pin. This wave travels until it hits an obstacle. Then the Echo pin receives the returning wave and Sends this detail to the arduino. Then the arduino  with a simple mathematical calculation it calculates the distance.So simple!!!

## Step 2: Solder Everything to a Protoboard.

The first thing you have to do is to put everything to the protoboard without solder them so you can see how large the whole thing is going to be.Then you mark with a marker the positions of each component and you start soldering.

## Step 3: Soldering

Not much to say here.Just grab your soldering Iron and start Soldering.

Some tips: always touch the component you are soldering. Take for example a resistor. If you are touching it when you are soldering it and you fill that it is getting hot you must stop soldering it until it gets cold enough ,because otherwise you might destroyed it.

## Step 4: Attach the Base of the Ultrasonic Sensor

So in this step you have to take this thing( I don't know its name) and cut it with a scissor or with a dremel.You want to solder this instead of the sensor itself, mainly for two reasons: First because if you solder the sensor you won’t be able to use it again to another project, and Second because you might destroyed it if you overheat it.

## Step 5:

The next thing you need to do is to combine all the ground lids and then you have to put a cable that will go to the arduinos ground.

Then you have to cut the lids that are not necessary and  solder all the jumper wires to the leads of each resistors ,buzzer, trigger(of the sensor),echo and Vcc(also of the sensor).

## Step 6: Cutting Time

After you ensure that all the previous steps have been done it is time to move to the next step.The CUT step…!

Take the dremel or  any other cutting tool you have and adjust the tool that is shown in the picture below.Then draw a line to use as a driver and start cutting.When you finish you should have something  like the one that is in the photo.

## Step 7: LED Soldering

Time to solder the LEDs and their cables.
Take some flexible wire and solder it to the negative side of the LED,wrapped it with tape to avoid any possible contact with any other component that will create troubles.Do this with all the LEDs and move on to the next step!!

## Step 8: Switch,Gluing,and Drilling!!!

Now that you have finished with all these protoboard  things you have to draw first where the LEDs, the switch and the sensor  are going to be.So first connect all the wires to random pins on the arduino and place it into the box so you will take an idea where you want to put the LEDs, the switch and the sensor!!

## Step 9: Almost Done!!!!!

It is time to make a stand for the arduino!
Take a piece of plexiglass,measure the dimensions your box have , and then it is up to you how big is going to be.Cut it and place it like the picture below.Then if you are totally sure you want to keep it like this glue it!Then cut the place where the switch is going to be and place it inside.Finally solder the positive wire from the battery to one lead and another cable that is going to go to the Vin of the arduino to the midle lead of the switch!

## Step 10: Code

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "pitches.h"

/*The following program checks with a HC-SR04 distance sensor if there is
an object between 2m and 25cm. If there is an object between 2m and 1and a half
meters the two green leds are changing from LOW to HIGH.If there is an object
between 1,50m and 50cm the green and the yellow LDS are going HIGH.If there is
an object between 50cm and 25cm all the leds are going HIGH.And finally if
there is an object closer to 25cm all the leds are flashing.
Circuit:ONE HC-SR04 Sensor
two green leds,two yellow leds,two red leds with a 220Ω resistor attached to
each one of them
a buzzer with a resistor
wires!!!!*/

int gren=2;
int green=3;
int yellow=4;
int yellow1=5;
int red=8;
int red1=9;
int trig=7;//triger pin of the sensor
int echo=6;//echo pin of the sensor
int maximumrange=200;//the maximum range that we want the sensor to measure
int minimumrange=25;//minimum range that we want the sensor to measure
int redRange=50;
int yellowRange=150;
int speaker=10;
int melody[] = {
NOTE_C4,NOTE_C4,NOTE_C4,NOTE_C4,0};
int noteDurations[]={
1,2,4,8,64};

long duration,distance;

void setup(){
Serial.begin(9600);
pinMode(echo,INPUT);
pinMode(trig,OUTPUT);
pinMode(green,OUTPUT);
pinMode(gren,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(yellow1,OUTPUT);
pinMode(red,OUTPUT);
pinMode(red1,OUTPUT);
pinMode(speaker,OUTPUT);

}

void loop(){
//We send signal from the triger pin and taking the signal with the
//echo pin
digitalWrite(trig,LOW);
delayMicroseconds(2);

digitalWrite(trig,HIGH);
delayMicroseconds(10);

digitalWrite(trig,LOW);
duration=pulseIn(echo,HIGH);
//we calculate the distance
distance=duration/58.2;
if(distance <=minimumrange){//minimum=25cm
limit();

}
else if(distance <=redRange && distance >= minimumrange){
redLimit();//red=50 minimum=25
}
/*if the distance is smaller or equal to 1,50 m and greater or equal to 25cm
do the fowlloings*/
else if(distance <= yellowRange && distance >=redRange){
yellowLimit();//yellow=150cm red=50cm
}
else if(distance <= maximumrange && distance >= yellowRange){
greenLimit();
}
else if(distance > maximumrange){
melody[4];
noteDurations[4];

}

}

void limit(){   //limit= 25cm from an object

Serial.println();
Serial.print(" ATTENTION!!! You are: ");
Serial.print(distance);
Serial.print(" cm close to an object");

digitalWrite(green,HIGH);
digitalWrite(gren,HIGH);
digitalWrite(yellow,HIGH);
digitalWrite(yellow1,HIGH);
digitalWrite(red,HIGH);
digitalWrite(red1,HIGH);
delay(20);
digitalWrite(green,LOW);
digitalWrite(gren,LOW);
digitalWrite(yellow,LOW);
digitalWrite(yellow1,LOW);
digitalWrite(red,LOW);
digitalWrite(red1,LOW);

// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[3];
tone(speaker, melody[3],noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(speaker);

}

void redLimit(){
Serial.println();
Serial.print("Be carefull!! You are: ");
Serial.print(distance);
Serial.print(" cm close to an object");

digitalWrite(green,HIGH);
digitalWrite(gren,HIGH);
digitalWrite(yellow,HIGH);
digitalWrite(yellow1,HIGH);
digitalWrite(red,HIGH);
digitalWrite(red1,HIGH);

// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[2];
tone(speaker, melody[2],noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(speaker);
}

void yellowLimit(){
Serial.println();
Serial.print("You are: ");
Serial.print(distance);
Serial.print(" cm close to an object");

digitalWrite(red,LOW);
digitalWrite(red1,LOW);
digitalWrite(green,HIGH);
digitalWrite(gren,HIGH);
digitalWrite(yellow,HIGH);
digitalWrite(yellow1,HIGH);

// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[1];
tone(speaker, melody[1],noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(speaker);
}

void greenLimit(){
Serial.println();
Serial.print("There is an object: ");
Serial.print(distance);
Serial.print(" cm close");

digitalWrite(yellow,LOW);
digitalWrite(yellow1,LOW);
digitalWrite(red,LOW);
digitalWrite(red1,LOW);
digitalWrite(green,HIGH);
digitalWrite(gren,HIGH);

// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[0];
tone(speaker, melody[0],noteDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(speaker);

}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
there is one extra tab that you have to name pitch.h and will include the pitches that you want your buzzer to play.In my code I have ;only NOTE_C4

#define NOTE_C4  262
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
So basically what this code does is to measure the distance and check some conditions.If the distance is smaller than Xcm it exude the green limit,if the distance is smaller than Xcm the yellow e.t.c.

## Step 11: The Final Step!!!!!

Ok that's it you finished with the hardware!!All you have to do is to put everything carefully into the box upload the code close the box and.....you've made it!!|You made a parking alarm!!!!!!

## Step 12: Future Improvements

This step was created in order to give you some improvements for the project. That is why you might notice that new things may be added in the future.

1.Because one sensor may not be suitable if one wants to attach this sensor to his car, a greater number of sensors can be added to this project in order to cover more area in the back of the car where you will be alarmed if you get too close to an obstacle.

2.As one adds more sensors, having them inside the box won't be comfortable.By extending the length of the wire the sensors are attached to however, the "brain" of the device(that's it the enclosure box with the arduino)can easily be inserted somewhere in the car where it suits the driver,and the sensors can be attached to the back of the car

Participated in the
Microcontroller Contest

## Recommendations

• ### Internet of Things Class

22,726 Enrolled