Documente Academic
Documente Profesional
Documente Cultură
By : Mohammed Sazzad(15302004)
Abstract
The purpose of project is to design and develop a distance measurement system using ultrasonic
waves(ultrasonic sensor HC-SR04) that interfaced with Arduino and a LCD screen that display
the readings of distance measured by ultrasonic sensor HC-SR04 ,along with a push button to
see the measured readings in different units (i.e.,Cm,inch) .We know that human audible range
is 20hz to 20khz. We can utilize these frequency range waves through ultrasonic sensor HC-
SR04.The advantages of this sensor when interfaced with Arduino which is a control and sensing
system, Arduino is a small microcontroller board with a USB plug to connect to the computer.
The Arduino board senses the environment by receiving input from ultrasonic sensor (HC-
SR04) and can affect its surroundings by controlling LCD display which provides the measured
readings, along with provided codes from the Arduino Basic Library in the Arduino coding
software (Arduino IDE 1.0.6). Have to modify the basic code to get almost accurate distance
measurement, converting the distance in different units. And push buttons to change units
(i.e.,Cm, inch) . In present work, I have measured small distances very precisely and Arduino
Programming functioned successfully for this system. It is used to detecting an obstacle, along
with its exact distance.
1
Table of contents
Abstract 1
Table of Contents 2
List of figures 3
List of Tables 4
Chapter 1 5
1.1 : Introduction 5
Chapter 2 6
3.1 : Ultrasonic-sensor(HC-SR04) 8
3.4 : Potentiometer 11
Chapter 4
4.1 : Methodology 12
4.2 : Results 14
2
Chapter 5
5.2 : References 16
3
List of Figures
4
List of Tables
5
Chapter 1
Introduction: Nowadays, we have some difficulties in obtaining the distance, length that we
want to measure. Even though, measuring tape, scale are easy option, but this kind of tool will
have a limitation of manual error, accuracy, precision. Before this, engineers have produced a
range finder module but in the end, they find out the module have many disadvantages like
limitation for distance, different result for different colored obstacles, and need a calibration for
every time before starts using it.
In our daily life we use rulers to measure length but we certainly face problems regarding
measurement errors. Precise and fix measurement of low range distance, is the main objective
for this project. In the project we have followed by the reference[1] and I have developed a
distance measurement device or system, which can measure distance or length using ultrasonic
sensors interfaced with Arduino conveniently and display them on LCD Screen, having the
results in different measuring units on the LCD display by pressing a push button. This distance
measuring device can measure distance in the range of 2cm to 400cm with the accuracy of 3mm .
This device is based upon the reflection of sound waves. Sound waves are defined as
longitudinal pressure waves in the medium in which they are travelling. Subjects whose
dimensions are larger than the wavelength of the impinging sound waves reflect them, the
reflected waves are called the echo. If the speed of sound in the medium is known and the time
taken for the sound waves to travel the distance from the source to the subject and back to the
source is measured, the distance from the source to the subject can be computed accurately.
6
Chapter 2
2.1 Project Background: Bats are wonderful creatures. Blind from the eyes but the vision is
sharper than humans, Ultrasonic ranging is the technique used by bats. Ultrasonic sensor
provides an easy way in distance measurement. The ultrasonic sensor (HC-SR04) is perfect for
distance measurements between moving or stationary objects. Ultrasonic Sensor measure the
distance of the objects in air through non-contact technique. They measure distance without
damage and are easy to use and reliable. These distance measurement sensors connect with all
common types of automation and telemetry equipment. Machinery and processes in a wide range
of industries use distance measurement sensors where size or position feedback is
required.Distance measurement sensors are used to control or indicate the position of objects and
materials. Distance measurement sensors can determine the dimensions of objects such as height,
width and diameter, using one or more sensors. The echo time response of ultrasonic sensor
detector is based on time of travel after trigger pulse to the surrounding objects is non-linear and
depends on the reflectance characteristics of the object surface. Ultra Sonic sensors are widely
used for distance measurement purposes. They offer low cost and a precision of less than 1 cm in
distance measurements of up to 6m [1, 4]. However, the most popular method used in these
measurements is based on the time of flight (ToF) measurement. This ToF is the time elapsed
between the emission and subsequent arrival after reflection of an Ultrasonic pulse train
travelling at the speed of sound. In this project, I have tried to devlop such a measurement
system which uses ultrasonic sensor. A sensor is a electrical transducer that converts one type
of energy to another (physical quantity into electrical signal). Ultrasound sensors are very
versatile in distance measurement. They are also providing the cheapest solutions. Ultrasound
waves are useful for both the air and underwater[3]. Ultrasonic sensors are also quite fast for
most of the common applications. Speed of sound in air is 340 m/s. An ultra-sound is a sound
wave which typically travels at speed of sound. A sonic sensor when triggered generates an
ultra-sound wave which will hit a solid barrier and reflect back to the ultra-sonic sensor. The
time is recorded starting from echoing to reception of the waves. The time taken is for twice
the distance travelled.
Using the formula
We get the uni-directional distance from sensor to object by using this fomula, a digital ruler
device can be designed with the power of micro controller and sensing capability of ultra-sonic
sensor. The circuit designed can be used to measure distances up to 4 meter with an accuracy of
3mm.
7
The Arduino Uno is a microcontroller board based on the ATmega328 (datasheet). It has 14
digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz
crystal oscillator, a USB connection, a power jack, an
ICSP header, and a reset button. It contains everything needed to support the microcontroller;
simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or
battery to get started[3]. The ultrasonic sensor emits an ultrasound at 40 000 Hz which travels
through the air and if there is an object or obstacle on its path It will bounce back to the module.
Considering the travel time and the speed of the sound the sensor measure the distance around
it[4]. The measured distance is calculated using Arduino controller within a predefined time
interval. The analog output read from the sensor module is transferred to LCD display through
serial port via Arduino and by pressing push button to have different measuring units. This
causes large response times for a single measurement.
Block diagram :
Personal
Arduino Uno computer or
Push buttons
9v battery
Atmega 328
Micro controller
8
Chapter 3
Experimental setup:
3.1 ULTRASONIC S ENSOR-SR04 :
a)
b)
Fig 3.1 a) Ultarspnic-sensor distance sensor module working principle
b) Ultrasonic-sensor (HC-SR04)
It emits an ultrasound at 40 000 Hz which travels through the air and if there is an object or
obstacle on its path It will bounce back to the module. Considering the travel time and the speed
Of the sound you can calculate the distance.An Ultrasonic Sensor have 4 pins, as we see in fig
3.1 the pins are VCC, Trig, Echo, GND. Ultrasonic Range Detection Sensor ,works by sending
an ultrasound pulse at around 40 KHz, It then waits and listens for the pulse to echo back,
calculating the time taken in microseconds. We can trigger a pulse as fast as 20 times a second
9
and it can determine objects up to 3 metres away and as near as 3cm. The snapshot of the sensor
and working process of the sensor is shown in fig 3.1The sensor needs a 5V power supply to run.
10
3.3 Arduino UNO Based on ATMega-328 Microcontroller:
11
3.4 Potentiometer :
Potentiometer is a device used to measure the internal resistance of a cell, to compare the e.m.f.
of two cells and potential difference across a resistor. It consists of a long wire of uniform
cross sectional area and of 10 m in length. The material of wire should have a high resistivity and
low temperature coefficient. The wires are stretched parallel to each other on a wooden
board. The wires are joined in series by using thick copper strips. A metre scale is also attached
on the wooden board. It works on the principle that when a constant current flows through a wire
of uniform cross sectional area, potential difference between its two points is directly
proportional to the length of the wire between the two points
12
Chapter 4
4.1 Methodology :
1. The ultrasonic sensor transmits ultrasound waves. Ultrasonic Sensor HC SR-04 has 4 pins.
VCC, GND, trig and echo. The VCC and GND are connected to the +5v and GND pins of
Arduino. The trig and echo pins to digital pins on Arduino.
2. 16x2 Lcd Display interfacing with Arduino pin diagrams
1 VSS GND
2 VDD 5V
4 RS 10
5 RW GND
6 E 9
11 DB4 Pin 5
12 DB5 Pin 4
13 DB6 Pin 3
14 DB7 Pin 2
15 Backlight LED +V 5V
Table 4.1: 16x2 Lcd Display interfacing with Arduino pin diagrams
13
Fig 4.1: Circuit diagram of Distance Measurement using Ultrasonic-sensor(HC-SR04)
14
Fig 4.2 : Schematic diagram Distance Measurement using Ultrasonic-sensor(HC-SR04)
3. The LCD display will need resistors for limiting current and potentiometers for
controlling the brightness and contrast of the LCD display
4. The signal from the sensor are fed in to Arduino pins
5. Arduino sends trigger signal of specific pulse width to the ultrasonic sensor.
6. Next it gets input from the ultrasonic sensor by the echo pin
7. The time between the sending and reception of signal is then multiplied with
constant speed of sound to give the distance
8. The Distance is halved to get the distance from sensor to the object.
9. The distance is coverted to inch and centimeter from miles using conversion
calculation and modifying the basic code in Arduino IDE 1.0.6
10. The measured value is then displayed on the LCD screen.
11. A push button is attached with a digital pin of Arduino which when pressed toggles
the mode between centimeter and inches reading on the LCD screen.
15
modifying the basic code in Arduino IDE 1.0.6, The measured value is then displayed on the LCD
screen.
16
Chapter 5
III. Acready compatible with many major simulation software like MATLAB & lab view,
we may see even move flexible programming environment & development option.
The importance of the project is calculating accurate distance from any obstacle that we want to
measure. The device can be used in many different fields and categories like distance calculation
in construction field, robots, car sensor to avoid obstacles and many other applications.
5.2 Reference:
1. https://circuitdigest.com/microcontroller-projects/arduino-ultrasonic-sensor-
based-distance-measurement (25-02-2018)
2. https://circuiteasy.com/distance-measurement-using-ultrasound/ (25-02-2018)
17
APPENDIX : c++ programming code for Arduino IDE 1.0.6
float pingTime; //time for ping to travel from sensor to target and return
float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees.
int toggleMode = 0;
int state;
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);
void loop() {
18
digitalWrite(trigPin, LOW); //Set trigger pin low
targetDistance= speedOfSound * pingTime; //This will be in miles, since speed of sound was miles per
hour
targetDistance=targetDistance/2; //Remember ping travels to target and back from target, so you must
divide by 2 for actual target distance.
//state = digitalRead(buttonPin);
//Serial.println(state);
printDistance();
delay(20);
state = digitalRead(buttonPin);
Serial.println(state);
if(state == 0){
if(toggleMode == 0){
toggleMode = 1;
19
}else if(toggleMode == 1){
toggleMode = 0;
void printDistance(){
if(toggleMode == 0){
delay(100);
20