OBSTACLE AVOIDING ROBOT

aswini aturi
8 min readJul 11, 2020

--

THIS PROJECT IS ABOUT CREATING OBSTACLE AVOIDING ROBOT.

Hardware Used:-

1.Arduino Uno

The Arduino Uno is an open-source micro controller board based on the Microchip AT mega 328P micro controller and developed by Arduino.cc.The board is equipped with sets of digital and analog input/output (I/O) pins that may be interfaced to various expansion boards (shields) and other circuits. The board has 14 digital I/O pins (six capable of PWM output), 6 analog I/O pins, and is programmable with the Arduino IDE (Integrated Development Environment), via a type B USB cable. It can be powered by the USB cable or by an external 9-volt battery, though it accepts voltages between 7 and 20 volts.

2.L293D Motor Driver

The L293D IC receives signals from the microprocessor and transmits the relative signal to the motors. It has two voltage pins, one of which is used to draw current for the working of the L293D and the other is used to apply voltage to the motors.

SCHEMATIC DIAGRAM OF L293D

3.DC Motor

A DC motor is any of a class of rotary electrical motors that converts direct current electrical energy into mechanical energy. Wheels of robot connected to motors and these motors help to rotate wheels.

4.Ultrasonic Sensor

HC-SR04 Ultrasonic (US) sensor is a 4 pin module, whose pin names are Vcc, Trigger, Echo and Ground respectively. This sensor is a very popular sensor used in many applications where measuring distance or sensing objects are required. The module has two eyes like projects in the front which forms the Ultrasonic transmitter and Receiver. The sensor works with the simple high school formula that

Distance = Speed × Time

The Ultrasonic transmitter transmits an ultrasonic wave, this wave travels in air and when it gets objected by any material it gets reflected back toward the sensor this reflected wave is observed by the Ultrasonic receiver module.The circuitry inbuilt on the module will calculate the time taken for the US wave to come back and turns on the echo pin high for that same particular amount of time, this way we can also know the time taken.

ULTRASONIC SENSOR

What is Obstacle Avoider Robot?

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 organisation now which helps carry out many risky jobs that cannot be done by any soldiers.

The obstacle avoidance robotic vehicle uses ultrasonic sensors for its movements. A UNO of Arduino family is used to achieve the desired operation. The motors are connected through motor driver IC to Arduino uno. The ultrasonic sensor is attached in front of the robot.Whenever the robot is going on the desired path the ultrasonic sensor transmits the ultrasonic waves continuously from its sensor head. Whenever an obstacle comes ahead of it the ultrasonic waves are reflected back from an object and that information is passed to the Arduino. The Arduino controls the motors based on ultrasonic signals.

About This Project:-

In this project we design a robot in such a way initially robot move in forward direction just after the switch ON ,whenever an obstacle come in front of robot (almost 20cm away from robot) it will start moving in backward direction for 2 second and then turn in right direction for 1 second then again start moving in forward direction.

When ultrasonic sensor send the value of distance equal to or less than 20cm ,again robot start moving in backward direction for 2 second and then turn in right direction for 1 second then again start moving in forward direction.This process repeat each and every time whenever an obstacle come in front of robot.

This robot also consist 4 LED (2 White LED and 2 Red LED).White LEDs used as headlight and connected in front of robot & Red LEDs used as back light.

When robot move in forward direction headlight start glowing and backlight remain OFF , when robot move in backward direction headlight stop glowing and backlight start glowing and when robot turning right direction both headlight & backlight start glowing. Again when robot start moving in forward direction the headlight start glowing and backlight stop glowing.

Robot keep moving in above manner until we OFF the switch connected in it.

Connections:-

This project consist an Arduino which have 14 pins and these pins connected to different component like ultrasonic sensor, motor, LED and motor driver.Now we will discuss the different connections between Arduino and components.

First, connect Arduino to motor driver IC and then connect motor driver to motors. Pin 8 connected to Input-1 & pin 9 connected to Input-2 of one side of motor driver IC and pin 6 connected to Input-1 & pin 5 connected to Input-2 of second side of motor driver IC.Connect GND pin to ground, connect Enable 1,2,3,4 & Power-1, Power-2 to 5 volt.

Now connect Output-1 & Output-2 of one side of motor driver to left motor terminals and Output-1 & Output-2 of second side of motor driver to right motor terminals.

CONNECTIONS SHOWING BETWEEN ARDUINO AND MOTORS

Now connect pin 3 to trigger pin of ultrasonic sensor and pin 4 to echo pin of ultrasonic sensor. Connect Vcc pin of sensor to 5volt and GND pin of sensor to GND of Arduino.

CONNECTIONS SHOWING BETWEEN ARDUINO AND ULTRASONIC SENSOR

Finally, connect pin 11,13 to Anode of white LED (Headlight) & Cathode connect to GND and pin 2,7 to Anode of red LED (Backlight) & Cathode to GND.

CIRCUIT DIAGRAM OF OBSTACLE AVOIDING ROBOT

Program:-

HERE I AM GOING TO DISCUSS THE PROGRAM IN STEP BY STEP MANNER.

void setup()
{
}

Void setup() is technically a function that we create at the top of each program. Inside the curly brackets is the code that we want to run one time as soon as the program starts running.

void loop()
{
}

void loop(): The loop is another function that Arduino uses as a part of its structure. The code inside the loop function runs over and over as long as the Maker Board is turned on. ; (semicolon) The end of a command or statement.

pinMode(_, OUTPUT);
pinMode(_, INPUT);

The pinMode() function is used to configure a specific pin to behave either as an input or an output.

pinMode(8, OUTPUT);//left motor
pinMode(9, OUTPUT);
pinMode(5, OUTPUT);//right motor
pinMode(6, OUTPUT);

Pin number 8,9 used for left motor and pin number 5,6 used for right motor and these pins connected to motors via L293D motor driver.

pinMode(3, OUTPUT);//ultrasonic sensor
pinMode(4, INPUT);

Pin number 3,4 connected to ultrasonic sensor in which pin 3 connected to trigger pin used as OUTPUT and pin 4 connected to echo pin used as INPUT.

pinMode(13, OUTPUT);//front light
pinMode(11, OUTPUT);
pinMode(2, OUTPUT);//back light
pinMode(7, OUTPUT);

Pin number 13,11 used for front light and pin number 2,7used for backlight.

digitalWrite(13,HIGH);//turning ON front light
digitalWrite(11,HIGH);
digitalWrite(2,LOW);
digitalWrite(7,LOW);

DigitalWrite Arduino Command is used to write the status of digital Pins, and can make them either HIGH or LOW. The Pin needs to be an OUTPUT Pin.

Pin 13,11 represent headlight and pin 2,7 represent backlight. When robot begin to move forward, headlight start glowing because pin 13,11 set to HIGH and backlight remain OFF because pin 2,7 set to LOW.

digitalWrite(8, HIGH);//move forward
digitalWrite(9,LOW);
digitalWrite(5, HIGH);
digitalWrite(6,LOW);

Pin 8,9 represent left motor and pin 5,6 represent right motor. Since pin 8 set to HIGH(terminal-1 of motor )and pin 9 set to LOW (terminal-2 of motor) ,left motor rotating in clockwise direction.

Similarly, Since pin 5 set to HIGH(terminal-1 of motor )and pin 6 set to LOW (terminal-2 of motor) , right motor also rotating in clockwise direction.

Since both motor moving in clockwise direction robot start moving in forward direction.

digitalWrite(3,LOW );//trigger pulse
delay(200);
digitalWrite(3, HIGH);
delay(200);
digitalWrite(3,LOW );

Above code is used to generate pulse by Arduino.

float duration=pulseIn(4,HIGH);

pulseIn( ) function is used to calculate duration between transmitting and receiving signal.

Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds or 0 if no complete pulse was received within the timeout.

Time calculated by sensor in micro second.

float distance=duration*(0.0344/2);//distance calculation
Serial.print("Distance=");
Serial.println(distance);
delay(100);

Serial.print() is used to print data on serial monitor.

Formula:- distance=duration*(0.0344/2) , where duration in micro second.

Above code is used to calculate distance using duration measure by sensor with the help of formula distance=speed*time where speed is equal to speed of sound in air i.e, 344 m/sec.

Above calculated distance in centi meter (cm).

if(distance<=20)
{
digitalWrite(2,HIGH);//turning ON back light
digitalWrite(7,HIGH);
digitalWrite(11,LOW);
digitalWrite(13,LOW);

digitalWrite(9, HIGH);//move backward
digitalWrite(8,LOW);
digitalWrite(6, HIGH);
digitalWrite(5,LOW);
delay(2000);

digitalWrite(2,HIGH);//turning ON all light
digitalWrite(7,HIGH);
digitalWrite(11,HIGH);
digitalWrite(13,HIGH);

digitalWrite(8, HIGH);//turning right
digitalWrite(9,LOW);
digitalWrite(5, LOW);
digitalWrite(6,LOW);
delay(1000);

digitalWrite(13,HIGH);//turning ON front light
digitalWrite(11,HIGH);
digitalWrite(2,LOW);
digitalWrite(7,LOW);

digitalWrite(8, HIGH);//move forward
digitalWrite(9,LOW);
digitalWrite(5, HIGH);
digitalWrite(6,LOW);

}

According to above code, when robot reach to near a obstacle whose distance equal to or less than 20 cm robot first start moving in backward direction for 2 sec and take a turn in right direction for 1 sec and then start moving in forward direction.

When robot start moving in backward direction, backlight turn ON and headlight turn OFF.

When robot turning right, both headlight and backlight turn ON.

When robot start moving in forward direction, backlight turn OFF and headlight turn ON.

void setup()
{
pinMode(8, OUTPUT);//left motor
pinMode(9, OUTPUT);
pinMode(5, OUTPUT);//right motor
pinMode(6, OUTPUT);
pinMode(3, OUTPUT);//ultrasonic sensor
pinMode(4, INPUT);
pinMode(13, OUTPUT);//front light
pinMode(11, OUTPUT);
pinMode(2, OUTPUT);//back light
pinMode(7, OUTPUT);
}
void loop()
{
digitalWrite(13,HIGH);//turning ON front light
digitalWrite(11,HIGH);
digitalWrite(2,LOW);
digitalWrite(7,LOW);

digitalWrite(8, HIGH);//move forward
digitalWrite(9,LOW);
digitalWrite(5, HIGH);
digitalWrite(6,LOW);

digitalWrite(3,LOW );//trigger pulse
delay(200);
digitalWrite(3, HIGH);
delay(200);
digitalWrite(3,LOW );

float duration=pulseIn(4,HIGH);
float distance=duration*(0.0344/2);//distance calculation
Serial.print("Distance=");
Serial.println(distance);
delay(100);
if(distance<=20)
{
digitalWrite(2,HIGH);//turning ON back light
digitalWrite(7,HIGH);
digitalWrite(11,LOW);
digitalWrite(13,LOW);

digitalWrite(9, HIGH);//move backward
digitalWrite(8,LOW);
digitalWrite(6, HIGH);
digitalWrite(5,LOW);
delay(2000);

digitalWrite(2,HIGH);//turning ON all light
digitalWrite(7,HIGH);
digitalWrite(11,HIGH);
digitalWrite(13,HIGH);

digitalWrite(8, HIGH);//turning right
digitalWrite(9,LOW);
digitalWrite(5, LOW);
digitalWrite(6,LOW);
delay(4000);

digitalWrite(13,HIGH);//turning ON front light
digitalWrite(11,HIGH);
digitalWrite(2,LOW);
digitalWrite(7,LOW);

digitalWrite(8, HIGH);//move forward
digitalWrite(9,LOW);
digitalWrite(5, HIGH);
digitalWrite(6,LOW);

}
}

THIS IS THE COMPLETE PROGRAMME.

REFERENCES:

* https://www.arduino.cc/

*https://www.google.com/search?q=OBSTACLE+AVOIDING+ROBOT&rlz=1C1PNBB_en&oq=OBSTACLE+AVOIDING+ROBOT&aqs=chrome..69i57j35i39l2j69i59j0j69i61j69i60l2.10293j0j7&sourceid=chrome&ie=UTF-8

--

--