Introduction: Obstacle Avoiding Bot

About: I'm passionate about electronics and embedded systems. I always try to do different projects. I'm a quick learner.

An obstacle avoiding robot avoids any obstacle that comes in front of it and changes its path. Here the working is explained with the input, control and output sections. In the input section we use ultrasonic sensor HCSR04 to measure the distance between the object in front of the robot and the robot itself. The control section includes arduino board and motor driver IC. The steps are programmed and uploaded into the board. This robot finds application in commercial devices like room cleaners and also it has military applications. We are now going to see the detailed working of the sensors and how to build a obstacle avoiding robot.

Step 1: Requirements:

Requirements

1. Arduino UNO board

2. HC SR04 ultrasonic sensor-1

3. L293D IC

4. Motors-2

5. 9V Battery-1

6. 6V Battery-2

7. Bread board, jumper wires.

You can buy Arduino board and ultrasonic sensor from the below link:

http://fkrt.it/Q0Fo3!NNNN

http://fkrt.it/AexUoTuuuN

Step 2: Principle of Operation:

The HCSR04 ultrasonic sensor measures distance by using sound waves. The basic operation is the emission and detection of sound waves. It has a transmitter and a receiver. The transmitter has a multi vibrator which is a combination of resonator and vibrator. The resonator delivers ultrasonic wave generated by the vibration. A 40KHz sound wave is emitted and this is detected by the receiver, the transducer inside the receiver detects the wave and sends out a electric pulse.

Step 3: Working:

The ultrasonic sensor has two transducers each for transmitter and receiver. When a electronic pulse is applied to the transducer in the transmitter, the vibrator vibrates across a specific spectrum of frequency and generates sound waves. These waves travel ahead and are bounced back by any object in front of it. These reflected waves are detected by the receiver and sends out a signal to the micro controller through the echo pin. This sensor has a trigger pin, echo pin, VCC and GND pins. A minimum pulse of 10 micro seconds has to be given to the trigger pin to activate the sensor. 5V is given as VCC. The echo pin goes high when the transmitter sends out sound waves and it goes low when they are detected.

We are calculating the time traveled by the ultrasonic waves. Distance is measured using the time calculated. When the transmitter sends out sound waves the echo pin is high and it goes low once they are detected. We calculate the time between high to low transition by using a timer. Since echo pin changes its output it is used as a control pin to the timer. The echo pin has to be connected to an interrupt pin(Pin 4 and 5).

The working of the motor driver IC is same as explained in my line follower bot project. You can find it here:

https://www.instructables.com/id/Line-Follower-Bot...

Step 4: Programming the Bot:

The connections are made as shown in the diagram.The programming is simple and it can be understood easily. In order to calculate the time we use a command called pulseIn(). It reads a pulse on the pin specified and controls the timer. You can read more about it here:

https://www.arduino.cc/en/Reference/PulseIn .

Program:

int trigpin=8;

int echopin=4;

int duration;

int inches,cm;

int led=12;

int leftforward=3;

int leftreverse=10;

int rightforward=5;

int rightreverse=6;

void setup() {

pinMode(trigpin,OUTPUT);

pinMode(echopin,INPUT);

pinMode(led,OUTPUT);

pinMode(leftforward,OUTPUT);

pinMode(leftreverse,OUTPUT);

pinMode(rightforward,OUTPUT);

pinMode(rightreverse,OUTPUT);

}

void loop() {

digitalWrite(trigpin,LOW);

delayMicroseconds(2);

digitalWrite(trigpin,HIGH);

delayMicroseconds(15);

digitalWrite(trigpin,LOW);

duration= pulseIn(echopin,HIGH);

inches = (duration/148);

cm = (duration/58);

if(cm<7)

{

digitalWrite(led,HIGH);

digitalWrite(rightforward,HIGH);

digitalWrite(leftreverse,HIGH);

digitalWrite(rightreverse,LOW);

digitalWrite(leftforward,LOW);

}

else

{

digitalWrite(led,LOW);

digitalWrite(leftforward,HIGH);

digitalWrite(leftreverse,LOW);

digitalWrite(rightforward,HIGH);

digitalWrite(rightreverse,LOW);

}

}

Here the duration is in micro seconds and we convert it to centimeters.