Obstacle Avoiding Robot Using Ultrasonic Sensor

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

OBSTACLE AVOIDING ROBOT USING

ULTRASONIC SENSOR

By:
G.ANIL KUMAR

IN ASSOSCIATION WITH

CST SERVICES

1
OBSTACLE AVOIDING ROBOT USING ULTRASONIC
SENSOR

Aim: Build an Obstacle avoiding robot using Arduino and Ultrasonic Sensor.

Introduction:

Obstacle Avoiding Robot is an intelligent device which can automatically sense the
obstacle in front of it and avoid them by turning itself in another direction. This design allows the
robot to navigate in unknown environment by avoiding collisions, which is a primary
requirement for any autonomous mobile robot.

The application of Obstacle Avoiding robot is not limited and it is used in most of the
military organization now which helps carry out many risky jobs that cannot be done by any
soldiers.

Components Required:

 Arduino UNO
 Ultrasonic Sensor Module HC-SR04
 ROBOT Chassis complete with screw
 DC Motors
 L293D IC
 Wheels
 Bread Board
 Connecting wires
 Power supply or Power bank

Arduino UNO:

Arduino is an open-source micro-controller device. It is an educational development


board which is mainly used for developing different kind of projects which is equipped with
digital and analog pins.

It can be powered by using a power cable or by external 9v battery. For developing


different projects using Arduino UNO board we use software called “Arduino”.

2
Arduino UNO

Ultrasonic Sensor:

An Ultrasonic sensor is used to sense the obstacles in the path by calculating the distance
between the robot and obstacle. If robot finds any obstacle it changes the direction and continues
moving.

How Ultrasonic Sensor can be used to Avoid Obstacles:

Before going to build the robot, it is important to understand how the ultrasonic sensor
works because this sensor will have important role in detecting obstacle.

The basic principle behind the working of ultrasonic sensor is to note down the time
taken by sensor to transmit ultrasonic beams and receiving the ultrasonic beams after hitting the
surface. Then further the distance is calculated using the formula. In this project, the widely
available HC-SR04 Ultrasonic Sensor is used.

Ultra sonic sensor

3
So, the Trig pin of HC-SR04 is made high for at least 10 us. A sonic beam is transmitted with 8
pulses of 40 KHz each.

The signal then hits the surface and returns back and captured by the receiver Echo pin of
HC-SR04. The Echo pin had already made high at the time sending high.

The time taken by beam to return back is saved in variable and converted to distance
using appropriate calculations like below.

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

4
L293d Motor Driver Module:
The L293d Motor Driver Module is responsible for providing the necessary drive current to the motors of the
robotic car.

L293D Motor Driver

Connections:

Motor Driver to Arduino:

L293D Motor Driver Arduino

A1 Digital pin 4

A2 Digital pin 5

B1 Digital pin 6

B2 Digital pin 7

VCC Vin

GND GND

5
UltraSonic Sensor to Arduino:

UltraSonic Sensor Arduino

Trig Digital pin 9

Echo Digital pin 10

Vcc 5v

GND GND

Buzzer to Arduino:

Buzzer Arduino

Positive(+) Digital pin 12

Negative GND

DC MOTOR L293D MOTOR DRIVER

DC MOTOR1 Positive(+) OUTPUT PIN MA 1

DC MOTOR1 Negative(-) OUTPUT PIN MA 2

DC MOTOR2 Positive(+) OUTPUT PIN MA 1

DC MOTOR1 Negative(-) OUTPUT PIN MA 2

6
Procedure:
Connect Arduino uno using a cable wire

Connect the motors to motor shield

Connect the motor driver to Arduino board

Connect Bluetooth Module to the Arduino Board

After giving all the connections compile and Execute the program

Check the output or Result

Code:

#define BUZZER 16
#define TRIGGER 12
#define ECHO 11
void setup() {

Serial.begin (9600);
pinMode(TRIGGER, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);

7
pinMode(6,OUTPUT);// Open serial monitor at 9600 baud to see ping results.

void loop() {

long duration, distance;


digitalWrite(TRIGGER, LOW);
delayMicroseconds(2);

digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);

digitalWrite(TRIGGER, LOW);
duration = pulseIn(ECHO, HIGH);
distance = (duration/2) / 29.1;
if (distance < 30)
{

Serial.println("B");
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
delay(2000);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
digitalWrite (6,LOW);
delay(2000);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
}
else

8
{

Serial.println("f");
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
} delay(500);

RESULT:

In loop() function, get the distance from HC-SR04 and based on the distance move the
motor direction. The distance will show the object distance coming in front of the robot. The
Distance is taken by bursting a beam of ultrasonic up to 10 us and receiving it after 10us.

If the distance is greater than the defined distance means there is not obstacle in its path
and it will moving in forward direction.

If the distance is less than the defined distance to avoid obstacle means there is some
obstacle ahead. So in this situation robot will stop for a while and move backwards after that
again stop for a while and then take turn to another direction.

9
OBSTACLE AVOIDING ROBOT

So this is how a robot can avoid obstacles in its path without getting stuck
anywhere. Find the complete code and video below.

10

You might also like