Sunday, November 23, 2014

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);
   
     
 }

}

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

For assembling the robot please check  http://learnhowtomakerobot.blogspot.in/2014/11/a-simple-line-following-robot-without.html

19 comments:

  1. AWESOME! Can't wait to try this. Just want to make certain I am looking at the schematic correctly. Did you jumper the power from one positive to the negative side of the board making it a positive? Also, what size resistors did you use along the motor drive?

    ReplyDelete
  2. AWESOME! Can't wait to try this. Just want to make certain I am looking at the schematic correctly. Did you jumper the power from one positive to the negative side of the board making it a positive? Also, what size resistors did you use along the motor drive?

    ReplyDelete
  3. Arduino: 1.6.3 (Windows 7), Board: "Arduino Uno"

    sketch_may18a.ino: In function 'void setup()':

    sketch_may18a.ino:3:12: error: 'trigpin' was not declared in this scope

    sketch_may18a.ino:4:12: error: 'echopin' was not declared in this scope

    sketch_may18a.ino: In function 'void loop()':

    sketch_may18a.ino:16:18: error: 'trigpin' was not declared in this scope

    sketch_may18a.ino:22:5: error: 'duration' was not declared in this scope

    sketch_may18a.ino:22:23: error: 'echopin' was not declared in this scope

    sketch_may18a.ino:24:5: error: 'distance' was not declared in this scope

    sketch_may18a.ino:29:7: error: 'distance' was not declared in this scope

    Error compiling.

    This report would have more information with
    "Show verbose output during compilation"
    enabled in File > Preferences.
    Getting this error code

    ReplyDelete
  4. Arduino: 1.6.3 (Windows 7), Board: "Arduino Uno"

    sketch_may18a.ino: In function 'void setup()':

    sketch_may18a.ino:3:12: error: 'trigpin' was not declared in this scope

    sketch_may18a.ino:4:12: error: 'echopin' was not declared in this scope

    sketch_may18a.ino: In function 'void loop()':

    sketch_may18a.ino:16:18: error: 'trigpin' was not declared in this scope

    sketch_may18a.ino:22:5: error: 'duration' was not declared in this scope

    sketch_may18a.ino:22:23: error: 'echopin' was not declared in this scope

    sketch_may18a.ino:24:5: error: 'distance' was not declared in this scope

    sketch_may18a.ino:29:7: error: 'distance' was not declared in this scope

    Error compiling.

    This report would have more information with
    "Show verbose output during compilation"
    enabled in File > Preferences.
    Getting this error code

    ReplyDelete
  5. Hello, I have a question on the robot above. Is there a direct power souce going into the arduino, becuase when I follow the circit Diagram above my arduino looks like it is turned off. If you could get back to me that would be great!

    Thanks, Jacob

    ReplyDelete
  6. I am thinking of puting second hc-sr04 sensor.. :P can you help me ?

    ReplyDelete
  7. our bot was just rapidly turning. any suggestions.. we clearly follwed the circuit diagram

    ReplyDelete
  8. For me its not working pls help im did everything but its just wiggling around when something is really close to him

    ReplyDelete
  9. explain me about distance calculation formula

    ReplyDelete
  10. why these errors while uploading the program to arduino board !! ?
    it can not be uploaded !! plz help
    Arduino: 1.6.0 (Windows 8), Board: "Arduino Uno"

    Sketch uses 3,996 bytes (12%) of program storage space. Maximum is 32,256 bytes.

    Global variables use 190 bytes (9%) of dynamic memory, leaving 1,858 bytes for local variables. Maximum is 2,048 bytes.

    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x01
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x01
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x01
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x01
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x01
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x01
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x01
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x01
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x01
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x01
    Problem uploading to board.

    ReplyDelete
  11. hey, i have built an avoider robot with this schematic, when all steps done, the DC motors arent working, so why?? and whats the problem?

    ReplyDelete
  12. plaese add new post about voice control obstacle avoiing robot

    ReplyDelete
  13. sir i have to only enter this code or something else also after making schematic

    ReplyDelete