Hi guys this is my first tutorial, I've just started a few months ago learning electronics (previously I've just knew how to program in C and Python). When I finished this project (took me about 5 hours or something) I've decided to share to help anyone that is starting in electronics.

What’s this project about?
Basically we have an Ultrasonic sensor that measures the distance and the LED’s bar graph will light up according to our distance from the sensor and as we get closer the buzzer beeps in a different way. This circuit can work as a parking sensor! It's easy and cheap.

Check my website for more electronic projects and information.
Check this video to watch the circuit working

Parts Required:
1x Arduino
1x 74HC595 8 Bit Shift Register
1x Breadboard
8x LED’s (for example: 3x red, 3x yellow, 2x green)
9x 220 Ohm Resisters
1x Buzzer
1x Ultrasonic Sensor (for exemple: HC-SR04)
Jumper Wires

Step 1: Let's start

First you should place all the components on the breadboard, check the picture.
<p>Hi do you know about signal in dangrees </p><p>road bend,project?</p>
<p>all leds are lighting up frm the beginning itself irrespective of the distance ...plz help me </p>
<p>everthing is well...but why my buzzer keep emitting the same sound? anyone can help?:( quite rush of time.... what type of buzzer u all using?</p>
<p>hello friend !!</p><p>Do you have any idea how to connect water Proofed Ultrasonic sensor with arduino and coding ,,,i have try but i just failed ..if you have any idea please share with me </p><p>thank you</p><p>Link:</p><p>http://www.google.lk/imgres?imgurl=http://g01.a.alicdn.com/kf/HTB1a12XJpXXXXX9aXXXq6xXFXXXE/-font-b-Ultrasonic-b-font-font-b-Module-b-font-Distance-Measuring-Transducer-font-b.jpg&amp;imgrefurl=http://www.aliexpress.com/w/wholesale-waterproof-ultrasonic-sensor-module.html&amp;h=800&amp;w=800&amp;tbnid=it82jjrdO0G8zM:&amp;docid=AoqmQkcV5JgGRM&amp;ei=YSEFVuPvKoKIuATQsq2QBQ&amp;tbm=isch&amp;ved=0CHsQMyhWMFZqFQoTCKOk9MT8kcgCFQIEjgodUFkLUg</p>
<p>i have done this project ,but in schematic some wire in leds and HC-SR04 wrong but out of all this is coll project ,thanks </p>
<p>How can I add a mute button?</p>
<blockquote><blockquote>a<br><br>Hi guys, I would like to ask on how to stabilize my ultrasonic sensor mounted in a servo motor. It is because everytime an &quot;Out of Range&quot; displays in the serial monitor it gives current to the servo motor causing it to sweep. The possibility of sweeping the servo left or right only is when there is an object being detected. BTW, the ultrasonic sensor is mounted above the servo mtor. </blockquote><blockquote>Here is my code://</blockquote><blockquote>#define trigPin 13</blockquote><blockquote>#define echoPin 12</blockquote><blockquote>#define led 11</blockquote><blockquote>#define led2 10</blockquote><blockquote>#include &lt;Servo.h&gt;</blockquote><blockquote>int pos = 0; // variable to store the servo position </blockquote><blockquote>int defPOS = 0; </blockquote><blockquote>Servo myservo;</blockquote><blockquote>void setup() {</blockquote><blockquote>Serial.begin (9600);</blockquote><blockquote>pinMode(trigPin, OUTPUT);</blockquote><blockquote>pinMode(echoPin, INPUT);</blockquote><blockquote>pinMode(led, OUTPUT);</blockquote><blockquote>pinMode(led2, OUTPUT);</blockquote><blockquote>myservo.attach(9);</blockquote><blockquote>myservo.write(0);</blockquote><blockquote>}</blockquote><blockquote>void loop() {</blockquote><blockquote>long duration, distance;</blockquote><blockquote>digitalWrite(trigPin, LOW); // Added this line</blockquote><blockquote>delayMicroseconds(2); // Added this line</blockquote><blockquote>digitalWrite(trigPin, HIGH);</blockquote><blockquote>// delayMicroseconds(1000); - Removed this line</blockquote><blockquote>delayMicroseconds(10); // Added this line</blockquote><blockquote>digitalWrite(trigPin, LOW);</blockquote><blockquote>duration = pulseIn(echoPin, HIGH);</blockquote><blockquote>distance = (duration/2) / 29.1;</blockquote><blockquote>//0 Left</blockquote><blockquote>//1 Center</blockquote><blockquote>//2 Right</blockquote><blockquote>int buttonState1 = digitalRead(led); //red</blockquote><blockquote>int buttonState2 = digitalRead(led2); //green</blockquote><blockquote>if( (buttonState1 == 0 &amp;&amp; buttonState2 == 1) &amp;&amp; (defPOS != 1))</blockquote><blockquote>{</blockquote><blockquote>delay(2000);</blockquote><blockquote>if(defPOS == 2)</blockquote><blockquote>{</blockquote><blockquote>for(pos = 0; pos &lt;= 90; pos += 1) // goes from 0 degrees to 180 degrees </blockquote><blockquote>{ // in steps of 1 degree </blockquote><blockquote>myservo.write(pos); // tell servo to go to position in variable 'pos' </blockquote><blockquote>delay(2); // waits 15ms for the servo to reach the position </blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>else if(defPOS == 0)</blockquote><blockquote>{</blockquote><blockquote>for(pos = 0; pos &lt;= 90; pos += 1) // goes from 0 degrees to 180 degrees </blockquote><blockquote>{ // in steps of 1 degree </blockquote><blockquote>myservo.write(pos); // tell servo to go to position in variable 'pos' </blockquote><blockquote>delay(2); // waits 15ms for the servo to reach the position </blockquote><blockquote>}</blockquote><blockquote>}</blockquote><blockquote>defPOS = 1;</blockquote><blockquote>}</blockquote><blockquote>if (distance &lt; 30) { // This is where the LED On/Off happens</blockquote><blockquote>digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off</blockquote><blockquote>digitalWrite(led2,LOW);</blockquote><blockquote>if(defPOS == 0)</blockquote><blockquote>{</blockquote><blockquote>for(pos = 90; pos&gt;=0; pos-=1) // goes from 180 degrees to 0 degrees </blockquote><blockquote>{ </blockquote><blockquote>myservo.write(pos); // tell servo to go to position in variable 'pos' </blockquote><blockquote>delay(2); // waits 15ms for the servo to reach the position </blockquote><blockquote>}</blockquote><blockquote>defPOS = 2;</blockquote><blockquote>}</blockquote><blockquote>else if(defPOS == 2)</blockquote><blockquote>{</blockquote><blockquote>for(pos = 0; pos &lt;= 90; pos += 1) // goes from 0 degrees to 180 degrees </blockquote><blockquote>{ // in steps of 1 degree </blockquote><blockquote>myservo.write(pos); // tell servo to go to position in variable 'pos' </blockquote><blockquote>delay(2); // waits 15ms for the servo to reach the position </blockquote><blockquote>}</blockquote><blockquote>defPOS = 1; </blockquote><blockquote>}</blockquote><blockquote>else if(defPOS == 1)</blockquote><blockquote>{</blockquote><blockquote>for(pos = 0; pos &lt;= 180; pos += 1) // goes from 0 degrees to 180 degrees </blockquote><blockquote>{ // in steps of 1 degree </blockquote><blockquote>myservo.write(pos); // tell servo to go to position in variable 'pos' </blockquote><blockquote>delay(2); // waits 15ms for the servo to reach the position </blockquote><blockquote>}</blockquote><blockquote>defPOS = 0; </blockquote><blockquote>}</blockquote><blockquote>//myservo.write(180);</blockquote><blockquote>// delay(1000);</blockquote><blockquote>//myservo.write(0);</blockquote><blockquote>}</blockquote><blockquote>else {</blockquote><blockquote>digitalWrite(led,LOW);</blockquote><blockquote>digitalWrite(led2,HIGH);</blockquote><blockquote>}</blockquote><blockquote>if (distance &gt;= 400 || distance &lt;= 0){</blockquote><blockquote>Serial.println(&quot;Out of range&quot;);</blockquote><blockquote>}</blockquote><blockquote>else {</blockquote><blockquote>Serial.print(distance);</blockquote><blockquote>Serial.println(&quot; cm&quot;);</blockquote><blockquote>}</blockquote><blockquote>delay(500);</blockquote><blockquote>}</blockquote></blockquote>
<p>HERE YOU GO </p>
<p>Hi there,</p><p>I would like to ask if these circuit can be applied for detecting water level. Was it only able to detect concrete object? How about object like water? :)</p>
hey in your schematic diagram position of echo and trig are reversed and the buzzer is not connected to d ground <br>
it's correct my schematics but the image is a bit large... (the yellow rectangle with Vcc trig echo ground) <br>so it's seems it's wrong... but it's working perfectly because I've received tons of emails of people that made this project and it worked! <br>If you have more questions just let me know
<p>Amazing work Rui, I think he is trying to say that on your breadboard when you are connecting the negative side of the buzzer to ground, technically its not because there is a break in the breadboard.</p>
<p>what about if without the bit shifter?.. does work or not?</p>
<p>Hi. I'm having a problem with B00000000 - B11111111 being declared. The verification process is not accepting this array for some reason. Do you have any ideas as to why?</p>
<p>Perfect...<br>More easy i'm dead! Plug &amp; Play!<br>Great explains and presentation.</p><p>(FR)</p>
the buzzer used is a 5v buzzer?or a 9v one?<br>
WHAT is the use of shift register here?<br>
Can you show how to connect multiple hc-sr04<br/>in arduino with same trigger pin by using 74hc595??
Could you please add how to make it independent, by using a 9v battery. I'd like to built it and install in my garage.
I think I've answered to you through facebook, right? <br>if you have more questions please leave a comment on my website! <br>thanks so much for checking out my projects! <br>(http://randomnerdtutorials.com)
My buzzer is rated 3VDC but i hear the buzzer very soft although it's working. Anything wrong with my buzzer? If i connect directly to a 3V supply the buzzer is loud.
Hmm... I put mine all together but all it does is light up all the LEDs and beep the same tone again and again.
hum... try to see the serial monitor and see if the distance sensor is measuring the distance properly. It can be that problem
I got it working. I had the trig and echo wires reversed.
nice I'm glad you make it to work!
sir , can you share a program of this project? :)
what you mean ? <br>If you want the source code it's on my insctructable, feel free to use it ! :)
Nice project,
Thanks! I'm glad you liked it
What if you don't want the LEDs? and want to use a vibrating motor instead of a buzzer? Just gimme some code lolz
Thanks man, I'm really glad you like, more projects soon!
Good work, congratulatios.

About This Instructable


107 favorites


Bio: Author, Blogger, Electronics Enthusiast and Entrepreneur. For complete Electronics Projects and Tutorials go to: http://randomnerdtutorials.com/start-here
More by RuiSantos: ESP8266 Web Server (Without Arduino) Arduino Simple Memory Game Arduino – Datalogger with Temperature Sensor and Photoresistor
Add instructable to: