loading

Have you ever wanted an ultrasonic tape measure, like this Stanley? (See picture). Well, I have but then I am a Lazy Old Geek. I don’t really need one but I thought I’d try to make one. And naturally, I thought of an Arduino.

August 2012 update: I just found out the software used in this Instructable does not work in the latest Arduino environment, 1.0. I think it is the LCDKeypad library but haven't found an updated version or software fix. However, this does work with version 023. LOG

Step 1: Parts List

Arduino                                  $17.60 (Duemilanove 2009) ebay.com
HC-SR04 Ultrasonic           $  4.61 ebay.com

LCD Keypad (Arduino)       $  8.88 ebay.com

Now I realize this is about $30 where the Stanley is available for around $24 but these parts are not committed to one function like the Stanley is.

Parts selection:
I wanted an Arduino that was shield compatible. I already have two, a Freeduino and Seeduino so I decided to buy a third. Right now, one of the best deals I liked is for a standard Arduino Duemilanove 2009 on ebay.
By the way, mine came with an Atmega 328-PU instead of the ‘standard’ Atmega328P-PU. I discussed this in another Instructable:

https://www.instructables.com/id/My-Arduino-Bootloader/

The LCD keypad also has Arduino support plus five user pushbuttons and a 16x2 (16 characters x two rows) display.

Step 2: Mechanical Design

First:I checked the Arduino pins used by the LCD Keypad. They are A0, D4, D5, D6, D7 and D8.
I’d already tested the HC-SR04. I’d set it up to use D2 and D3 and it needs 5V and Ground. So there would be no pin conflicts.

Modification1: The HC-SR04 had male right angle header pins coming out of the bottom of the module. To save room, I wanted them to come straight out of the PCB.
One way: So what I did was unsoldered the four pin connector, removed it and replaced it with straight male pins. (See picture) I also put some electrical tape on the back of the PCB to hopefully prevent it from shorting out.
Better way: That was a hard way to do it. I think a better way would be to take some pliers and carefully straighten the pins. They would be too long but could be cut off.

Second: Tthe LCD keypad is a standard shield and fits right onto a shield-compatible Arduino. The problem is how to connect the HC-SR04 to the system. I didn’t want to solder it directly to the shield or the Arduino.
Well, the LCD keypad has a nice feature. It has the standard male header shield connectors but it also has some extra 0.1” solder pads outside of the shield connectors but connected to the shield pins. (See picture)
This is the schematic for the HC-SR04 wiring that I used. (See picture)
Modification2: On the bottom of the LCD Keypad, I soldered two male header pins for 5Vdc and GND, so that they pointed downward. (See picture) This was so the connectors and wires would be out of the way for viewing the LCD.
On the top side, I soldered three male header pins on D1, D2  and D3. I used three pins so that it was easier to distinguish the two connectors though I only connected wires to D2 and D3.

TIP: If I was thinking ahead, I would probably have soldered complete six and eight pin male header strips. These might be useful for future projects.
Since it is easy to flip connectors, I used some red nail polish to mark one side of each connector and header.
 

Step 3: Software Design

The LCD keypad and HC-SR04 each have Arduino libraries that have to be added to your Arduino software. Attached
The HC-SR04 libraries had some functions that would print out measurements in inches but I wanted a little better resolution so I wrote my own.

Technical stuff:
Theory of Operation: Basically, the user sends a trigger pulse to the module which sends out an ultrasonic wave. After a period of time the receiver gets back a reflection. The duration determines the distance. The documentation gives a little formula to find distance.
Distance = ((Duration of high level)*(Sonic :340m/s))/2
Now this is a not very clear even for a Geek but I figured out that it meant.
Distance in Meters = Duration in Sec * 340 Meters/Sec/2
The documentation isn’t very clear but the HC-SR04 library has a function called Timing. It is based on pulseIn and returns a duration in microseconds(uSec)
I want Distance in inches

So I used the following algebraic transformations:
Distance M = Dur uS *340M/1000000uS/2
DistancecM=Dur uS*340cM/10000uS/2
Distance In = Dur uS * 133.85827In/10000uS/2
Distance In = Dur uS *.013386 In/2
Distance In = Dur uS *0.00669 In

In my code: distanceIn=ultrasonic.Timing()*0.00669;

For the rest of the world which probably prefers centimeters:
distance cM= ultrasonic.Timing()*0.0170;

I also wrote it so that if the distance is over 60in(5foot) then it would convert the output to feet.

The LCD keypad has 16 characters x 2 lines so I divided it up into four sections. The software is setup so that it will continually sample the distance. If the user presses the ‘Select’ button, it will save the value at one of the four locations and move to the next location.

Some of the manufactured electronic tape measures will actually calculate area and/or volume but I didn’t bother.

My Arduino sketch is attached.

 

Step 4: Operation and Conclusions

For portability, I used a six-AA battery pack from Adafruit
http://www.adafruit.com/products/248
with rechargeable batteries.

It works pretty good. The resolution is supposed to be 0.3cM(0.12in). That seems reasonable. The range is supposed to be 450-500cM(16.4feet). Now I only got about 11feet. (still investigating).
The effective angle is supposed to be less than 15 degrees so you have to take that into consideration.
Sometimes, when I press the Select button, it fills several locations. I need a debounce circuit. But right now I just push the reset button.

I love this thing. the newer arduino writers made it a little more difficult than it first looked because of the library upgrades that needed to be modified. I also altered the code making the trigger and echoPin 12, 13. I then made 11 a constant HIGH to use it as the 5v source. that way it all lines up with the ground at the end of the uno and can be soldered right in after flipping the pins on the sensor. please excuse my crap de- soldering. this is one of the boards I use for prototypes so I don't mind if I break it.<br><br>however, I'm still having a glitch. the range only go's to 20.1 inches and just maxes out at that. is there something I can do to fix it?
<p>Glad you got it working mostly. Not sure why you have limited range. The only thing I can think of is something interfering at 20.1 inches. You might try it somewhere else like outside.</p><p>LOG</p>
<p>tried it outside and anywhere else i could reach it too, still stuck. i have switched out unos, ultrasonic sensors, rechecked my wiring, even downloaded your file again just in case i accidentally did something to it. still reading a maximum of 20.1. </p>
<p>Sorry, I think you've tried everything I would have. </p><p>What version of Arduino are you using?</p><p>LOG</p>
<p>ummmm... the blue model? i have tried it with several different Unos that range in age and quality from cheap chines knock offs that are a few years old, to more modern and updated... cheap Chinese knock offs. im sure at this point that it isnt the code at all and have narrowed it down to bad hardware, or that the gremlin that steals all my left socks from the dryer has put an anchent voodoo curse on it... it really could be either one at this point. </p>
Have you actually tested how accurate this is?
No, I haven't. <br> <br>LOG
Hi: <br>I replicated the tape measure exactly, but hooking up Trig &amp; Echo to 2,3 results in it just showing 0.0 and not measuring. I transferred it to my mega 2560 and it works when assigned pins not connected to the LCD shield. I would like to know what i'm doing wrong with my UNO R3. <br> <br>Thank You, <br>Albert L. Chupick
The way I would troubleshoot it: <br>0. Do a visual inspection of your work to look for shorts, solder bridges or cold solder joints. <br>1. Connect HCSR04 and LCD to UNO R3 <br>2. Without power, with a DMM, measure for continuity between HCSR04 Trigger and D2 on the UNO R3 which is Atmega328 pin 4. <br>3. Measure continuity between Echo and Atmega pin 5 <br>4. If ok, then turn on power and make sure you have 5V and ground on the HCSR04 <br>5. Load sketch and carefully wiggle all added connections to see if you get any reading. <br>6. If still not working, turn off power and make sure pin 4 or 5 aren't bent over instead of going into the socket. <br>7. If still not working and you have one, try a different Atmega328. <br> <br>Hope this helps. <br> <br>LOG
I installed all the library files but after compiling I get this error - <br> <br> In file included from sketch_dec06a.cpp:2: <br>C:\Users\Chris\Desktop\ARDUINO\arduino-1.0.1\libraries\HC_SR04Ultrasonic/Ultrasonic.h:11:22: error: WProgram.h: No such file or directory <br> <br>The HC_SR04 library has been installed. Anyone any ideas please - still relatively a noob . Tx
Its ok I got it, for anyone else you need to 'edit' the library files and change anything that says wprogram to arduino if you are using a newer version of arduino.
Thanks for figuring this out. This Instructable was written using Arduino 0023 Environment and I don't have the hardware readily available. When Arduino released 1.0.0, I heard that were some compatibility problems. Usually, when I run into a problem, I'll revert to the older Environment. But your solution is probably better. <br> <br>Thanks <br> <br>LOG
I'm a total Noob. I can't figure out how to even save this so i can compile it. I can't figure where to save it to. I don't have the sub folders as described.
I just discovered that this software will not work with the latest Arduino environments. However you can still get and use older versions like 0023 that does work. <br> <br>LOG
Hopefully, you are using a Windows computer as I'm not familiar with Linux or Mac. I assume you already have the Arduino software loaded onto your computer. You should have a directory called Arduino-???. Mine is Aruduino-0023 for the version number. Under this is a subdirectory called libraries. Unzip the first three downloads and copy the zipped directory into libraries. So under libraries you should have directories called HC_SRO4Ultrasonic, LCD4Bit_mod and LCDKeypad. <br>The UltraRanger file is the program sketch. I don't think it matters where you store it but I store all of my sketches in a directory under Arduino-0023 called MTS. So it would look like this c:\arduino-0023\MTS\UltraRanger. <br>TIP: Apparently a .pde file has to be in a subdirectory of the same name. So I have UltraRanger.pde under UltraRanger directory.<br>Now I'm not sure but it seems like sometimes I had to reboot my computer to get the Arduino environment to see everything.<br>Now when you start up your Arduino software, you go to file open and find the UltraRanger directory and open up UtraRanger.pde.<br><br>Hope this helps.<br><br>LOG
I have it working now. Finally. I was having the same problem as crack hacker.<br>When using Arduino-1.0 you have to change all of the WProgram.h to Arduino.h for it to work with the new software. I thought i was downloading it wrong. Very cool project. Thanks for the Instructable.
Hey thanks a lot for the instructable! It's very helpful for beginners such as myself. The device's simplicity makes it easy to understand, as well as add new features to it in the future. Your shared knowledge is much appreciated!
I started using the Arduinos as they are user friendly and there is so much support online. For all the help I received and receive, I like to pay back with some of my own experiences. <br> <br>LOG
Thanks for this instructable, it will help me with a current project!
Hope it works!<br><br>LOG
i am having some trouble with the include header for the lcd keypad. i am using arduino 1.0 IDE and the libraries i have downloaded just toss errors when compiling. did you have this trouble?
I didn't have any trouble with the libraries but I think I used Arduino version 22. <br><br>I suspect you need to update your Arduino IDE but you might also try to reload the header files. One source is:<br>http://iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/<br><br>though the download is an *.rar file<br><br>Iteadstudio has some good information on the HC-SR04.<br><br>Hope this helps.<br><br>LOG
arduino 1.0 is the most current IDE.<br><br>not having trouble with the ultrasonic just the lcd keypad thing but i will check out the site you mentioned.<br><br>thanks for the reply bro
You're right. I didn't know they changed their revision numbering. If you don't have any luck, you might try 0022, I know mine worked with that one.<br><br>LOG
Very nicely done! I take it that the distance is measured from the very front of the device? Would it be easy enough to add a variable adding the length of the device so that it could be placed against a wall, for example? I'm assuming you could just add the measurement to dist before the printLCD?
Thanks,<br><br>Yes, the measurement is from the front of the device, <br><br>That's a good idea about measuring from the back of the Arduino. It's a little tricky in that the power connector is on that side so that would have to be added in also or you could mount the sensors on one of the sides or maybe even perpendicular to the LCD.<br>Right now I have mine torn apart for some other projects but the idea behind my design is so that it can be easily recreated just by plugging in the cable connectors and the sensor. Assuming that I can find them again.<br><br>LOG
You could power it with a battery (for example 9V with 5V regulator), and then do some simple math. Take the measurement + the length of the device.
Yes. With the way I have it setup, the 2.1mm power jack and wire would also have to be added to the length since the connector comes out of the 'back'.<br>LOG
What's the total measurable distance on these ultrasonic sensors?
It is supposed to measure up to 500cm about 16.4 ft. I couldn't get mine to measure over 11 feet but haven't really looked into this.<br><br>LOG

About This Instructable

21,321views

90favorites

License:

Bio: Lazy Old Geek
More by msuzuki777:Senior Moments Weather Station 5 IP Time Clock Part 2 
Add instructable to: