Object Avoiding Bot

Object Avoiding Bot © GPL3+

Coded to avoid obstacles.

  • 651 views
  • 0 comments
  • 3 respects

Components and supplies

About this project

AVOIDER

The main aim of the project is to use ultrasonic sensor and ir sensor to detect the object and avoid the obstacle.I have noted down some scenarios i.e:

  • If a complete wall comes in front of ultrasonic sensor then at a distance of 15cm the bot would reverse and make 180 turn and again start moving.
  • If an object is detected on left/right but not in front of the bot then the ir sensor would detect it and make a slight left/right turn depending on the position of obstacle.
  • If an ultrasonic sensor and one ir sensor detects the object then also a right or left turn is made.

Code

Avoider codeC/C++
The code that is used by the bot in the video.
byte la=2,lb=3,ra=5,rb=4,trig=6,echo=7,ls=8,rs=9;
float duration=1,distance;
float d;
void setup() {
  pinMode(la,OUTPUT);
  pinMode(lb,OUTPUT);
  pinMode(ra,OUTPUT);
  pinMode(rb,OUTPUT);
  pinMode(trig,OUTPUT);
  pinMode(echo,INPUT);
  pinMode(ls,INPUT);
  pinMode(rs,INPUT);
  Serial.begin(9600);
}
float dis(){
 digitalWrite(trig,LOW);
 delayMicroseconds(2);
 digitalWrite(trig,HIGH);
 delayMicroseconds(10); 
 digitalWrite(trig,LOW);
 duration=pulseIn(echo,HIGH);
 distance=duration*(0.034/2);
 Serial.print("distance =");
 Serial.println(distance);
 return distance;
 delay(1000);
}
void drive(){
  digitalWrite(ra,1);
  digitalWrite(la,1);
  digitalWrite(lb,0);
  digitalWrite(rb,0);
}
void stoper(){
  digitalWrite(ra,0);
  digitalWrite(la,0);
  digitalWrite(lb,0);
  digitalWrite(rb,0);
}
void reverse(){
  digitalWrite(ra,0);
  digitalWrite(la,0);
  digitalWrite(lb,1);
  digitalWrite(rb,1);
}
void right(){
  digitalWrite(ra,0);
  digitalWrite(la,1);
  digitalWrite(lb,0);
  digitalWrite(rb,1);
}
void left(){
  digitalWrite(ra,1);
  digitalWrite(la,0);
  digitalWrite(lb,1);
  digitalWrite(rb,0);
}
void loop() {
 d=dis();
 drive();
 if(d<=15)
 {
  if(digitalRead(ls)==1 && digitalRead(rs)==0)
  {
    stoper();
    delay(1000);
    reverse();
    delay(1000);
    right();
    delay(500);
    stoper();
  }
  else
  if(digitalRead(rs)==1 && digitalRead(ls)==0)
  {
    stoper();
    delay(1000);
    reverse();
    delay(1000);
    left();
    delay(500);
    stoper();
  }
  else
  {
    stoper();
    delay(1000);
    reverse();
    delay(1000);
    right();
    delay(2000);
  }
 }
 else
 if(digitalRead(ls)==1 || digitalRead(rs) ==1)
 {
  if(digitalRead(ls)==1)
  {
    stoper();
    delay(1000);
    reverse();
    delay(1000);
    right();
    delay(500);
  }
  else
  {
    stoper();
    delay(1000);
    reverse();
    delay(1000);
    left();
    delay(500);
  }
 }
}

Schematics

Circuit Diagram
The photo uploaded describes the circuit connection of the whole bot.
Img 20180610 083055 ne1dii0uyk
Scenarios
The photo below specifies the cases taken under consideration for the position of the obstacle and from what sensor the input would be provided to the bot.
Img 20180610 083152  01 gfu2czs8no

Comments

Similar projects you might like

Object Avoiding FSM Robot Arm

Project showcase by Marcos Soares and Ricardo Boinho

  • 1,939 views
  • 0 comments
  • 6 respects

Obstacle Avoiding Car

Project showcase by Team Adam

  • 5,744 views
  • 1 comment
  • 18 respects

Ground-Based Obstacle Avoiding Robot

Project showcase by Xavier Tan

  • 5,312 views
  • 1 comment
  • 20 respects

Remote Control bot

by vedrocks15

  • 1,228 views
  • 0 comments
  • 1 respect

Project 1: 2WD Obstacle Avoiding Robot

Project showcase by HDA Robotics

  • 7,535 views
  • 6 comments
  • 17 respects
Add projectSign up / Login