Distance Measurement by Ultrasonic Sensor – An Efficient Remedy
for Perilous Situations in Measurement

Le Tuan Vu1, Van Dinh Trieu1 and Dang Thanh Tin1

1 Bach Khoa University, Ho Chi Minh City, Vietnam

Email: [email protected]

Up until
now, measurement is considered as a fundamental demand in man’s life and
innovation process. In many aspects of life, the
need for accurate measurement is increasing as measuring size and distance of
the object serves the purpose of designing, installing and establishing. There is availably a wide range of distance measurement
methods to cope with specific situations and environments.  Sharing the same aim, distance measurement
device using ultrasonic sensor is examined for a straightforward performance in
measuring from a distance.


ultrasound, ultrasonic waves, ultrasonic sensor, distance measurement, arduino.


It is a fact that traditional measurement techniques such as
several categories of rulers expose their crucial flaws which are the inability
to mete from long distance, the danger when users have to tackle the arduous
geographic environment and the time-consuming implementation. As a solution
given by the development of technology, ultrasonic sensor or laser beam are
often applied in measuring distance for the purpose of facilitating users and
diminishing the risk during meting process as well as the time requirement.
These methods have their own upsides and downsides and vary in the price, size
of device, the accuracy, the productivity, energy consumption level as well. In
the market of this field, there are a number of companies taking up producing
these devices with a relatively high price and the diversity of their
functions. Take Bosch GLM product as an example, it is a measurement device
using laser beam, which is challenging to individually purchase. With an aim to
building a portable, energy-saving, reasonably priced and highly accurate
equipment, Ultrasonic sensor is chosen for this project.

The distance measurement device using ultrasonic includes an
ultrasonic sensor, a temperature sensor DS18B20, a LCD screen displaying the
result, a microcontroller Arduino Nano and 9V battery. Brief discussion on the
applied methods is in section 2, principle in section 3, result analysis in
section 4. The conclusion will be in the section 5.

II. Method

A. Tools

US-015- Ultrasonic sensor is used to define the distance.
This sensor is chosen as a result of being low-cost and providing relatively
precise capacity of measuring which meets the primary needs of users.

Fig. 1 Ultrasonic sensor

Specification of US-015



Static current


Working temperature

0 ~ +70oC

Output way


Induction Angle

Less than 15o

Detection range

2cm to 400cm

Detecting precision

0.3cm + 1%

Sensor size

45 x 20 x 1.6 mm


The DS18B20 is a digital
thermometer which provides high resolution (12 bits). IC uses one wire
communication which is succinct, straightforward to program, and enables the
communication between numbers of DS18B20 in one wire.  In addition, IC has function of warning when the
temperature exceeds the allowanced level and be able to supply power from data
pin (parasite power).

Fig. 2 DS18B20 Temperature Sensor

Specification of DS18B20


3 – 5.5V

Usable Temperature Range

-55 oC ~ 125 oC


±0.5oC from -10 oC to +85 oC


9 ~ 12 bits

Communication protocol

1 – Wire


Arduino nano is a small, complete, and breadboard-friendly version of Arduino Uno R3 SMD basing on MCU
Atmega328P. Sharing the same MCU, It
has more or less the same functionality and program of the Arduino Uno.

Fig. 3 Arduino Nano v3.0

Specification of Arduino Nano





Operating Voltage


Flash Memory

32KB of which 2KB used by bootloader



Clock Speed

16 MHz

Analog I/O Pins




DC Current per I/O Pins


Input Voltage


Digital I/O Pins


PWM Output


Power Consumption


PCB Size

18 x 45mm

B. Theoretical base 2

Ultrasound is sound waves with frequencies higher than the upper
audible limit of human hearing. This upper audible limit depends on each
individual and human hearing normally tops out at
around 20 kHz. Ultrasound can pass through several substances which are
similar to sound environment such as air, solid and liquid by the speed of
sound. Despite having the same speed of propagation, the ultrasound’s frequency
is much higher than that of the sound which leads to their short wavelengths.
Due to this characteristic, resolution of the ultrasonic images allows user to
define objectives whose dimension is in centimeter or millimeter. Therefore, Ultrasonic imaging applications include industrial
non-destructive testing, quality control and medical uses. Due to the invisibility
of ultrasound, it is currently applied in observation applications to measure
distance or speed of things. Besides, Ultrasound technology is spreading in
many aspects of life such as ultrasonic cleaner, ultrasonic soldering,
ultrasonography and so forth.

nature, a number of animals are capable of emitting and receiving ultrasound.
Bat, for instance, is known as an animal having weak sigh but they transmit and
sensor the ultrasound-a trick called echolocation to locate their surroundings.
Toothed whales, including dolphins, can hear ultrasound and use such sounds in
their navigational system (biosonar) to orient and capture prey.  Ultrasound radar is a practical solution for
the fact that radio wave is inactive in water environment. A discernable
application of ultrasound is submarine’s navigational system, radar, depth
measurement of the ocean. The picture below depicts the advent of ultrasound in


Fig. 4 The advent of ultrasound in nature

Basing on the observation of animal activities relating to
the utility of ultrasound, it can be concluded that the principle manipulating
ultrasound in the navigation is such simple that can be summarized in three
steps: Initially, the subject produces ultrasonic waves which travel through
distance and collide with obstacles in the surrounding environment and then
reverberate. Afterward, the time ultrasonic waves are emitted and received is
recorded for further calculation for the distance between the subject and
object. The computation depends significantly on the transmission medium. This
can be proven by the fact that sound waves travel faster in water or metal than
the air.  It is noticeable that
ultrasonic wave is impossible to transmit in vacuum.

As usual, the problem relating to ultrasound is solved using
a constant speed of v = 340m/s. This figure is acceptable in case error is
permissive in order to simplify the computation. In reality, this case is
abolished as a result of the requirement for high accuracy in a number of
tasks. Thus, calculating precisely the speed of ultrasonic wave is crucial.
Temperature is also a condition that affects the speed of sound 1. Heat, like
sound, is a form of kinetic energy. Molecules at higher temperatures have more
energy, thus they can vibrate faster. Since the molecules vibrate faster, sound
waves can travel more quickly. The speed of sound in room temperature air is
346 meters per second. This is faster than 331.3 meters per second, which is
the speed of sound in air at freezing temperatures. The formula to find the
speed of sound in air is as follows:


Where v is the speed of sound and T is the temperature of
the air. One thing to keep in mind is that this formula finds the average speed
of sound for any given temperature. The speed of sound is also affected by
other factors such as humidity and air pressure.

III. Principle

In this project, Arduino nano is chosen on account of its
favourableness, reasonable price, size as well as efficiency. Besides the
aforementioned features, Arduino is back up by Arduino IDE programming
environment that facilitates users and shortens the programming process.

Before measuring the distance,
ultrasonic speed value at a time must be defined. According to the
aforementioned theory, temperature value is worth considering due to the fact
that speed of ultrasound depends much more on this parameter. Measuring
environmental temperature requires DS18B20 digital thermometer which will be
inserted to the Arduino. The reason for the manipulation of this digital
thermometer in this project is its received value will be digit which
diminishes the loss of value during transmission and the appreciable errors
compared to other analog devices. For the purpose of saving time and energy,
Onewire library is used for 1-wire communication and Dallas Temperature library
to read the value taken from sensor 4. After initializing the object for
temperature measurement, the t_sensor in this case, will be activated by t_sensor.requestTemperatures() command.
Temperature values from sensor are read by:

float Temp = t_sensor.getTempCByIndex(0);

During the process, sensor performs
properly, its results are stable and the errors are acceptable ?T = 0.3oC.
With the obtained temperature value, the speed of ultrasound is computed basing
on the formula (1) which is precedently discussed.

float Speed = 331.3 + 0.6 * Temp;

From then, the critical
parameters for measuring method are all obtained. Next, ultrasonic sensor is
connected to Arduino’s two digital pins and supplied power. Ultrasonic sensor
includes 2 power pins, a trigger pins and an echo pin. Its trigger pin connects
to transmitter in order to emit ultrasonic wave, whereas, echo pin connects to
receiver to receive forward wave signal. Basing on this fundamental principle,
the time interval between emitting and receiving point is calculated. There is
pulseIn() function availably on Arduino that copes with the aforementioned
computation. This function returns the time points from when it is initially
referred to when echo receives the signal 3, 5. Firstly, the two pins of
sensor must be set up its mode:

                    pinMode(TRIG_PIN, OUTPUT);

                    pinMode(ECHO_PIN, INPUT);

Secondly, a pulse is sent to
Trigger which then emits ultrasonic waves:

digitalWrite(TRIG_PIN, HIGH);

Changing pin’s mode into LOW then
the time that ultrasonic wave travels from start point, collides the obstacles,
reverberates and returns to receivers is recorded and calculated:

long duration = pulseIn(ECHO_PIN, HIGH);

Fig. 5 Transmitting and receiving ultrasound process

Due to the fact that this
recorded time covers the entire length ultrasound travel, whereas the distance
from device to objective is a half of it, the recorded time must be divided
into halves:

float distance = Speed * (duration / 2);

The following flow chart
illustrates the overview of this process:



Fig. 6 Process overview

IV. Result Analysis

Table 4 Statistical result

Distance (cm)

Result (cm)

Error (%)































Average of Error




As can be seen, the error of 0.21% is inconsiderable and
acceptable. The recorded figures in the interval of measured distance have the
allowable errors from 30cm to 400cm. For the distance under 30cm, the error
becomes greater which partially results from the restricted capability of
Arduino. With such a short distance, time required for measurement is so small
that the capacity of microcontroller to store the variables is irresponsive.
Another factor causing this issue is the diffraction that happens when the
device is set at a short distance to the object. Ultrasonic sensor can not
access the distance above 400 cm. This depends on the decision of this sensor’s
manufacture. To expand the measurement interval for mass production, this project
needs the greater investment.


The total expense for this project is roughly $16 in
which the Arduino nano costs $5, ultrasonic sensor, temperature sensor, LCD
costs $6 and packaging costs $5 excluding the labour. It is a fact that the
significant decrease of price will result from the advent of mass productions.
As a result, the price of this device is much more reasonable compared with the
existing products on the market. For example, the price of Bosch device is
seven times as much as that of our product. The accomplished device performs
accurately and smoothly. Its upsides are being portable, reasonably-priced,
energy-saving and highly accurate. However, there are some obstacles in
measurement process such as the system is unstable, the
significant error when measuring out of the allowable range. These
inconveniences result from the sensor itself as listed by the manufacturers and
the limit of algorithm as well as formula. In the upcoming version, the device
will be designed and developed more carefully to achieve user’s higher reliance


1.      Eberhard
S, Calculation of the Speed of Sound in Air and the effective Temperature at http://www.sengpielaudio.com/calculator-speedsound.htm,
accessed November 10th 2017.

2.      Ultrasound
at https://en.wikipedia.org/wiki/Ultrasound,
accessed October 25th  2017.

3.      Ultrasonic
Sensor HC-SR04 and Arduino Tutorial at http://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/,
accessed Oct 5th

4.      How
to Use DS18B20 Temperature Sensor at http://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/,
accessed Oct 5th 2017

5.      PulseIn
at https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/,
accessed Oct 5th 2017


I'm Katy!

Would you like to get a custom essay? How about receiving a customized one?

Check it out