Obstacle Avoiding Robot using Arduino with Code

Obstacle detection and avoiding robots are intelligent robots that can perform desired tasks in an unstructured environment by finding and overcoming obstacles in their way without continuous human guidance.

Obstacle avoidance is a means of a robot being able to move around in an unknown environment whilst not colliding with surrounding objects. Obstacle avoidance can be found on many different types of machines, big and industrial robots, or even on newer cars. Knowing how to program obstacle avoidance into your robots can be a very useful skill to have, whether for a little robot project, or a larger project where obstacle avoidance is just a small piece of the larger picture. 

We will need the following components for this project:

1. Microcontroller (Arduino Mega 2560)
2. Motor Shield (L298P)
3. Ultrasonic Sensor (HC08)
4. Bread Board
5. Robot chassis with 4 DC motors and 4 wheels
6. Connecting Wires
7. Power source (9v battery)
8. Arduino IDE 
9. Servo motor (SG90)

CIRCUIT DESIGN:

To implement your project successfully, we had done these steps for designing our robotic circuit connection. 

STEP 1: Robot chassis DC motors connection to Motor Shield

Each motor has  +ve and –ve terminals. Two +ve and –ve terminals of both left side and right side DC motors are shorted separately to be connected to the ports of motor shield A+, A-( 2 +ve terminals of left side DC motors are connected to A+ and 2 -ve terminals of left side DC motors are connected to A-  ) and B+, B-( 2 +ve terminals of right side DC motors are connected to B+ and 2 -ve terminals of right side DC motors are connected to B-  ) respectively. 

STEP 2: Servo motor connection

The Servo motor we used was TowerPro SG90 9G Micro Small Servo Motor to control movement 0-180 degrees. This controls the ultrasonic head movement for sensing an obstacle. It  has three wire :

Red = +5v

Brown = GND

Orange = Signal (pin 10 for our code)

STEP 3:  Ultrasonic Sensor Connection

The ultrasonic Sensor we used was HC-SR04. It consists of 4 wires for the following connection:

VCC = +5VDC
Trig = Trigger input of Sensor  (pin no 12 for our project)
Echo = Echo output of Sensor  (pin no 11 for our project)
GND = GND

STEP 4:  Horn and Light Connection

Horn and Light we used here. It consists of 3 wires for the following connection:

Horn = pin 2 in the motor shield 
Lignt = 1 in the motor shield 
        GND = GND

By following the above procedure, we completed our circuit designing of Obstacle avoiding robot.

Working Principle of this Obstacle Avoiding Robot

The Obstacle avoiding robot we created was mainly based on the working principle of 

Ultrasonic sensor.  Our robot initially goes on moving forward direction until it gets any kind of obstacle. During moving, every time it will check if there is any obstacle nearby by continuously sending and receiving distance-related information. The Trig pin will be used to send the signal and the Echo pin will be used to listen for returning signal.

So, For every check, we are seeing if there is an object closer than 30 cm to our robot. The check has two possible outcomes, yes or no. Yes, meaning that there is indeed some object closer than 30 cm. No, meaning that there are no objects detected within 30 cm. If there is nothing within 30 cm the robot can simply move forward as the path is clear. If there is something closer than 30 cm the robot must perform obstacle avoidance maneuvers.

Another check occurs to see what direction is the best way to go. If left is the way to go it has to turn back to the left and then go forward. If the right is the way to go the robot simply moves forward as it is already facing in the right direction.

All we have done is converting that diagram into Arduino code and that's it. So, easily, the obstacle avoidance code was done.


Arduino Code for Obstacle Avoiding Robot:






0/Post a Comment/Comments