Introduction: Digital Ultrasonic Tape Measure
This instructable will show how to build a digitial tape measure using a HC - SR04 ultrasonic distance sensor and an Arduino Pro Mini. This was inspired by elecronics for everyone's instructable which can be found HERE.
I have entered this in the Tech contest so please vote if you like this.
Step 1: Supplies
You will need:
- 16x2 LCD display
- Half Breadboard
- Arduino Pro Mini and FTDI chip for programming
- 2 x Momentary Push Buttons
- 2 x 10k Ohm resistors
- 9V Battery adapter
- 9V Battery
- Variable Resistor (10k Ohm works well)
- HC-SR04 Ultrasonic Distance Sensor
- Switch
- Jumper Wires
- Hookup wire
- Case for the measurer (I used the case my old iPod nano came in)
(Note: many of the above items can be found in this kit which I have purchased and recommend)
Tools:
- Wire strippers
- Soldering iron and solder
- Rotary tool
Step 2: Constructing the Container
I used an old iPod nano retail box as a case for my digital measurer and a 400 tie-point breadboard. It was necessary to remove one of the power rails from to make it fit in the container. To make the holes for the ultrasonic sensor first put it in the case and mark the outlines of the transmitter and receiver. Then use the Dremel tool to grind out the holes. You should also drill a hole in the side for the power switch and the front for the two buttons. Next drill four holes in the lid to hold up the screen. My original plan was to use screws but I didn't have any that were narrow and long enough to fit so I used twist ties instead.
Step 3: Wiring and Assembly
The assembly was one of the more difficult parts because there is so much to fit into a relatively small area. In the end I had to bend the pins on the LCD screen so that they were parallel to the back of the LCD and move the 9V battery to outside of the case. I was able to save some space by using twist ties on the wires to the LCD and using some hookup wire for some of the breadboard connections instead of longer Dupont wires. I also ended up switching out the larger 50k pot for a 10k pot with a smaller form factor. Once all of the wiring was done and everything was in place the case no longer shut all of the way so I used electrical tape to hold it firmly shut.
The Fritzing diagram above shows how I wired this project and the connections are listed below. The buttons need to be connected to D2 and D3 and need to go to HIGH when pressed. They should have a pull down resistor to Ground when not pressed which I used a 4.7k resistor for.
Arduino | LCD
- GND | VSS
- Vcc | VDD
- Pot | V0
- D13 | RS
- GND | RW
- D11 | E
- D5 | D4
- D4 | D5
- D7 | D6
- D6 | D7
- Vcc | A
- GND | K
Arduino | HC-SR04
- Vcc | Vcc
- D8 | Echo
- D9 | Trig
- GND | GND
Attachments
Step 4: Code
The code for this is slightly different than most other Arduino projects because there is no code in the Loop. Instead, it operates off of Interrupts meaning code executes only after user input; in this case, pressing one of the buttons. The Arduino Pro Mini can only accept interrupts on digital pins 2 and 3. An Interrupt is set up so that when pins or 2 or 3 detect a rise in voltage (voltage goes to HIGH), the functions attached to the Interrupt will execute.
One button is set to measure and the other switches between SI and metric units. SI units are reported as feet and inches and metric units are in cm. The code defaults to standard velocities for the speed of sound but there is also a scaling factor (called fudgeFactor) which can be adjusted if you find that the values are systematically biased high or low. The speed of sound can be influenced by many factors including temperature, elevation, and humidity so experiment a little to see if you need to adjust the fudgeFactor variable to get good results.
The ultrasonic sensor is very simple and works by putting the transmit pin HIGH for some length of time (I use 10 milliseconds), then pulling it low and using pulseIn on the receive pin. Pulse in measures the time in microseconds between the function being called and it being triggered to level set in the function, in our case HIGH. After that we can use that time (divided by 2 to account for the round trip) to calculate the distance.
If you've never programmed an Arduino Pro Mini before you can look at Step 4 in my Motion Detector With LED for Beginners Instructable for detailed instructions. This code ought to work without modification for an Arudino Uno as well.
I have embedded the .ino file here and you can find the code on my GitHub page Here.
Attachments
Step 5: Measure Away!
Congratulations! You've finished making your very own digital tape measure! I've found that my own digital tape measure is accurate to around 0.1 inches though it only seems to measure out to around 13 feet before giving garbage results. It also does best with larger, flat surfaces so I wouldn't throw away your regular tape measure just yet. I hope you found this helpful and fun and let me know in the comments if you have any questions!