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 is and how does it work. basically,

 

Introduction

it is a robot that walks automatically with the help of an ultrasonic sensor. an ultrasonic sensor is used in many other mini-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? / Working

 

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

An ultrasonic sensor having 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. we can make many other mini projects for ece with this useful sensor.

 

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

 

Component Table

 

S.No Component Name Quantity Link
1. Arduino UNO 1 https://amzn.to/3ue2vmh
2. Ultrasonic Sensor 1 https://amzn.to/39uTStP
3. Servo Motor 1 https://amzn.to/3zxjqkz
4. L298N Motor Driver 1 https://amzn.to/3lJTw8c
5. Jumper Wire 40 https://amzn.to/39q43jr
6. Breadboard 1 https://amzn.to/39vsRX2
7. BO Motor & Wheel 4 https://amzn.to/3zuAkAd
9. Switch 1 https://amzn.to/3nZ4tFH
10. 9 Volt Battery 2 https://amzn.to/3EKvkLB

 

this is a special Obstacle avoiding robot using Arduino 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 human. when we cross the road. the robot walks straight and if it found any obstacle in the path it rotates its neck and compares 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 

Learn 10+ basic activity & sensor interfacing with our Arduino ebook. Well explained program. And brief circuit diagram WhatsApp and email support. which will help you to learn basic electronics, Arduino Coding, Sensor interfacing with Arduino, Arduino, and much more. buy Arduino Ebook to learn https://techatronic.com/arduino-ebook/

 

Obstacle avoiding robot circuit diagram

 

obstacle avoiding robot circuit diagram

 

Fritzing Diagram

 

 

 

Connection Table

 

Arduino UNO Servo Motor
PIN  3 Signal Pin Orange Wire
VCC VCC Red Wire
GND GND Black Wire
Arduino UNO Ultrasonic Sensor
VCC VCC
PIN 5 Trig
PIN 6 Echo
GND GND
Arduino UNO L293d Motor Driver
PIN 7 IN 1
PIN 8 IN 2
PIN 9 IN 3
PIN 10 IN 4
Arduino UNO 9 Volt Battery Switch
VIN PIN + Positive
GND Terminal 1
GND Terminal 2
L293d Motor Driver 9 Volt Battery Switch
+12 V PIN + Positive
GND Terminal 1
GND Terminal 2

Obstacle avoiding robot code:-

 

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

#include <Servo.h>
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);
  }

}

 

Video Sample