Friday, April 29, 2016

Very Easy How to make a Obstacle Avoiding robot using arduino

A very simple obstacle avoiding robot using arduino , this robot uses very simple code and can accomplish the task with ease, check out the video for how the robot is working, its really simple to make not much complicated circuit. It uses HC SR-04 sensor which senses distance between the robot and object. If the distance is maximum and robot can move without colliding , the robot moves in forward direction, if the robot senses object near to it, it takes diversion and moves to the safe place and avoiding colliding to any objects around the robot,

Components Used: 

HC SR- 04 (ultrasonic sensor)
L293D Motor driver
2x Gear Motor
2x wheels
1x chasis
1x castor wheel
connecting wires
battery
Arduino Uno 


Circuit Diagram:


--------------------------------------------------------------------------------------------------------------------------
Arduino Program:

/*
 HC-SR04 Ping distance sensor:
 VCC to arduino 5v 
 GND to arduino GND
 Echo to Arduino pin 8 
 Trig to Arduino pin 9*/
#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 (4, OUTPUT);
  pinMode (5, OUTPUT);
  pinMode (13, OUTPUT);
  pinMode (6, OUTPUT);
  pinMode (7, 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(4,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(6,LOW);
    digitalWrite(7,LOW);
    delay (200);
  }
  
  else if (distance >=15 && distance <= 25) {
    digitalWrite (4,HIGH);
    digitalWrite (5,LOW);
    digitalWrite (6,LOW);
    digitalWrite (7,LOW);
    delay (1000);
  }
 else if (distance < 15){
   digitalWrite (4, LOW);
   digitalWrite (5, LOW);
   digitalWrite (6,HIGH);
   digitalWrite (7,HIGH);
   delay (1000);
   digitalWrite (4,LOW);
   digitalWrite (5,HIGH);
   digitalWrite (6,LOW);
   digitalWrite (7, LOW);
   delay (1000);
   
     
 }

}

--------------------------------------------------------------------------------------------------------------------------

1 comment: