Aniket Mindhe
Published

Obstacle Avoiding Robot

A simple obstacle avoiding robot developed on Arduino platform.

IntermediateFull instructions provided1.5 hours1,733
Obstacle Avoiding Robot

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Battery - 18650 - 7800mAh- 3.7V
×1
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
×1
9V battery (generic)
9V battery (generic)
×1
9V to Barrel Jack Connector
9V to Barrel Jack Connector
×1
BO Motor - Straight - 300rpm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Ball Caster Wheel
×1
Chasis - Eg. Plastic Box Cover, Acrylic Sheet, Metal Sheet
×1
Toggle Switch, (Off)-On
Toggle Switch, (Off)-On
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Tape, Double Sided
Tape, Double Sided
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Obstacle Avoiding Robot

Connect them and get going !

Code

Obstacle Avoiding Robot

C/C++
Download/Copy-Paste and compile+upload it using Arduino IDE.
int trigPin = 9;      // Trig Pin Of HC-SR04
int echoPin = 8;     // Echo Pin Of HC-SR04
int revleft4 = 10; // Motor Pins
int fwdleft5 = 11;
int revright6 = 12;
int fwdright7 = 13;
long duration, distance;

void setup() {
  Serial.begin(9600);
  pinMode(revleft4, OUTPUT); // Set Motor Pins As O/P
  pinMode(fwdleft5, OUTPUT);
  pinMode(revright6, OUTPUT);
  pinMode(fwdright7, OUTPUT);
  pinMode(trigPin, OUTPUT); // Set Trig Pin As O/P To Transmit Waves
  pinMode(echoPin, INPUT); //Set Echo Pin As I/P To Recieve Reflected Waves
}

void loop() {

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);   
  digitalWrite(trigPin, HIGH); // Transmit Waves For 10us
  delayMicroseconds(10);
  duration = pulseIn(echoPin, HIGH); // Recieve Reflected Waves
  distance = duration / 58.2; // Get Distance
  delay(10);
  if (distance > 20) // Condition For Absence Of Obstacle            
  {
    digitalWrite(fwdright7, HIGH); // Move Forward
    digitalWrite(revright6, LOW);
    digitalWrite(fwdleft5, HIGH);                                
    digitalWrite(revleft4, LOW);                                                       
  }

  if (distance < 20) // Condition For Presence Of Obstacle
  {
    digitalWrite(fwdright7, LOW); //Stop                
    digitalWrite(revright6, LOW);
    digitalWrite(fwdleft5, LOW);                                
    digitalWrite(revleft4, LOW);
    delay(500);
    digitalWrite(fwdright7, LOW); // Move Backward             
    digitalWrite(revright6, HIGH);
    digitalWrite(fwdleft5, LOW);                                
    digitalWrite(revleft4, HIGH);
    delay(500);
    digitalWrite(fwdright7, LOW);  //Stop                
    digitalWrite(revright6, LOW);
    digitalWrite(fwdleft5, LOW);                                
    digitalWrite(revleft4, LOW);  
    delay(100);  
    digitalWrite(fwdright7, HIGH); // Move Left       
    digitalWrite(revright6, LOW);   
    digitalWrite(revleft4, LOW);                                 
    digitalWrite(fwdleft5, LOW);  
    delay(500);
  }

}

Credits

Aniket Mindhe

Aniket Mindhe

7 projects • 3 followers
Undergrad Electronics Engineering Student at D.J Sanghvi C.O.E.-Mumbai

Comments