loading

## UPDATED WITH CODE, SCHEMATICS AND PARTS WITH LINKS ##

= Introduction =

Hi everyone! This is my first instructable!

After reading hundreds of instructables, I decided to make one myself!

As a brazilian, my mother language is portuguese. So, please be patient with my english.

= What did I make? =
I have built an animated Sonic Ruler using an Arduino, an HC-SR04, a buzzer, two resistors, some wires and a LCD Display. I also used an expansion module for Arduino (optional) and a breadboard. It had a very defying coding and debugging, but now I see it did worth the effort!

The mounting should be easy if you have already mounted some gadgets on breadboards, so any Arduino enthusiast can actually build it! Even begginers!

= Why did I make it? =

There are many projects so far using a HC-SR04 as a measurement gadget, but I have seen none using an animated LCD and a buzzer integrated. This one got style and personality!

My project can also be used as a parking sensor. Just by adding some meters of wire you can actually install this on your vehicle to make sure you'll never hit that wall again.

Step 1: Gathering Materials...

Total cost (suposing you already have an Arduino - do the math) = LESS THAN 10 DOLLARS!!!

Step 2: Breadboard Mounting and Wiring

    Mount the components using these images as guidelines. The most important thing is to make the connections as follows:

    • LCD VSS pin to ground;
    • LCD VDD pin to +5V;
    • 2K2Ohm resistor: ends to LCD VO pin and ground;
    • LCD RS pin to digital pin 9;
    • LCD R/W pin to ground;
    • LCD Enable pin to digital pin 8;
    • LCD D4 pin to digital pin 5;
    • LCD D5 pin to digital pin 4;
    • LCD D6 pin to digital pin 3;
    • LCD D7 pin to digital pin 2;
    • LCD A pin to +5V;
    • LCD K pin to ground;
    • Buzzer + to 220Ohm Resistor leg and - to ground. The other resistor leg goes to pin 12.;
    • HC-SCR GND to ground;
    • HC-SCR Echo to pin 11;
    • HC-SCR Trig to pin 10; and
    • HC-SCR Vcc to +5V.

    Step 3: Code & Upload

    Here goes the code:

    https://github.com/Raphango/Animated-Sonic-Ruler/blob/master/AnimatedSensor.ino

    And the sounds library used with the code:

    https://github.com/Raphango/Animated-Sonic-Ruler/blob/master/pitches.h

    DO NOT FORGET TO PUT THE SOUNDS LIBRARY IN THE SAME FOLDER OF THE .INO FILE!

    Step 4: Final Thoughts

    At this project you have learned how to use the HC-SR04 and the LCD with Arduino.

    Feel free to make yourself one! And once you make it, why not to make it more permanent, by putting it on a PCB? Why not to embed it in a 3D printed case?

    Use your creativity!


    Thank you for reading!

    <p>Nice work bro. I will try it soon. I hope I can ((:</p>
    Thanks man! =D
    <p>Hi , i made same project but first i tried without buzzer now im trying to use the buzzer but i cant find the code . Can you help me .</p>
    <p>The code piece for using the buzzer is already in the code available. Mind, however, that you should download the &quot;pitches.h&quot; file at the bottom of this instructable in order to make the buzzer work correctly.</p><p>Good luck!</p>
    <p>I made same project. But mine is telling the distance when a block appears in front of the ultrasonic sensor. You can check my project. :)</p><p>https://www.instructables.com/id/Arduino-wtv020-Sd-16P-Talking-Distance-Meter/</p>
    <p>Excellent! </p>
    <p>Nice work bro,Its GR8</p><p>REGARDS</p>
    <p>how to put the sound library inthe same folder.i dont understand</p>
    The sounds library is the &quot;pitches.h&quot; file.<br>You have to put it in the same folder of the Arduino Sketch (.ino file).<br><br>Any more doubts? =)<br><br>
    <p>Mine is saying fora do alcance, what is wrong?</p>
    <p>Take a look at this fragment of code:</p><blockquote>if (distance &gt;= 400 || distance &lt;= 0){//Evaluate the distance value.<br> lcd.setCursor(0, 0);<br> lcd.print(&quot;Fora do alcance &quot;);<br> lcd.setCursor(0, 1);<br> lcd.print(&quot; &quot;);<br> }<br> else {</blockquote><p>If your sensor gets a measure greater than 400cm or equal to 0cm, the it will show you the &quot;Fora do alcance&quot; text, that means that it's out of range.</p><p>I see two possible solutions for this error:</p><p>1) Check the connections; see if there's any incorrect wiring. You may use a multimeter to check the continuity of the wires. The default value for the &quot;distance&quot; variable is &quot;0&quot; so, if your sensor reading is never updated, it will give you &quot;Fora do alcance &quot; forever.</p><p>2) Check if your ultrassonic sensor is working properly, and if it's receiving enough voltage.</p><p>I hope it helps!</p>
    <p>the sketch not work for me, please help me</p>
    <p>Did you follow the steps exactly? Can you describe the problem?</p>
    Hi, awesome project. <br>I am trying to get this project on my car but I'd like to use 6 sensors and a temperature sensor (for replacing &quot;out of range&quot;) <br>When I tried to add the second sensor everything become slow and doesn't work on real time. <br>I can post the code I made if you /anybody can help me please
    <p>It's so awesome...!!!!!!</p><p>I succeeded in making this.....</p><p>Thank you so much.... </p><p>Where will I get the detailed working information and the function of the components???</p>
    <p>Thank you! ^^ All the info I've gathered from the internet: other instructables, google, datasheets, etc.<br> A good source for an overall vision at the components is the link to the site where I bought it (DX.com for the <a href="http://www.dx.com/pt/p/hc-sr04-ultrasonic-sensor-distance-measuring-module-133696#.VTjW-PnUtNS" rel="nofollow">HC-SR04</a> and <a href="http://www.dx.com/pt/p/1602a-16-x-2-lines-white-character-lcd-module-w-blue-backlight-dc-5v-151978#.VTjWaPnUtNR" rel="nofollow">LCD Display</a>). You'll have to look at the description of the itens.<br> <br> And if you really like the subject &quot;Sensors&quot; (what includes the HC-SR04 ultrasonic sensor) you could buy <a href="http://www.amazon.com/Make-Sensors-Hands-On-Monitoring-Raspberry/dp/1449368107" rel="nofollow">this book</a> (which I have and is very good).<br> <br> Happy making and God Bless you!! =D</p>
    <p>Nice work ! Although if I were to make it for myself , I would get rid of all the extra shiny things and just use it to display the distance and buzz without the use of special characters and custom music. :) Any pointers as to how I would go about doing that ? </p>
    <p>LoL! xD</p><p>I just made all these extra shiny things to make the project more fancy... ^^</p><p>So... to get rid of the mario theme just delete this line of code:</p><p><strong>//Plays intro song</strong></p><p><strong>playSong(0,1.30);</strong></p><p>And to get rid of the special charachters, just remove these lines:</p><p><strong>//Each of these &quot;lcd.setCursor&quot; and &quot;lcd.write&quot; are responsible for the drawings.</strong></p><p><strong>lcd.setCursor(10, 0);//This positionates the cursor on the desired slot</strong></p><p><strong>lcd.write(byte(0));//This writes the prefab symbols lcd.write(byte(1));</strong></p><p><strong>lcd.write(byte(4));</strong></p><p><strong>lcd.write(&quot; &quot;);</strong></p><p><strong> lcd.write(&quot; &quot;);</strong></p><p><strong>lcd.write(&quot; &quot;);</strong></p><p>Mind that you might have to adjust the position of the other texts... =)</p>
    <p>Sir, what is the meaning of &quot;1.30&quot; on this sketch: &quot;playSong(0,1.30)&quot;. Thx for your answer. Nice project for newbie like me.</p>
    <p>Thanks! ^^</p><p>Take a look at this piece of code:</p><p>int playSong(int track, float durConst){</p><p>for (int thisNote = 0; thisNote &lt; sizes[track];</p><p>thisNote++) { int noteDuration = 1000/noteDurations[track][thisNote];</p><p>tone(buzPin, music[track][thisNote],noteDuration);</p><p>int pauseBetweenNotes = noteDuration * durConst;</p><p>delay(pauseBetweenNotes); noTone(buzPin);</p><p>}</p><p>}</p><p>Actually, this is the function &quot;playSong&quot;. When I invoke this function as in </p><p>&quot;playSong(0,1.30)&quot; I'm telling Arduino to play the &quot;track&quot; number &quot;0&quot; for the 1.30 constant time factor multiplier. The higher the number, the more will last the note.</p><p>Got it? =D</p>
    <p>please.... i need you project, can you show step by step on compile the code</p>
    <p>First of all, you have to include the &quot;pitches&quot; library (the file is above) with the following command line:</p><p><strong>#include &quot;pitches.h&quot;</strong></p><p>This is the part of the code responsible for the sounds:</p><p>////Sound notes setupint melody0[] = {NOTE_B3, NOTE_B3,NOTE_B3, NOTE_G3, NOTE_B3,0, NOTE_D4, NOTE_D3};int melody1[] = {NOTE_C6,NOTE_C6,NOTE_C6,NOTE_C6};int melody2[] = {NOTE_C6,NOTE_C6,NOTE_C6};int melody3[] = {NOTE_C6,NOTE_C6};int melody4[] = {NOTE_C6};//Add melodies here, and at the end of the &quot;music&quot; array.int* music[6/*number of melodies + 1*/] = {melody0, melody1, melody2, melody3, melody4 /*,add here*/};////Sound notes durationsint notesMelody0[] = {8,4,4,8,8,8,2,4};int notesMelody1[] = {8,8,8,8};int notesMelody2[] = {8,8,8};int notesMelody3[] = {8,8};int notesMelody4[] = {4};//Add durations of the melodies here, and at the end of the &quot;noteDurations&quot; array.int* noteDurations[6/*number of melodies + 1*/] = {notesMelody0, notesMelody1, notesMelody2 , notesMelody3 , notesMelody4 /*,add here*/};////Sound sizesint sizeMelody0 = sizeof(melody0)/sizeof(int);int sizeMelody1 = sizeof(melody1)/sizeof(int);int sizeMelody2 = sizeof(melody2)/sizeof(int);int sizeMelody3 = sizeof(melody3)/sizeof(int);int sizeMelody4 = sizeof(melody4)/sizeof(int);//Add sizes here, and at the end of the &quot;sizes&quot; array.int sizes[] = {sizeMelody0,sizeMelody1,sizeMelody2,sizeMelody3,sizeMelody4 /*,add here*/};////Tone Function - Plays the toneint playSong(int track, float durConst){ for (int thisNote = 0; thisNote &lt; sizes[track]; thisNote++) { int noteDuration = 1000/noteDurations[track][thisNote]; tone(buzPin, music[track][thisNote],noteDuration); int pauseBetweenNotes = noteDuration * durConst; delay(pauseBetweenNotes); noTone(buzPin); }}</p><p>But what actually plays the tone is this function callback:</p><p><strong>playSong(1,1.30);</strong></p><p>Hope it helps!!</p>
    <p>I just want to make simulation..</p>
    <p>How to make pitches into the code</p>
    <p>this code gives many erors how can i solve it</p>
    <p>Follow these steps:</p><p>1-Double check the circuit. See if every single piece of the circuit is attached correctly.</p><p>2-Did you download all the files and libraries (including pitches.h)? You'll need it for the correct functioning of the project.</p><p>3- Se if your LCD is compatible with the libraries you've been using.</p><p>If you still can't make it work after all these steps, please post these errors you talk about, so I can help you.</p>
    Finally made my own!! Cool project though.. Thanks for sharing it!
    <p>Awesome!!! xD</p><p>Congratulations!</p><p>It's not ugly! Seriously! =D</p><p>If you really liked the project and do want to make a permanent version of it you could start to think how to put it in a PCB using a barebone arduino.. just an idea to think about! ^^</p>
    <p>This is just a prototype so it looks ugly :P</p>
    awesome project thanks for uploading :-P
    <p>Thanks! ^^</p>
    <p>Hi,i have a problem with code...<br>arduino software give me a error:<br>int melody0[] = {NOTE_B3, NOTE_B3,NOTE_B3, NOTE_G3, NOTE_B3,0, NOTE_D4, NOTE_D3};<br>this is the problem:<br>sketch_sep08c.ino:44:21: error: pitches.h: No such file or directory</p><p>sketch_sep08c:60: error: 'NOTE_B3' was not declared in this scope</p><p>sketch_sep08c:60: error: 'NOTE_B3' was not declared in this scope</p><p>sketch_sep08c:60: error: 'NOTE_B3' was not declared in this scope</p><p>sketch_sep08c:60: error: 'NOTE_G3' was not declared in this scope</p><p>sketch_sep08c:60: error: 'NOTE_B3' was not declared in this scope</p><p>sketch_sep08c:60: error: 'NOTE_D4' was not declared in this scope</p><p>sketch_sep08c:60: error: 'NOTE_D3' was not declared in this scope</p><p>sketch_sep08c:61: error: 'NOTE_C6' was not declared in this scope</p><p>sketch_sep08c:61: error: 'NOTE_C6' was not declared in this scope</p><p>sketch_sep08c:61: error: 'NOTE_C6' was not declared in this scope</p><p>sketch_sep08c:61: error: 'NOTE_C6' was not declared in this scope</p><p>sketch_sep08c:62: error: 'NOTE_C6' was not declared in this scope</p><p>sketch_sep08c:62: error: 'NOTE_C6' was not declared in this scope</p><p>sketch_sep08c:62: error: 'NOTE_C6' was not declared in this scope</p><p>sketch_sep08c:63: error: 'NOTE_C6' was not declared in this scope</p><p>sketch_sep08c:63: error: 'NOTE_C6' was not declared in this scope</p><p>sketch_sep08c:64: error: 'NOTE_C6' was not declared in this scope<br><br>Please help me!</p>
    Did you download the sound library and put it in the right directory?
    Sorry,i don't download sound library....put in the right directory where in folder of arduino..or in code...?thanks for you help!<br>wait for reply!
    <p>You have to put the file in the same folder of your sketch. The line &quot; #include &quot;pitches.h&quot; &quot; at the code does the 'link' between your code and the &quot;pitches.h&quot; file. Be sure to copy and paste the code exactly so you won't have any problem.....</p><p>Let me know if you've managed to make it work! ^^</p>
    would love the step by step guide and arduino schematic. awesome project!
    <p>Thank you very much!</p><p>I have just updated it with the code and schematics!</p>
    Thank you ! Can I have the schematics of the circuit and the arduino sketch please :)
    <p>Off course!</p><p>I'll post the schematics and the mouting images as soon as I make it.</p><p>For the sketch, I'll post it by the moment I put the schematics in.</p>
    buen projecto,me gusta lo de la animaci&oacute;n de la distancia :-) el c&oacute;digo me gustar&iacute;a tenerlo
    <p>Gracias!</p><p>Yo cr&eacute;o que en poco tempo tendr&eacute; un &quot;step-by-step guide&quot;.</p><p>Mientras no lo concluo, me poner&iacute;a muy grato si puede votar en mi proyecto.</p>
    <p>cool project</p>
    Thank you!

    About This Instructable

    8,991views

    79favorites

    License:

    More by Raphango:ATTiny85 Game Timer - Get rid of that old hourglass! Animated Sonic Ruler / Parking Sensor using Arduino 
    Add instructable to: