Obstacle Avoiding robot using Arduino

Obstacle Avoiding robot using Arduino

 Obstacle Avoiding Robot using Arduino

How to make an Obstacle Avoiding Robot using Arduino.
Welcome to the Techatronic guys, So in this project, we will make an
Obstacle avoiding robot using Arduino and kit. do you know about the obstacle avoiding robot? well, I am gonna explain to you what does it and how does it work. basically, it is a robot that walks automatically with the help of the ultrasonic sensor. an ultrasonic sensor is used in many other projects like Smart robots. obstacle avoiding robot also known as the autonomous robot.
which takes the decision self. if there is something in front of the robot it will change
its path like a human. so’ it is somewhere smart. it is the most popular project nowadays which is searched by most of the students nowadays. and everyone likes this robot.in this project, you will also learn many things like how to use the ultrasonic sensor. and using the serial monitor also. we will discuss the code also.

 

Obstacle avoiding Robot

How does it work?

In Obstacle avoiding robot, there is a sensor that is known as the ultrasonic sensor. which have the capability to measure the distance in front of the sensor. in the below paragraph we will know how does the sensor work. in this obstacle avoiding robot using Arduino Uno, it works like a distance measurer.

An ultrasonic sensor having the two parts one is a transmitter and another is the receiver that is known as a trigger and echoes. the trigger is the transmitter part and transmits the ultrasonic wave. another part that is receiver an echo receive that transmitter ultrasonic waves transmitted from the trigger. now we calculate that in how much time the ultrasonic waves return back to the receiver and divided by 2 because the time travel is double.

 

ultrasonic sensor working

 

we calculate the distance by the time and speed formula

distance = time X speed

of the ultrasonic wave = 340 m/s

Components Required for obstacle avoiding robot 

  1. Arduino NANO or Uno (any version)
  2. HC-SR04 Ultrasonic Sensor
  3. LM298N Motor Driver Module
  4. 5V DC Motors
  5. Battery
  6. Wheels
  7. Chassis
  8. Jumper Wires

this is a special obstacle avoiding robot with neck to detect the distance here and there also. the ultrasonic sensor is connected to the servo which rotates if there is any obstacle found in the path of the robot-like a human. when we cross the road. the robot walks straight and if it found any of obstacle in the path it rotates its neck and compare the distance from the right and left then according to the distance it takes the decision. for example, it detects any obstacle in the path then it will stop and check right and left where is the maximum distance. so it will turn the right or left according to the maximum distance. If you want to add a metal detector to this project that makes it a big project so you can learn about how to make a metal detector 

Obstacle Avoiding car circuit diagram Arduino

obstacle avoiding robot circuit diagram

 

 

Arduino code for Obstacle avoiding robot:-

 

int duration=0;
long distance=0;
int firstduration=0;
long firstdistance=0;
int secondduration=0;
long seconddistance=0;





#include 
Servo myservo; 

int pos = 0;   

void setup() {
pinMode(5,OUTPUT);
pinMode(6,INPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
 myservo.attach(3);
Serial.begin(9600); 
}
void loop() {


digitalWrite(5, HIGH);
delayMicroseconds(10);
digitalWrite(5, LOW);
delayMicroseconds(2);
duration= pulseIn(6,HIGH);
delay(100);
distance=duration*0.034/2;
Serial.println(distance);
if(distance<=20)
{



  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);

  delay(300);

digitalWrite(7, LOW);
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);

  delay(350);


  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);

myservo.write(0);
delay(500);
digitalWrite(5, HIGH);
delayMicroseconds(10);
digitalWrite(5, LOW);
delayMicroseconds(2);
firstduration= pulseIn(6,HIGH);
delay(100);
firstdistance=firstduration*0.034/2;
int first = firstdistance; 
Serial.println(firstdistance);


  myservo.write(90);
delay(500);



  myservo.write(180);
delay(500);
digitalWrite(5, HIGH);
delayMicroseconds(10);
digitalWrite(5, LOW);
delayMicroseconds(2);
secondduration= pulseIn(6,HIGH);
delay(100);
seconddistance=secondduration*0.034/2;
int second = seconddistance;

Serial.println(seconddistance);

myservo.write(90);
delay(500);

if(first < second ) { digitalWrite(7, LOW); digitalWrite(8, HIGH); digitalWrite(9, HIGH); digitalWrite(10, LOW); delay(500); } else if(first >   second  )


{

 digitalWrite(7, HIGH);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);  
 delay(500);
 
  
  
  }
}

  
else 
{
  digitalWrite(7, HIGH);
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  digitalWrite(10, LOW);
  }

}