Introduction: Arduino Based Distance Measure Box
Hello, in this project I will show you how to build your own distance meter box with Arduino uno and one ultrasonic sensor.
Before starting, make sure that you have:
- Arduino uno
- HC-SR04 Ultrasonic Sensor
- LCD 16x2
Official page: http://www.ardumotive.com/distance-measure-box.html
Step 1: About HC-SR04 Ultrasonic Sensor
- Ultrasonic Sensors
Ultrasonic sensors work on a principle similar to radar or sonar, which evaluate attributes of a target by interpreting the echoes from radio or sound waves respectively. Active ultrasonic sensors generate high frequency sound waves and evaluate the echo which is received back by the sensor, measuring the time interval between sending the signal and receiving the echo to determine the distance to an object. Passive ultrasonic sensors are basically microphones that detect ultrasonic noise that is present under certain conditions.
-----------------------------
- HC-SR04
The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats or dolphins do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package. From 2cm to 400 cm or 1” to 13 feet. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and receiver module.
- Power Supply :+5V DC
- Quiescent Current : <2mA
- Working Currnt: 15mA
- Effectual Angle: <15°
- Ranging Distance : 2cm – 400 cm/1" - 13ft
- Resolution : 0.3 cm
- Measuring Angle: 30 degree
- Trigger Input Pulse width: 10uS
- Dimension: 45mm x 20mm x 15mm
-----------------------------
- Arduino Library
Download and extract the HC-SR04 Library file to 'libraries' folder of Arduino ide
Attachments
Step 2: Breadboard Schematic
Tip!
If you want to control screen contrast put a 4.7k potentiometer at pin 3 of LCD board instead ground cable.
Step 3: Code
Note: make sure that you have already install hc-sr04 library into Arduino ide 'libraries' folder.
//Libraries
#include
#include
//Setup connection with LCD and HC-SR04
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Ultrasonic ultrasonic(A0,A1);
void setup() {
//Lcd init
lcd.begin(16, 2); //16 rows, 2 columns
}
void loop() {
lcd.clear();
lcd.print(" Ardumotive ;) "); // You can change this message.
lcd.setCursor(0, 1); //Change line...
lcd.print("Distance: ");
lcd.print(ultrasonic.Ranging(CM));
lcd.print("cm");
delay(1000); // 1sec delay
}
Attachments
Step 4: Circuit and Box
I prefer to build my own Arduino based circuit and make my constraction smaller than size of Arduino uno.
To build the box I used one sheet of balsa wood. Before you cut it make sure that your circuit will fit in it.
Steps for success:
- With a pen draw lines where you will cut the sheet
- Cut the sheet with something... Balsa wood is very soft and can be easily cut.
- Put the Arduino uno (or your circuit) , LCD and HC-SR04 on already cut sides
- Final glue the box sides. (i used glue gun pistol)
If you want you can paint it! I paint it green with a marker ;)
5 Comments
4 years ago
Howdy all !
Excellent tutorial, but its a damn shame the code NO LONGER WORKS...
This part; DOES NOT WORK ANYMORE
But i just omitted certain parts to the below and changed to using digital pins not that that should have mattered but i wanted to use other things on the Analogs, it compiles once again but i have NOT tested it yet - still waiting for my HC-SR0 Ultrasonic Sensor to arrive in post, will update when it arrives :)
6 years ago
if this thread still live, please help...
I'm getting this error
sketch_feb25a:15: error: 'class Ultrasonic' has no member named 'Ranging'
lcd.print(ultrasonic.Ranging(CM));
^
exit status 1
'class Ultrasonic' has no member named 'Ranging'
7 years ago
Hi, does this sensor work ok when it is not used in open space. For instance can it be used to measure level of fluid in vertical pipe? (sensor on the top fluid on the bottom?
7 years ago
Can someone post an arduino code to "run a motor" as soon as it reach "25 meter distance"?
7 years ago
Is it possible to work these kind of project to make cheap DRO for lath or manual machines and measurement tool like digital vernier for manual measurement.