Basics

Sunday, 27 March 2016

Obstacle avoiding Robot using Arduino

     Hey guys in this tutorial we will see how to make an autonomous obstacle avoiding Robot.This robot is designed and programmed in such a way that it avoids collision.The robot basically moves in a forward direction and whenever it detects a object/obstacle in its path it takes an diversion and avoids the collision.

COMPONETS REQUIRED:

  • Arduino UNO
  • HC SR-04(Ultrasonic sensor)
  • ultrasonic sensor clamp(optional)
  • L293D motor driver
  • metal chassis
  • 2x BO motors
  • 1x caster wheel
  • 2x wheels
  • 2x 9v battery
  • 2x dc battery connectors
  • connecting wires


WORKING PRINCIPLE:

 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.

ULTRASONIC SENSOR:
The ultrasonic sensor is used for obstacle detection. Ultrasonic sensor transmits the ultrasonic waves from its sensor head and again receives the ultrasonic waves reflected from an object.The ultrasonic sensor emits the short and high frequency signal. These propagate in the air at the velocity of sound. If they hit any object, then they reflect back echo signal to the sensor. The ultrasonic sensor consists of a multi vibrator, fixed to the base. The multi vibrator is combination of a resonator and vibrator. The resonator delivers ultrasonic wave generated by the vibration. 

 The ultrasonic sensor actually consists of two parts; the emitter which produces a 40 kHz sound wave and detector detects 40 kHz sound wave and sends electrical signal back to the arduino.
The ultrasonic sensor enables the robot to virtually see and recognize object, avoid obstacles, measure distance. To use this sensor to measure distance, the robot's brain must measure the amount of time it takes for the ultrasonic sound to travel.                                              
  Sound travels at approximately 340 meters per second. This corresponds to about 29.412┬Ás (microseconds) per centimeter. To measure the distance the sound has travelled we use the formula: Distance = (Time x SpeedOfSound) / 2. The "2" is in the formula because the sound has to travel back and forth. First the sound travels away from the sensor, and then it bounces off of a surface and returns back. The easy way to read the distance as centimeters is to use the formula: Centimeters = ((Microseconds / 58.2).

LETS MAKE THE ROBOT:

STEP1:

Fix the wheels on the metal chassis and mount the Dc BO motors on the back wheels and fix a caster wheel in the front.
connect the L293D motor driver with the arduino and dc motors.
CONNECTIONS:
3,6(l293d) to left motor(output)
11,14(l293d) to right motor(output)

2,7,10,15(l293d) to pins 2,3,4,5 of Arduino(inputs)

NOTE: you can use an l293d ic or an readymade module,each module differs so check L293D IC pin diagram to make correct connections.


STEP 2:



connect the ultra sonic sensor with your arduino,
pin 8 of arduino to echo pin 
pin 9 of arduino to trigger pin
vcc-5v ,gnd-gnd

STEP3:
Interface your arduino with arduino IDE software and upload the below program.


#define echopin  8 // echo pin
#define trigpin 9 // Trigger pin
int maximumRange = 30;
long duration, distance;

void setup() {
  Serial.begin (9600);
  pinMode (trigpin, OUTPUT);
  pinMode (echopin, INPUT );
  pinMode (2, OUTPUT);
  pinMode (3, OUTPUT);
  pinMode (4, OUTPUT);
  pinMode (5, OUTPUT);
}
void loop ()
{

  {
    digitalWrite(trigpin,LOW);
    delayMicroseconds(2);
    digitalWrite(trigpin,HIGH);
    delayMicroseconds(10);
    duration=pulseIn (echopin,HIGH);
    distance= duration/58.2;
    delay (50);
    Serial.println(distance);
  }
  
  if (distance >= 30 ){
    digitalWrite(2,HIGH);
    digitalWrite(3,LOW);
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    delay (200);
  }
  
  else if (distance >=15 && distance <= 25) {
    digitalWrite (2,HIGH);
    digitalWrite (3,LOW);
    digitalWrite (4,LOW);
    digitalWrite (5,LOW);
    delay (1000);
  }
 else if (distance < 15){
   digitalWrite (2, LOW);
   digitalWrite (3, HIGH);
   digitalWrite (4, LOW);
   digitalWrite (5, HIGH);
   delay (1000);
   digitalWrite (2,LOW);
   digitalWrite (3,LOW);
   digitalWrite (4,HIGH);
   digitalWrite (5,LOW);
   delay (1000);     
 }
}

DOWNLOAD PROGRAM:click here

STEP 4:

connect the power supply to your arduino and motor driver....

YOUR BOT IS READY TO GO.......