Introduction: Arduino Based Distance Measure Box

Picture of 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

Picture of 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

(see this video if you don't know how to find it)

Step 2: Breadboard Schematic

Picture of 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

}

Step 4: Circuit and Box

Picture of 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 ;)

Step 5: Distance Measure Test

Picture of Distance Measure Test

Comments

KetanS12 (author)2017-02-25

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'

druševljan (author)2016-06-03

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?

nageshsp (author)2016-04-24

Can someone post an arduino code to "run a motor" as soon as it reach "25 meter distance"?

amjadpksbp (author)2016-02-19

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.

GaganS made it! (author)2015-08-28

Thanks a lot for this instructable!!!!!!!Your library was very useful. I also made another instructable in which I used your library(is it okay).

Thank you!!!!!!!!!!!!!!!

Ardumotive_com (author)GaganS2015-09-01

nice!!

jmorgan22 made it! (author)2015-02-28

It's alive! Thanks Mi Vasilakis!

Super easy instructions to follow and worked second time (the first time I forgot what way the bread-board lines run! My bad!) So really it works first time!

The 4.7k pot (I used a 5k) works really well too, just helps in different light situations.

Ardumotive_com (author)jmorgan222015-02-28

Yeah! Thats good news!!! Thanks for comment and photo jmorgan22 !!!