OBSTACLE the guidance of Dr.SAIKAT MAJUMDER (Assistant Professor)


A major project report submitted in partial fulfillment of the requirement for
the award of degree

With specialization



SUMAN TANDAV (14116080)

Under the guidance of

(Assistant Professor)

Department of Electronics and Telecommunications

National Institute of Technology

Raipur-492010, Chhattisgarh

(Jan-May 2018)



This is to certify that the Major Project work entitled “OBSTACLE DETECTION USING HC-SR04 ULTRASONIC SENSOR” is the bona-fide work done by Shivani Nuruti (14116075), Suman Tandav (14116080) under our guidance and supervision. This report is submitted following the completion of major project during the academic session of Jan-May 2018.

Head of the Department
Dr. Ajay Singh Raghuvanshi Dr. Saikat Majumder
Asst. Professor and Head Asst.Professor
Department of E & TC Department of E & TC
NIT Raipur



This is to certify that the Major Project work entitled “OBSTACLE DETECTION USING HC-SR04 ULTRASONIC SENSOR” is the bona-fide work done by Shivani Nuruti (14116075), Suman Tandav (14116080). They have successfully completed above mentioned project as a part of major project during academic session of Jan-May 2018.

Examiner 1

Examiner 2
Name: Name:
Date: Date:



Every project big or small is successful largely due to the effort of a number of wonderful people who have always given their valuable advice or lent a helping hand. We sincerely appreciate the inspiration, support and guidance of all those people who have been instrumental in making this project a success. We are highly indebted to our guide Dr.S.Majumder whose contribution in stimulating suggestions and encouragement helped us to coordinate this project.

We would also like to convey my gratitude to Dr. Ajay Singh Raghuwanshi (Head, Department Electronics & Telecommunication), for providing us the possibility to complete this project. We are highly thankful to the authors whose work we have consulted and quoted in this work. Finally we acknowledge the constant inspiration, encouragement and good wishes to all the colleagues for their cooperation and enlightened views at every stage of our work to complete this in time.

SUMAN TANDAV (14116080)



1. Introduction ……………………………………………………………………….. 6
1.1 Definition
1.2 Motivation
1.3 working
1.4 how to use HC-SR04 ultrasonic sensor
1.5 Performance factors
2. Literature survey………………………………………………………………… 8
3. Theory……………………………………………………………………………… 9
4.System description…………………………………………………………………. 10
5.Software description………………………………………………………………. 14
6. Connections………………………………………………………………………. 16
6.1 Procedure
6.2 Circuit diagram
6.3 Code
7. Application………………………………………………………………………… 23
8 . Result……………………………………………………………………………….. 24
9. Conclusion………………………………………………………………………….. 25
References…………………………………………………………………………… 26

Ultrasonic transducers is a device it is also known as ultrasonic sensors and it is a type of acoustic sensor divided into mainly three parts: transmitters, transceivers and receivers. Transmitters is a device which is used to convert electrical signals into ultrasound, on the other way receivers is also used to convert ultrasound into electrical signals, and transceivers can be use for both transmit and receive ultrasound.
It is same as radar and sonar, ultrasonic transducers are used in systems which evaluate targets by interpreting the reflected signals. For e.g. it is used to measure the time between sending a signal and receiving an echo the distance of an object can be calculated. ultrasonic sensors are basically a type of microphones that is use to detect ultrasonic noise that is present under certain conditions.

The ultrasonic sensor is mounted on a micro servo in order to have a sweeping perspective. The device is use for talk and announce basis status message and object detection events. Further more disadvantages users have no other way to control these devices a parts from costly centralized device. We were able to developed a system having most of the functionalities of existing home automation products.
1.3 HC-SR04 Ultrasonic Sensor – Working
The HC-SR04 Ultrasonic sensor is a 4 pin module, whose pin names are as follows Vcc, Trigger, Echo and Ground respectively. The HC-SR04 Ultrasonic sensor is a very popular sensor and used in many applications which is used where measuring distance or sensing objects are required. The module has two eyes in the front of the sensor which forms the Ultrasonic transmitter and ultrasonic Receiver. The sensor works with the simple formula are as follows:
Distance = Speed × Time
The Ultrasonic transmitter is a device that is use to transmits an ultrasonic wave, the wave generated by this travels in air and when a object is detected by any material it gets reflected back toward the sensor and the reflected wave is observed by the Ultrasonic receiver .
Now, to calculate the distance by using the above formula, we should know the Speed and time. when we are using the Ultrasonic wave we know about the universal speed of ultrasonic sensor wave at room conditions which is about 330m/s. The circuitry inbuilt on the module will calculate the time taken for the ultrasonic sensor wave to come back and turns on the echo pin high for that same particular amount of time, this way we can also know about the time taken by the sensor. Now we can calculate the distance using a microcontroller or microprocessor.
1.4 How to use the HC-SR04 Ultrasonic Sensor
HC-SR04 distance sensor is commonly used in both microcontroller and microprocessor platforms like ARM, PIC, Raspberry Pie, arduino etc. The following guide is universally since it has to be followed by the type of computational device used.
Power regulated in this sensor is +5V through the Vcc and Ground pins of the sensor. The current consumed by this sensor is less than 15mA and hence can be directly powered by the on board 5V pins . The Trigger pin and the Echo pin are both known as I/O pins and they are connected to I/O pins of the microcontroller. To start the measurement by using HC-SR04, the trigger pin has to be made high for 10uS and then turned off. This action will trigger an ultrasonic wave at frequency of 40Hz from the transmitter and the receiver will wait for the wave to return back. Once the wave is returned back after it get reflected by any object the Echo pin goes high for a particular amount of time which will be equal to the time taken for the wave to return back to the sensor.
The amount of time taken by the sensor during which the Echo pin stays high is measured by the MCU or MPU and it gives the information about the time taken for the wave to return back to the Sensor.
Ultrasound can be used for measuring wind speed , channel fluid level, and speed through air or water. For measuring direction, a device uses multiple detectors and calculates the speed from the relative distances to particulates in the air or in water. To measure tank or channel liquid level, the sensor measures the distance to the surface of the fluid.
Other applications include: non-destructive testing and wireless charging. This technology, as well, can detect approaching objects and track their positions.
System use a transducer which generates sound waves in the ultrasonic range, above 18 kHz, by converting the electrical energy into sound, then receiving the echo that turn the sound waves into electrical energy which can be measured by the sensor.
This technology is limited by the shapes of the surfaces and the density or the consistency of the material. Foam, in particular, can distort surface level readings.


Obstacle detecting sensors are one of the most basic type of sensors that use in many electronic devices. There are different methods to make cheap obstacle sensors. These simplest sensors are made by using a IR Rx/Tx pair or Normal LED and LDR pair(this design is most basic and is heavily affected by environment lighting conditions). These sensor may be useful for simple requirement but they have following drawbacks :
1. Can not say anything about the real distance of obstacle.
2. Give different types of result for different coloured obstacles.
3. Require calibration (like setting up a variable resistor).
To solve these type of problems initially IR Range Finder Modules(like one made by Sharp) were used but they have small range.
1. Sharp GP2D12 Distance Measurement Sensor has a maximum range of 80cm
2. Sharp GP2D120 Distance Measurement Sensor has a maximum range of 30cm only.
To solve all these tyoe of problem we can use an Ultrasonic Range Finder Module. An Ultrasonic Range Finder Module uses ultrasonic waves to measure distance. These module consist of an Ultrasonic Transmitter that emits the ultrasonic wave, the waves after striking any obstacle bounces back and reach the Ultrasonic Receiver. By measuring the time it take by the process to complete and using simple arithmetic we can measure the distance to the obstacle.
These specifications makes it ideal for distance measurement application. These can be used
1. Speed check in roads.
2. Handheld units that can be pointed on vehicles to measure their speed.
3. Fixed unit installed in check booths that can click pictures of over speeding vehicles.
4. Contact less measurement of liquid level in tanks (even 4m deep tank).
5. Radars for robot.
6. Obstacle sensing in Robotics.
Distance measurement of an object in front of a moving entity or by the side of a moving entity is required in a large number of devices. These devices may be large or small and also complicated or quiet simple. Such distance measurement systems are available. These use various kinds of sensors and systems. Speed and low cost as well as accuracy is important in most of the applications.
In this project, we have implemented such a measurement system in which uses ultrasonic sensor unit and a ATmega32 microcontroller based system. This type of microcontroller is 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 euipment. They are also providing the cheapest solutions to the equipment. Ultra- sound waves are useful for the air as well as underwater. 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.
The current methods of blockage detection are based on inspection through CCD camera based equipments and manual visual inspection. In such type of systems first pictures of obstacle can be obtained and then they are observed and analyzed. The main limitation of these systems are that they cannot tell you the exact location of the obstacle.



• Breadboard
It is a construction base for prototyping of electronics. Originally it is a type bread board,a polished piece of wood used for slicing bread. In the 1970s the solderless breadboard also known as (AKA plugboard, a terminal array board) became available and nowadays the term “breadboard” is commonly used to refer to these.
Because the solderless breadboard does not require any type of soldering, it is reusable. Solderless breadboard makes it easy to use for experimenting with circuit design and creating temporary prototypes. For this reason, solderless breadboards are also extremely popular in technological education and with students. Older type of breadboard does not have this property.
A similar prototyping printed circuit boards and stripboard (Veroboard) , which are used to build one-offs or semi-permanent soldered prototypes, cannot easily be reused. A variety of the electronic systems may be prototyped by using breadboards, from small digital and analog circuits to complete central processing units (CPUs).

Fig 2. Breadboard

• Jump wires
Jump wires are also called jumper wires for solderless breadboarding can be manually manufactured or can be obtained in ready-to-use jump wire set. The latter can become too long work for larger circuits. Ready-to-use jump wires come in different qualities, some even with tiny plugs attached to the wire ends. Jump wire material for homemade wires or ready-made should usually be 22 AWG (0.33 mm2) solid copper, tin-plated wire – assuming no tiny plugs are to be attached to the wire ends. The wire ends should be stripped in (4.8 to 7.9 mm). Shorter stripped wires might result in bad contact with the board’s spring clips (insulation being caught in the springs). Longer stripped wires increase the short-circuits on the board. Tweezers and needle-nose pliers are helpful when they are inserting or removing wires, particularly on crowded boards.
Differently types of colored wires and color-coding discipline are often adhered to for consistency. However, the number of available colors is typically far fewer than the number of signal types or paths. Typically, a few wire colors are reserved and are used for the supply voltages and ground (e.g., red, blue, black), some are reserved for main signals, and the rest are simply used where convenient. Some ready-to-use jump wire sets use the color to indicate the length of the wires, but these sets do not allow a meaningful color-coding scheme.

• Ultrasonic HC-SR04
An Ultrasonic sensor HC-SR04 is a device that is use to measure the distance to an object by using sound waves. It measures distance by sending out a sound wave at a specific frequency and listening for that sound wave to bounce back. By recording the time elapsed between the generated sound wave and the sound wave bouncing back, now it is make possible to calculate the distance between the sonar sensor and the object.

Fig 3. Ultrasonic sensor

• Leds
A light-emitting diode is also known as (LED) is a two-lead semiconductor light source. It is a type of a p–n junction diode that emits light when activated. When a voltage is applied to the leads, electrons starts to recombine with electron holes present within the device, it start releases the energy in the form of photons. This effect is called electroluminescence, and the color of the light (corresponding to the energy of the photon) is determined by the energy band gap of the semiconductor. LEDs are small and integrated optical components may be used to give the shape to radiation pattern.

• Servo moter
A servomotor is a type of closed-loop servomechanism that uses position feedback to control its final position. The input to its control is a signal either analog or digital representing the position commanded for the output shaft.
The servo motor is paired with some type of encoder to provide speed feedback and position. In the simplest case,only the position is measured. The measured output position is compared to the command position, the external input to the controller. If the output position different from that required position, an error signal is generated which then causes the motor to rotate in either direction, as needed to bring the output shaft to the appropriate position. As the positions observed, the error signal reduces to zero and the motor stops.
The simplest servomotors use position-only sensing via a bang-bang control of their motor and potentiometer; the motor always rotates at full speed. This type of servomotor is not used in industrial motion control, but servo motor forms the basis of the simple and cheap servos and used for radio-controlled models.

Fig 4. servo motor

• Resistor
A resistor is a passive two-terminal electrical component which use to implements electrical resistance as a circuit element. In electronic circuits, resistors is a component are used to reduce current flow, to divide voltages, adjust signal levels, bias active elements, and terminate transmission lines, among other uses. High-power resistors that can dissipate many watts of electrical power as heat may be used as part of motor controls, in power distribution systems, or as test loads for generators. Fixed resistors have resistances that only change slightly with time, temperature or operating voltage. Variable resistors are the resisters that can be used to adjust circuit elements (such as a volume control or a lamp dimmer), or as force, or chemical activity, sensing devices for heat, light, humidity.

• Arduino Uno board
Microcontroller ATmega328 having a Operating Voltage of 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 (ATmega328) of which 0.5 KB used by bootloader SRAM 2 KB (ATmega328) EEPROM 1 KB (ATmega328) Clock Speed 16 MHz

Fig 5. Arduino board

The Arduino Web Editor is one of the most common Arduino Create platform’s tools. The open-source Arduino Software makes it easy to write a code in the software and upload it to the arduino board. The environment is written in Java and they are based on Processing and other type of open-source software. This software can be used with different Arduino board.
The arduino Uno is programmed using the Arduino Software , our Integrated Development Environment referred as common to all our boards. The USB connection with the PC is necessary to upload the program to arduino board and not just for power it up. The arduino Uno automatically draw power from either the USB cable or from an external power supply. Connect the arduino board to your computer using the USB cable.
A program for Arduino that can be written in any programming language by using compilers that produce binary machine code for the target processor. Atmel provides a development environment for microcontrollers, AVR Studio and the newer Atmel Studio.
The Arduino project provides the Arduino integrated development environment , which is a type of cross-platform application written in the programming language Java. It is originated from the integrated development environment for the languages processing and wiring. It includes a code editor with features such as, searching and replacing text, text cutting and pasting, automatic indenting and syntax highlighting, and provides simple one click mechanisms to compile and upload programs to an Arduino board. It also contains a message area, a text console, a toolbar with buttons for common functions.
A program that is written with the integrated Development Environment for Arduino is called a sketch. And sketches are used to save on the development computer as text files. Arduino Software (IDE) pre-1.0 saved sketches with the extension .
The Arduino Integrated Development Environment supports the languages like C and C++ using special rules of code. The Arduino integrated Development Environment supplies a software library from the Wiring project, which provides many common input and common output procedures. User-written code requires only two basic functions, for starting the sketch and the main program loop, that are compiled and linked with a program stub main() into an executable cyclic executive program with the GNU tool chain, also included with the IDE distribution. The Arduino IDE employs the program avrdude to convert the executable code into a text file in a form of hexadecimal encoding and that is loaded into the Arduino board by the help of loader program in the board’s firmware.


Processing is an open-source computer programming language and integrated development environment also referred as IDE it is use to built for the electronic arts, new media art, with the purpose of teaching non-programmers the fundamentals of computer programming in a visual context. The Processing language are builds on the Java language, but uses a simple syntax and a graphics user interface.
The project was initiated in 2001 by Casey Reas and Ben Fry, both formerly of the Aesthetics and Computation Group at the MIT Media Lab. In 2012, they started the Processing Foundation along with Daniel Shiffman, who joined as a third project lead. Johanna Hedva joined the Foundation in 2014 as Director of Advocacy.
Processing software includes a sketchbook, a alternative to an integrated development environment (IDE) for organizing projects.
Every Processing sketch is a type of subclass of the Java class (formerly a subclass of Java’s built-in Applet) and which is use to implements most of the Processing language’s features.
When programming in Processing, before compiling all additional classes defined will be treated as inner classes when the code is translated into pure Java. This means that the use of static variables and methods in classes is prohibited unless. Processing is explicitly told to code the program in pure Java mode.
Processing also allows the users to create their own classes within the Papplet sketch. This allows for complex data types that can include any number of arguments and avoids the limitations of solely using standard data types such as: int (integer), char (character), float (real number), and color (RGB, RGBA, hex).
Processing is an open-source computer programming language and integrated development environment also referred as (IDE) it is use to built for the electronic arts, new media art, and visual design communities with the purpose of teaching non-programmers the fundamentals of computer programming in a visual context. The Processing language are builds on the Java language, but uses a simplified syntax and a graphics user interface.


6.1 Procedure
1. VCC connection of the sensor attached to +5V
2. GND connection of the sensor attached to ground
3. TRIG connection of the sensor attached to digital pin 10
4. ECHO connection of the sensor attached to digital pin 11
5. The servo motor to the pin number 12 on the Arduino Board.

6.2 Circuit diagram

Fig 6. Circuit diagram

6.3 code

// Includes the Servo library
#include .
// Defines Tirg and Echo pins of the Ultrasonic Sensor
const int trigPin = 10;
const int echoPin = 11;
// Variables for the duration and the distance
long duration;
int distance;
Servo myServo; // Creates a servo object for controlling the servo motor
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
myServo.attach(12); // Defines on which pin is the servo motor attached
void loop() {
// rotates the servo motor from 15 to 165 degrees
for(int i=15;i15;i–){
distance = calculateDistance();
// Function for calculating the distance measured by the Ultrasonic sensor
int calculateDistance(){

digitalWrite(trigPin, LOW);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance= duration*0.034/2;
return distance;

2. Processing code
import processing.serial.*; // imports library for serial communication
import java.awt.event.KeyEvent; // imports library for reading the data from the serial port
import java.io.IOException;
Serial myPort; // defines Object Serial
// defubes variables
String angle=””;
String distance=””;
String data=””;
String noObject;
float pixsDistance;
int iAngle, iDistance;
int index1=0;
int index2=0;
PFont orcFont;
void setup() {

size (1200, 700); // ***CHANGE THIS TO YOUR SCREEN RESOLUTION***
myPort = new Serial(this,”COM5″, 9600); // starts the serial communication
myPort.bufferUntil(‘.’); // reads the data from the serial port up to the character ‘.’. So actually it reads this: angle,distance.
void draw() {

// simulating motion blur and slow fade of the moving line
rect(0, 0, width, height-height*0.065);

fill(98,245,31); // green color
// calls the functions for drawing the radar
void serialEvent (Serial myPort) { // starts reading data from the Serial Port
// reads the data from the Serial Port up to the character ‘.’ and puts it into the String variable “data”.
data = myPort.readStringUntil(‘.’);
data = data.substring(0,data.length()-1);

index1 = data.indexOf(“,”); // find the character ‘,’ and puts it into the variable “index1”
angle= data.substring(0, index1); // read the data from position “0” to position of the variable index1 or thats the value of the angle the Arduino Board sent into the Serial Port
distance= data.substring(index1+1, data.length()); // read the data from position “index1” to the end of the data pr thats the value of the distance

// converts the String variables into Integer
iAngle = int(angle);
iDistance = int(distance);
void drawRadar() {
translate(width/2,height-height*0.074); // moves the starting coordinats to new location
// draws the arc lines
// draws the angle lines
void drawObject() {
translate(width/2,height-height*0.074); // moves the starting coordinats to new location
stroke(255,10,10); // red color
pixsDistance = iDistance*((height-height*0.1666)*0.025); // covers the distance from the sensor from cm to pixels
// limiting the range to 40 cms
if(iDistance40) {
noObject = “Out of Range”;
else {
noObject = “In Range”;
rect(0, height-height*0.0648, width, height);

text(“Indian Lifehacker “, width-width*0.875, height-height*0.0277);
text(“Angle: ” + iAngle +” °”, width-width*0.48, height-height*0.0277);
text(“Distance: “, width-width*0.26, height-height*0.0277);


I'm Mary!

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

Check it out