Ultrasonic Tape Measure
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
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.
Mechanical Design
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. First: I checked the Arduino pins used by the LCD Keypad. They are A0, D4, D5, D6, D7 and D8.
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.
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.
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.