Introduction: Parking Sensor With Arduino Uno
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
Step 1: A Few Things to Understand Before We Start!
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!!
http://www.youtube.com/watch?v=PG2VhpkPqoA
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.
Step 3: 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
Step 5:
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
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
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!!!
Step 9: Almost Done!!!!!
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!!!!!
Attachments
Step 12: Future Improvements
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