You are on page 1of 32

Online Internship & Training Program Conducted By-

Name of the program - Embedded Systems & Internet of Things

Project Report On – Distance Measurement System

Date of Submission- 01.12.2021

Submitted by Submitted to
Amit Bar 1. Mr. Mayur Dev Sewak
ETCE,UG-III General Manager, Operations
Jadavpur University,Kolkata Eisystems Services
2. Mr. Krishnamohan Pandey
Trainer,ICT Domain,Logicpro Infosystems
Eisystems Services
CONTENTS
SL No. Heading Page No.

1 Notations 3

2 List of Figures 4

3 Abstract 5

4 Objectives 6

5 Project Summery 6

6 Introduction 7

7 Block diagram of Proposed System 7

8 Components Required 8

9 A. Hardware Description
9-20
Description of Hardware And Software
B. Software Description 21

10 Project Development A. Simulation Project 22-25

(Methodology --- Code , Circuit


Diagram/View ,Implementation) B. Practical Project 26-30

1 Application 30

12 Conclusion 31

13 Future Scope 31

14 References 32
Notations
RX : Reciever

TX : Transmitter

LCD : Liquid Crystal Display

ISP : In- System programming

SPI : Serial Peripheral Interface

TQFP : Thin Quad Flat Pack

QFN : Quad Flat with No lead packages

MLF : Micro Led Frame Packages

MIPS : Microproccessor without Internal Pipeline Stages

PDIP : Plastic Dual Inline Package

AVR : Automatic Voltage Regulator

RAM : Random Access Memory

EPROM : Electrically Erasable Programmable Read Only Memory

SONAR : Sound Navigation And Ranging

USART : Universa l Synchronous Asynchronous Reciever –Transmmitter

USB: Universal Serial Bus


List of Figures
Figure No. Figure Caption

Figure-2.1 Block Diagram of proposed System

Figure-3.1 View of all required components

Figure-4.A.1 Pin layout of ATmega 328

Figure-4.A.2 Arduino Uno Board

Figure-4.A.3 HC-SR04 Ultrasonic Sensor

Figure-4.A.4 HC-SR04 Ultrasonic Sensor with pin description

Figure-4.A.5 Working of HC-SR04 when no object is detected

Figure-4.A.6 Working of HC-SR04 when object is detected

Figure-4.A.7 Dimensions of the HC-SR04 Ultrasonic Distance Sensor as well as


the effective angle of operation.
Figure-4.A.8 Top View of 16*2 LCD Display ( i2c interface)

Figure-4.A.9 Back Side of 16*2 LCD Display ( i2c interface)

Figure -4.A.10 View of Bread Board

Figure-4.A.11 Jumpers Wires

Figure-4.B.1 Arduino IDE 1.8.13 Interface

Figure-5.A.1 Schematic diagram of simulated System/Circuit

Figure-5.A.2 Simulated System/Circuit at run condition

Figure- 5.B.1 Practical system/Circuit

Figure-5.B.2 Practical system at working


Abstract
Distance measurement of an object in the path of a person, equipment, or a vehicle, stationary or moving is
used in a large number of applications such as robotic movement control, vehicle control, blind man’s walking
stick, medical applications, etc. Measurement using ultrasonic sensors is one of the cheapest among various
options. In this project Distance Measurement System is made using ultrasonic transmitter, receiver and a
microcontroller is presented. This sensor can be easily interfaced with Arduino or NodeMCU or any other
microcontroller and requires only 8 to 10 line code to measure the distance through air.

Key Words -Distance Measurement , Ultrasonic Sensor, Arduino, Obstacle detection


Objectives
In this project I am going to design a distance measurement system using Arduino Uno and a Ultrasonic Sensor
HC SC-04.We will see how it can be implemented and how it will measure the distance . Here we will do the
simulation part on the tinkercad online platform and also do the practical implementation with hardwares. we
will display the measured distance by using a crystal display.

Project Summery
Here we will do the simulation part on the tinkercad online platform and also do the practical implementation
with hardwares to make a Distance Measurement System. We will write the program and accordingly we will
make the circuits connections and finally measured distance will be shown on the crystal display . Finally we
will see the various practical field where this project can be used.
1. Introduction
Distance measurement of an object in front or by the side of a moving entity is required in a large number of
devices. These devices may be small or large and also quite simple or complicated. Such distance measurement
systems are available. These use various kinds of sensors and systems. Low cost and accuracy as well as speed is
important in most of the applications. In this paper, we describe such a measurement system which uses
ultrasonic transmitter and receiver units mounted at a small distance between them and microcontroller based
system. This microcontroller is very easily available at low cost. A correlation is applied to minimize the error in
the measured distance. Ultrasound sensors are very versatile in distance measurement. They are also providing
the cheapest solutions. Ultrasound waves are useful for both the air and under-water . Ultrasonic sensors are
also quite fast for most of the common applications. In simpler system a low cost version of 8- bit
microcontroller can also be used in the system to lower the cost.

2. Block Diagram of the Proposed System

Power supply

Figure -2.1
3. Components Required
Sl No. Name Specification Quantity Price(Rs.)

1 Arduino Uno Board ATmega328 microcontroller 1 400

2 Ultrasonic Sensor HC-SR04 1 75

3 LCD Module 16*2 display / ic2 interface 1 300

4 Bread Board 5*17 cm2 1 70

5 Jumper wires Male to Male 8 20

Table-01 –Components Specifications

Figure-3.1
4. Description of Hardware And Software

A. Hardware Descpription

1. Arduino Uno Board

Introduction
Arduino refers to an open-source electronics platform or board and the software used to program it. An
Arduino board can be purchased preassembled or, because the hardware design is open source, built by hand .
A pre-assembled Arduino board includes a microcontroller, which is programmed using Arduino programming
language and the Arduino development environment. Arduino programming language is a simplified from of
C/C++ programming language based on what Arduino calls "sketches," which use basic programming
structures, variables and functions. These are then converted into a C++ program.

Hardware
Arduino is open-source hardware. Most Arduino boards consist of an Atmel 8-bit
AVR microcontroller (ATmega8, ATmega168, ATmega328, ATmega1280, ATmega2560) with varying amounts of
flash memory, pins, and features. We have arduino with ATmega 328.

ATmega328
The ATmega328 is a single-chip microcontroller created by Atmel in the megaAVR family.

Specification
The Atmel 8-bit AVR RISC-based microcontroller combines 32 kB ISP flash memory with read-while-write
capabilities, 1 kB EEPROM, 2 kB SRAM, 23 general purpose I/O lines, 32 general purpose working registers,
three flexible timer/counters with compare modes, internal and external interrupts, serial programmable
USART, a byte-oriented 2-wire serial interface, SPI serial port, 6-channel 10-bit A/D converter (8-channels
in TQFP and QFN/MLF packages), programmable watchdog timer with internal oscillator, and five software
selectable power saving modes. The device operates between 1.8-5.5 volts. The device achieves throughput
approaching 1 MIPS per MHz.
Key Parameters

Parameter Value

CPU type 8-bit AVR

Performance 20 MIPS at 20 MHz[2]

Flash memory 32 Kb

SRAM 2 kB

EEPROM 1 kB

Pin count 28-pin PDIP, MLF, 32-pin TQPF, MLF

Maximum operating 20 MHz


frequency

Number of touch channels 16

Hardware QTouch Acquisition No

Maximum I/O pins 23

External interrupts 2

USB Interface No

USB Speed –

Table-4.1 – Specification of ATmega 328


Features

 Microcontroller: ATmega328
 Operating Voltage: 5V
 Input Voltage (recommended): 7-12V
 Input Voltage (limits): 6-20V
 Digital I/O Pins: 14 (of which 6 provide PWM output)
 Analog Input Pins: 6
 DC Current per I/O Pin: 40 mA
 DC Current for 3.3V Pin: 50 mA
 Flash Memory: 32 KB of which 0.5 KB used by bootloader
 SRAM: 2 KB (ATmega328)
 EEPROM: 1 KB (ATmega328)
 Clock Speed: 16 MHz

Pin diagram

Figure-4.A.1
Figure-4.A.2

More Details About Arduino uno- Click

2. Ultrasonic Sensor(HC SR-04)

Introduction

The HC-SR04 Ultrasonic Distance Sensor is an inexpensive device that is very useful for robotics and test
equipment projects. This tiny sensor is capable of measuring the distance between itself and the nearest solid
object. An ultrasonic sensor is a device that is generally used to measures the distance to an object and object
detection using ultrasonic sound waves. The sensor head transmits an ultrasonic wave and receives the wave
reflected from the object. Ultrasonic Sensors measure the distance to the object by calculating the time
between the transmission and reception.

Distance= (Time x Speed of Sound in Air (340 m/s))/2

The HC-SR04 can be hooked directly to an Arduino or other microcontroller and it operates on 5 volts.
This ultrasonic distance sensor is capable of measuring distances between 2 cm to 400 cm. It’s a low current
device so it’s suitable for battery powered devices. This device is widely used in SONAR systems.
Working

Ultrasonic distance sensors use pulses of ultrasonic sound (sound above the range of human hearing) to
detect the distance between them and nearby solid objects. The sensors consist of two main components:
 An Ultrasonic Transmitter – This transmits the ultrasonic sound pulses, it operates at 40 KHz
 An Ultrasonic Receiver – The receiver listens for the transmitted pulses. If it receives them it produces an
output pulse whose width can be used to determine the distance the pulse travelled.
The HC-SR04 has the following four connections:
 VCC – This is the 5 Volt positive power supply.
 Trig – This is the “Trigger” pin, the one driven to send the ultrasonic pulses.
 Echo – This is the pin that produces a pulse when the reflected signal is received. The length of the pulse is
proportional to the time it took for the transmitted signal to be detected.
 GND – This is the Ground pin.

Figure-4.A.3
Figure-4.A.4

The device operates as follows:

i. A 5 volt pulse of at least 10 uS (10 microseconds) in duration is applied to the Trigger pin.
ii. The HC-SR04 responds by transmitting a burst of eight pulses at 40 KHz. This 8-pulse pattern makes
the “ultrasonic signature” from the device unique, allowing the receiver to discriminate between
the transmitted pattern and the ultrasonic background noise.
iii. The eight ultrasonic pulses travel through the air away from the transmitter. Meanwhile the Echo
pin goes high to start forming the beginning of the echo-back signal.
iv. If the pulse in NOT reflected back then the Echo signal will timeout after 38 mS (38 milliseconds)
and return low. This produces a 38 mS pulse that indicates no obstruction within the range of the
sensor.
v. If the pulse IS reflected back the Echo pin goes low when the signal is received. This produces a pulse
whose width varies between 150 uS to 25 mS, depending upon the time it took for the signal to be
received.
vi. The width of the received pulse is used to calculate the distance to the reflected object. Remember
that the pulse indicates the time it took for the signal to be sent out and reflected back so to get
the distance you’ll need to divide your result in half.
Figure-4.A.5

Figure-4.A.6
The illustration below shows the dimensions of the HC-SR04 Ultrasonic Distance Sensor as well as the
effective angle of operation. As you can see the sensor is most accurate when the object to be detected
is directly in front of it but you do get a response from objects within a 45 degree “window”. The
documentation recommends confining that window to 30 degrees (15 degrees on either side) for
accurate readings.

Figure-4.A.7
More details about HC SR04- Click

3. LCD Module
Figure-4.A.8 Top View

The I2C 16×2 Arduino LCD Screen is using an I2C communication interface. It is able to display 16×2 characters
on 2 lines, white characters on blue background.This display overcomes the drawback of LCD 1602 Parallel LCD
Display in which you’ll waste about 8 Pins on your Arduino for the display to get working. Luckily in this product,
an I2C adapter is directly soldered right onto the pins of the display. So all you need to connect are the I2C pins,
which shows a good library and little of coding.

The I2C is a type of serial bus developed by Philips, which uses two bidirectional lines, called SDA (Serial Data
Line) and SCL (Serial Clock Line). Both must be connected via pulled-up resistors. The usage voltages are
standard as 5V and 3.3V.If you already have the I2C adapter soldered onto the board like in this product, the
wiring is quite easy. You should usually have only four pins to hook up. VCC and GND of course. The LCD display
works with 5 Volts. So we go for the 5V Pin.

Figure-4.A.9 Back Side

The values shown on the display can be either a simple text or numerical values read by the sensors, such as
temperature or pressure, or even the number of cycles that the Arduino is performing.
4 pins for the LCD display:
PIN DETAILS:-
1. VCC,
2. GND,
3. SDA,
4. SCL.

It will saves at least 4 digital / analog pins on Arduino. Usually, Arduino LCD display projects will run out of pin
resources easily, especially with Arduino Uno. And it is also very complicated with the wire soldering and
connection.

SPECIFICATION AND FUTURES:-


1.Compatible with Arduino/Genuino UNO, Mega, Micro, Nano, Mini
2. I2C Address: 0x20-0x27(0x20 default)
3. Back lit (Blue with white char color)
4. Supply voltage: 5V
5. Interface: I2C/TWI x1,Gadgeteer interface x2
6. Adjustable contrast
7. Size: 82 x 35 x 18 mm (3.2×1.4×0.7 in)
8. White text on the Blue background
9. Interface Address: 0x27
10. Character Color: White
11. Backlight: Blue
12. Supply voltage: 5V.

For more details about LCD(ic2 interface)- Click


4. Bread Board

Basically It is a testing board for electronic circuits. Widely use in colleges,laboratory and may industry related to
electronic products.

Figure -4.A.10

 840 Tie Point Solderless Breadboard


 A breadboard is used to make up temporary circuits for testing or to try out an idea
 Jumper wires are easy to insert into or remove from these breadboards
 Perfect for proto-typing circuit, electronic and electrical experiments without soldering.
 The solderless breadboards do not require soldering, therefore they are completely re-usable

5. Jumper wires

This is a set of 10 rainbow color male to male jumper wires. They can be used for interconnecting electronic
components on breadboard or berg strips. The wires are 20 cm long. Both the side of the wire has male
pins. The color of all four wires will be different but the exact color might vary from that of the
picture. These male to male jumper wires are of good quality, reusable and has an approximate length of 20cm.

Specifications of Male to Female Connecting Wires

 1 x 20cm male to female breadboard connecting wires

 Easy to plug in

 Durable, Flexible

 Multiple Colours

 Jumper wire size : 26 AWG


 Current Rating : up to 1 A
 Insulation Type: PVC

Figure -4.A.11
B. SOFTWARE DESCRIPTION

Arduino IDE

Introduction
Arduino consists of both a physical programmable circuit board (often referred to as a microcontroller) and a
piece of software, or IDE (Integrated Development Environment) that runs on your computer, used to write and
upload computer code to the physical board.

Programming Language used

First, the Arduino compiler/IDE accepts C and C++ as-is. In fact many of the libraries are written in C++. Much of
the underlying system is not object oriented, but it could be. Thus, "The arduino language" is C++ or C.

Getting started with Arduino ide

Figure-4.B.1

1. Open arduino 1.8.13


2. Go to file menu and select new page.
3. Write program.
4. Compile
5. Upload program to arduino.
5. Project Development

A. Simulation Project-

First the code is written for this project and then the circuit connection is made accordingly on Tinkercad
online simulation platform.

Methodology-

 Simulated Code

*/

#include <LiquidCrystal.h> // includes the LiquidCrystal Library

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)

const int trigPin = 9;

const int echoPin = 10;

long duration;

int distanceCm, distanceInch;

void setup() {

lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of
the display

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

}
void loop() {

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distanceCm= duration*0.034/2;

distanceInch = duration*0.0133/2;

lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed

lcd.print("Distance: "); // Prints string "Distance" on the LCD

lcd.print(distanceCm); // Prints the distance value from the sensor

lcd.print(" cm");

delay(10);

lcd.setCursor(0,1);

lcd.print("Distance: ");

lcd.print(distanceInch);

lcd.print(" inch");

delay(10);

}
 Schematic Diagram

Figure-5.A.1 -- Simulated System

Simulated Circuit in Tinkarcad

Name Quantity Component


U1 1 Arduino Uno R3
U2 1 LCD 16 x 2
R1 1 1 kΩ Resistor
DIST1 1 Ultrasonic Distance Sensor

 Implementation

 Now for the simulation part first we take a wire and connect it with 5V pin and connect the other end
to the positive rail of breadboard.
 Next we take another wire and connect it to the ‘GND’ pin of Arduino and we connect the other port to
negative rail of the breadboard.
 After that we connect ‘Vcc’ and ‘GND’ pin of both ultrasonic sensor and display module to the positive
and negative rail of the breadboard respectively.
 Next we connect the trigger pin of ultrasonic sensor to ‘pin 9’ of Arduino board and we connect the
echo pin of ultrasonic sensor pin of ultrasonic sensor to ‘pin 10’ of Arduino board. And hence the
connection of Arduino is completed.
 Next we write the code under CODE section on the tinkercad simulator and run it over this platform.
 We find the measured distance on the LCD display in cm as well as in inch. .
 After Simulation

Figure-5.A.2 – Simulated System at run Condition

*To see Simulated Project on Tinkercad please CLICK HERE .

*To see the video (Full process ) please Click Here .


B. Practical Project

First the code is written for this project on the Arduino ide and then the circuit connection is made accordingly
on the bread board .Then connect the power cable with arduino and then run the program.

Methodology-
 Code written on Arduino IDE

#include <Wire.h> // Library for I2C communication

#include <LiquidCrystal_I2C.h> // Library for LCD

LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x3F, 16, 2); // Change to (0x27,16,2) for 16x2 LCD.my address is (0x3F)

int trigPin = A0;

int echoPin = A1;

long distance;

long distanceInch;

long duration;

void setup(){

lcd.init();

lcd.backlight();
pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

lcd.setCursor(0,0);

lcd.setCursor(0,1);

delay(2000);

void loop() {

ULTRASONIC();

lcd.clear();

lcd.setCursor(0,0);

lcd.print("DISTANCE CM:");

lcd.print(distance);

lcd.setCursor(0,1);

lcd.print("DISTANCE INCH:");

lcd.print(distanceInch);

// lcd.setCursor(0,1);

// lcd.print("DISTANCE MM:");

// lcd.print(distanceInch);

}
void ULTRASONIC(){

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = duration*0.034/2;

distanceInch = duration*0.0133/2;

 Practical Proposed System

Figure- 5.B.1--practical system


 Implementation

 Now for the practical hardware part first we take a male to male jumper wire and connect it with 5V pin
and connect the other end to the positive rail of breadboard.
 Next we take another male to male jumper wire and connect it to the ‘GND’ pin of Arduino and we
connect the other port to negative rail of the breadboard.
 After that we connect ‘Vcc’ and ‘GND’ pin of both ultrasonic sensor and display module to the positive
and negative rail of the breadboard respectively.
 Next we connect the trigger pin of ultrasonic sensor to ‘pin A0’ of Arduino board and we connect the
echo pin of ultrasonic sensor pin of ultrasonic sensor to ‘pin A1’ of Arduino board. And hence the
connection of Arduino is completed.
 Next we write the code on Arduino IDE and burn it to the Arduino board.
 Then we supply power to the Arduino via cable and run the program .
 Now we can see the measured distance (on the LCD display ) of the object with respect to the
ultrasonic sensor.
Figure-5.B.2 -- practical system at working

*To See the video (full process of the project) please Click Here .

6. Application
 Driverless car
 Robotics
 In radar
 To measure the level of fuel in the aircraft fuel tank
7. Conclusion
The objective of this project was to design and implement an distance measurement sytem(/device) (using
ultrasonic sensor & Arduino). By using the system we can calculate the distance of the object. The following can
be concluded from the above project-:

 The system can calculate the distance of the object without errors.
 The system provide low cost and efficient solution.

8. Future Scope
 We can use humidity sensors in future to measure distance in different environment.
 Using ultrasonic sensor with better specification we can increase the distance measurement
range.
 This system is used in driverless car to detect obstacle.
 This system with some buzzer can be used in navigation System for blind people to detect the
obstacle.
10. References
1. Arduino programming – Richard Bloom

2. Arduino robotics – John David Warner

3. Ultrasonic sensor and technology – Stefan Cokis

4. Website link- Click

Download i2c lcd library at this link:- Click

Download Arduino IDE at this link - Click

Download wire library at this link- Click

You might also like