loading
Are you excited about Arduino!!!     Well you have come to the right place!!!! My sister and I have made a distance sensor parking garage meter! The purpose for this device is to help you try to park your car in the garage, safely. As a driver you have no idea if the car is too close to the wall or too far from the wall that prevents the garage door from closing. It might close and hurt your car in the process!!! That’s not good. This device prevents you from all that trouble. To get an idea of about what I am talking about look at the picture above……

Step 1: Placing the Device

As you can see in this picture, the car has to be within the right distance from the wall to be parked safely.
So, we have built a parking garage meter to help the driver by making different color LEDs (light emitting diodes) light up.
For example, if the car is close enough to the wall that the car is about to bump into objects in the front, the blue led will glow. If the car is parked too far from the wall and the garage door can’t close, the red led will glow. Any distance between these 2 places is the safe zone and the green led will glow. So now you see why this device is very useful for drivers who park their cars in garages. The finished device looks a little like this picture above.

Step 2: Items Needed for This Project

All these items are available at any electronic store
 For this project we are using:
 Arduino UNO
 Breadboard
 3 LEDs( green, blue, red)
 Pack of wires
 USB cable to connect computer to Arduino
 Ping Sensor HC-SR04

All of these items except for the ping sensor come in the Arduino Uno starter’s kit available in Radio Shack. You can also buy these items individually if you want. You can find this model of the ping sensor at Vetco Electronics.

Step 3: Connecting the Ping Sensor

1. Connect the 5V of the Arduino to the outside +ive rail of the bread board.
2. Connect the GND to the –ive rail of the bread board.
3. Wire the Ping sensor (pins VCC and GND) to the correct locations in the bread board. (Now the Ping sensor is powered)
4. Connect Trig pin of the sensor to the Pin 12 of the Arduino board.
5. Connect the Echo pin of the sensor to the Pin 11 of the Arduino board.
Now the ping sensor is wired completely.

Step 4: Connecting the LEDs

Connect the LEDs as described below

Blue LED +ive to Arduino pin 8
Red  LED +ive to Arduino pin 9
Green LED +ive to Arduino pin 11
Remember to connect the –ive pin to GND.

Step 5: Time for Some Code

Here are some important pieces of the software that we used to program his device.

#include "NewPing.h"
#define justRightLed 11 // green


#define faulty 10 // do not use
#define tooFarLed 9 // red
#define tooCloseLed 8 // blue

#define ECHO_PIN 12
#define TRIGGER_PIN 13

/*
Change these values for your garage
*/
double tooCloseInches = 5;
double tooFarInches = 20;

In setup function, make sure you set the pins to the correct mode
  pinMode(tooCloseLed, OUTPUT);
  pinMode(justRightLed, OUTPUT);
  pinMode(tooFarLed, OUTPUT);
  pinMode(ECHO_PIN,INPUT);
  pinMode(TRIGGER_PIN,OUTPUT);

/*
This code Lights up or shuts off all the LEDs …. Use when testing..
*/
void lightAllLeds()
{
      digitalWrite(tooCloseLed,HIGH);
      digitalWrite(tooFarLed,HIGH);
      digitalWrite(justRightLed,HIGH);
}
void resetAllLeds()
{
      digitalWrite(tooCloseLed,LOW);
      digitalWrite(tooFarLed,LOW);
      digitalWrite(justRightLed,LOW);
}

/*
The main loop
*/
void loop()
{
delay(300);                       
unsigned int uS = sonar.ping(); 
double distanceCM = uS / US_ROUNDTRIP_CM;
double distanceIn = uS / US_ROUNDTRIP_IN;
if (distanceIn > 0.1) displayCorrectStatus(distanceIn);
}

/*
First check if the distance measured is greater that the too close line AND if the distanced is less than the 2 far line, - at this time we know it is in the safe zone
Next, check if the distance is too close, then the blue LED lights up.
Lastly, the Red LED lights, if the distance is too far.
*/
void displayCorrectStatus(int distanceIn)
{
  if ( (distanceIn >=tooCloseInches) && (distanceIn <= tooFarInches ))
  {
   displayJustRightStatus();
  }
  else if ( distanceIn < tooCloseInches)
  {
   displayTooCloseStatus();
  }
  else
  {
      displayTooFarStatus();
  }
}

Step 6: All Done

Now after all this is finished we now have a complete product which will look like this.

   HAVE FUN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! My sister and I are 11 years old and have been working on this project for the last 2 months. If you have feedback we will be glad to hear them.. The most exciting part of this project was when it all came together and we saw it work . Try it yourself ... Now we don't have a problem with parking the car...!!!!!!!!!!!!!!!!!!!!
Nice! This is really cool! :-) This is AR
Dear will u plz upload complete software file of awesome arduino adventure.. <br>I need it plz upload here or send me at hika.jika@yahoo.com <br>
Hi hikajika, sorry for the delay. I don't check this blog often. I am including my file here. I could not upload a file. Hence I have copied the software here....You will have to adjust the values to your experiment. <br> <br>// --------------------------------------------------------------------------- <br>// Example NewPing library sketch that does a ping about 20 times per second. <br>// ------'--------------------------------------------------------------------- <br> <br>#include &quot;NewPing.h&quot; <br> <br> <br>#define justRightLed 11 // green <br>#define faulty 10 // do not use <br>#define tooFarLed 9 // red <br>#define tooCloseLed 8 // blue <br> <br>#define ECHO_PIN 12 <br>#define TRIGGER_PIN 13 <br> <br> <br>double tooCloseInches = 5; <br>double tooFarInches = 20; <br> <br>NewPing sonar (TRIGGER_PIN, ECHO_PIN); <br> <br> <br>void setup() <br>{ <br> Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results. <br> pinMode(tooCloseLed, OUTPUT); <br> pinMode(justRightLed, OUTPUT); <br> pinMode(tooFarLed, OUTPUT); <br> pinMode(ECHO_PIN,INPUT); <br> pinMode(TRIGGER_PIN,OUTPUT); <br> <br> <br> resetAllLeds(); <br> lightAllLeds(); <br> delay(2000); <br> resetAllLeds(); <br> /* <br> resetAllLeds(); <br> delay(2000); <br> lightAllLeds(); <br> delay(1000); <br> resetAllLeds(); <br> delay(1000); <br> lightAllLeds(); <br> delay(1000); <br> resetAllLeds(); <br> */ <br> /* <br> resetAllLeds(); <br> displayTooCloseStatus(); <br> delay(1000); <br> resetAllLeds(); <br> delay(1000); <br> displayJustRightStatus(); <br> delay(1000); <br> resetAllLeds (); <br> delay(1000); <br> displayTooFarStatus(); <br> delay(1000); <br> resetAllLeds(); <br> delay(1000); <br> lightAllLeds(); <br> delay(1000); <br> resetAllLeds(); <br> delay(1000); <br> lightAllLeds(); <br> delay(1000); <br> resetAllLeds(); <br> delay(1000); <br> lightAllLeds(); <br> delay(1000); <br> resetAllLeds(); <br> */ <br>} <br> <br> <br>void lightAllLeds() <br>{ <br> digitalWrite(tooCloseLed,HIGH); <br> digitalWrite(tooFarLed,HIGH); <br> digitalWrite(justRightLed,HIGH); <br>} <br> <br>void loop() <br>{ <br> delay(300); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings. <br> unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS). <br> double distanceCM = uS / US_ROUNDTRIP_CM; <br> double distanceIn = uS / US_ROUNDTRIP_IN; <br> Serial.print(&quot;Ping: &quot;); <br> Serial.print(distanceIn); // Convert ping time to distance in cm and print result (0 = outside set distance range) <br> Serial.println(&quot;inches&quot;); <br> <br> if (distanceIn &gt; 0.1) displayCorrectStatus2(distanceIn); <br> <br>} <br> <br>/* <br>*/ <br>void displayCorrectStatus(int distanceIn) <br>{ <br> if ( (distanceIn &gt;=tooCloseInches) &amp;&amp; (distanceIn &lt;= tooFarInches )) <br> { <br> displayJustRightStatus(); <br> } <br> else if ( distanceIn &lt; tooCloseInches) <br> { <br> displayTooCloseStatus(); <br> } <br> else <br> { <br> displayTooFarStatus(); <br> } <br>} <br> <br>void displayCorrectStatus2(int distanceIn) <br>{ <br> // check if the distance is too close, then turn on the tooClose LED <br> if ( distanceIn &lt;= tooCloseInches) <br> { <br> displayTooCloseStatus(); <br> return; <br> } <br> <br> if ( distanceIn &gt;= tooFarInches) <br> { <br> displayTooFarStatus(); <br> return; <br> } <br> <br> displayJustRightStatus(); <br> return; <br>} <br> <br>/* <br>Make all the LED's off <br>*/ <br>void resetAllLeds() <br>{ <br> digitalWrite(tooCloseLed,LOW); <br> digitalWrite(tooFarLed,LOW); <br> digitalWrite(justRightLed,LOW); <br>} <br> <br>/* <br>Display the too close led <br>*/ <br>void displayTooCloseStatus() <br>{ <br> resetAllLeds(); <br> digitalWrite(tooCloseLed,HIGH); // <br>} <br> <br>void displayJustRightStatus() <br>{ <br> resetAllLeds(); <br> digitalWrite(justRightLed,HIGH); <br>} <br> <br>void displayTooFarStatus() <br>{ <br> resetAllLeds(); <br> digitalWrite(tooFarLed,HIGH); <br>} <br> <br> <br>
nice project ;)

About This Instructable

2,835views

22favorites

License:

More by Tarini Srikanth:Building a robotic arm Awesome Arduino Adventure 
Add instructable to: