Edu-Right, learn about electrical electronics, space science, science fact. We provide Right Education and Develop technical Skills only on Edu-Right

Science Fact

Space science

Electrical & Electronics

How To

edu-right

Obstacle Avoiding Robot By Using Arduino Project 3


What is an obstacle avoiding robot?

Obstacle Avoiding robot is an intelligent device that may automatically sense the obstacle. This style permits the robot to navigate in unknown surroundings by preventing collisions, which could be a primary demand for an autonomous mobile robot. The applying of the Obstacle Avoiding robot isn't restricted, and it's utilized in most of the military organizations currently that help perform several risky jobs that can't be done by any troopers.


We'll use Arduino and ultrasonic devices to form an Obstacle Avoider. Here an ultrasonic sensor is employed to sense the obstacles within the path by scheming the space between the mechanism and obstruction. If a robot finds an obstacle, it changes the direction and continues moving.

How ultrasonic sensor are often wont to Avoid Obstacles

Before planning to build the robot, it's essential to know; however, the inaudible device works as a result of this device can have a vital role in detection an obstacle. The fundamental principle behind the operating of the inaudible transducer is to notice down the time taken by device to transmit low beams and receiving small rays when touching the surface. Then any, space is calculated exploitation the formula. During this project, the wide offered HC-SR04 inaudible device is employed. To use this device, the same approach is going to be followed, as explained on top of.


Edu-rightProcedure:-


So yes, I’m planning to divide the total creating into four elements. 





Connections of ultrasonic sensor    →    Connections of L298N    →    Code    →    Testing


If you haven’t used or experimented before with the inaudible device, I might recommend you get accustomed to it first! I have a detailed tutorial on ultrasonic sensor HC SR-04 which can guide you throughout

Calculation of Distance

Distance= (Time (t) x Speed of Sound in Air (343 m/s))/2
= (tx(343m/s))/2


Connections of Ultrasonic sensor

VCC – VCC terminal of Arduino.
GND – GND terminal of Arduino.
Trigpin – digital pin 9 on Arduino.
Echo pin – digital pin 10 on Arduino.
Connections of L298N –
 +12V – Positive terminal of the battery.
GND – a)GND of Arduino b)Negative terminal of the battery.
Input terminal 1 – Pin 4
Input terminal 2 – Pin 5
Input terminal 3 – Pin 6
Input terminal 4 – Pin 7
The output terminal 1 – Positive of the first motor.
The output terminal 2 – Negative of the first motor.
The output terminal 3 – Positive of the second motor.
The output terminal 4 – Negative of the second motor.


We used the ultrasonic sensors in many projects to learn more about Ultrasonic sensors, check other projects related to the Ultrasonic sensor. 

The requirement for this obstacle avoiding robot can be found easily. You can go through this list. A shorted component are given and click "Buy now" option. To make chassis, Preferable if you make it my own.


Electronics Product Required

(I recommend only these product that I used for this project you can buy from another site also but these are trusted for me)

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



Arduino Code for Obstacle Avoiding Robot

A complete program with a demonstration video is given at the end of this project. The program will include setting up an HC-SR04 module and outputting the signals to Motor Pins to move motor direction accordingly. We are trying to complete this project without any library file.

First, define the trig and echo pin of HC-SR04 are given below in the code. Go through with this code, and the trig pin is connected to GPIO9, and the echo pin connects with the GPIO10 of Arduino NANO.

int trigPin = 9;    // trig pin in HC-SR04
int echoPin = 10;  // Echo pin in HC-SR04

Define pins for the input of the LM298N Motor Driver Module. The LM298N has 4 input pins used to control the direction of a motor connected to it.

int revleft4 = 4;       //Reverse motion of Left motor
int fwdleft5 = 5;       //Forward motion of Left motor
int revright6 = 6;      //Reverse motion of Right motor
int fwdright7 = 7;      //Forward motion of Right motor



LM298N Motor Driver Module Connection


In setup() function, set the data direction of utilized GPIO pins. The four Motor pins and Trig pin are set as OUTPUT, and Echo Pin is set as Input.

pinMode(revleft4, OUTPUT);      // set Motor pins as output
pinMode(fwdleft5, OUTPUT);
pinMode(revright6, OUTPUT);
pinMode(fwdright7, OUTPUT); 
pinMode(trigPin, OUTPUT);         // set trig pin as output
pinMode(echoPin, INPUT);          //set echo pin as input to capture reflected waves

In loop() function, get the distance from HC-SR04 and, based on the range, move the motor direction. The length will show the object distance coming in front of the robot. The Distance is taken by bursting a beam of ultrasonic up to 10 mm and receiving it after 10mm. To learn more about measuring distance using the Ultrasonic sensor and Arduino, follow the link.

digitalWrite(trigPin, LOW);
delayMicroseconds(2);   
digitalWrite(trigPin, HIGH);     // send waves for 10 us
delayMicroseconds(10);
duration = pulseIn(echoPin, HIGH); // receive reflected waves
distance = duration / 58.2;   // convert to distance
delay(10);

If the distance is higher than the defined range means there is no obstacle in its path, and it will move in a forward direction.

            if (distance > 19)            
            {
            digitalWrite(fwdright7, HIGH);                    // move forward
            digitalWrite(revright6, LOW);
            digitalWrite(fwdleft5, HIGH);                                
            digitalWrite(revleft4, LOW);                                                       
            }

If the distance is less than the set range to avoid obstacles means there is some obstacle ahead. The robot will stop and move backward after again stop and then take a turn in another direction.

              if (distance < 18)
             {
             digitalWrite(fwdright7, LOW);  //Stop                
             digitalWrite(revright6, LOW);
             digitalWrite(fwdleft5, LOW);                                
             digitalWrite(revleft4, LOW);
             delay(500);
             digitalWrite(fwdright7, LOW);      //movebackword         
             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);       
             digitalWrite(revright6, LOW);   
             digitalWrite(revleft4, LOW);                                 
             digitalWrite(fwdleft5, LOW);  
             delay(500);
            }


So this is how a robot can avoid obstacles and can find its own path. Find the complete code below

Code For Obstacle Avoiding Robot


int trigPin = 9;      // trig pin of HC-SR04
int echoPin = 10;     // Echo pin of HC-SR04

int revleft4 = 4; //Reverse motion of Left motor
int fwdleft5 = 5; //Forward motion of Left motor
int revright6 = 6; //Reverse motion of Right motor
int fwdright7 = 7; //Forward motion of Right motor

long duration, distance;

void setup() {
  
  delay(random(500,2000)); // delay for random time
  Serial.begin(9600);
  pinMode(revleft4, OUTPUT);// set Motor pins as output
  pinMode(fwdleft5, OUTPUT);
  pinMode(revright6, OUTPUT);
  pinMode(fwdright7, OUTPUT);
  
  pinMode(trigPin, OUTPUT);// set trig pin as output
  pinMode(echoPin, INPUT); //set echo pin as input to capture reflected waves
}

void loop() {

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);   
  digitalWrite(trigPin, HIGH); // send waves for 10 us
  delayMicroseconds(10);
  duration = pulseIn(echoPin, HIGH); // receive reflected waves
  distance = duration / 58.2; // convert to distance
  delay(10);
    // If you don't get proper movements of your robot then alter the pin numbers
  if (distance > 19)            
  {
    digitalWrite(fwdright7, HIGH);    // move forward
    digitalWrite(revright6, LOW);
    digitalWrite(fwdleft5, HIGH);                                
    digitalWrite(revleft4, LOW);                                                       
  }

  if (distance < 18)
  {
    digitalWrite(fwdright7, LOW);  //Stop                
    digitalWrite(revright6, LOW);
    digitalWrite(fwdleft5, LOW);                                
    digitalWrite(revleft4, LOW);
    delay(500);
    digitalWrite(fwdright7, LOW);      //movebackword         
    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);       
    digitalWrite(revright6, LOW);   
    digitalWrite(revleft4, LOW);                                 
    digitalWrite(fwdleft5, LOW);  
    delay(500);
  }

}
 Read More About Projects Only on Edu-right

No comments:

Post a Comment

Thank You!!

Bottom Ad [Post Page]

| Designed by Colorlib
//]]>