Obstacle Avoiding Robot
1773 7
Nilotpal Basak

Obstacle Avoiding Robot

An Obstacle Avoidance Robot is an intelligent robot, which can automatically sense and overcome...

Description:-

An Obstacle Avoidance Robot is an intelligent robot, which can automatically sense and overcome obstacles on its path. It contains of a Microcontroller(arduino uno) to process the data, and Ultrasonic sensors to detect the obstacles on its path. Obstacle avoidance is one of the most important aspects of mobile robotics. Without it robot movement would be very restrictive and fragile. This project also presents a dynamic steering algorithm which ensures that the robot does n't have to stop in front of an obstacle which allows robot to navigate smoothly in an unknown environment, avoiding collisions. Almost all navigation robot demands the some sort of obstacle detection, hence obstacle avoidance strategy is of most importance. Obstacle Avoidance Robot has a vast field of application. They can be used as services robots, for the purpose of household work and so many other indoor applications. Equally they have great importance in scientific exploration and emergency rescue, there may be places that are dangerous for humans or even impossible for humans to reach directly, then we should use robots to help us. In those challenging environments, the robots need to gather information about their surroundings to avoid obstacles. Nowadays, even in ordinary environments, people require that robots to detect and avoid obstacles. For example, an industrial robot in a factory is expected to avoid workers so that it won’t hurt them. In conclusion, obstacle avoidance is widely researched and applied in the world, and it is probable that most robots in the future should have obstacle avoidance function. Thanks for reading my idea.

Project Used Hardware

Arduino uno, motor driver, ultrasonic sensor, gear motor, servo motor, 9v battery, wheels, jumper wires.

Project Used Software

Arduino

Project Hardware Software Selection

HARDWARE :-

->Arduino uno - It is a microcontroller which gives comand to the robot.

->Motor driver - It helps to control motor attached in robot , it is connected with arduino.

->Ultrasonic sensor - It senses any obstacle in front of the robot.

->Servo motor - It turns left and right to the ultrasonic sensor or we can say that it helps the robot to sense obstacle in left and right direction.

->Gear motor - It hels the robot to move in all the direction (forward, backward, left, right).

->Wheels - It is conected in gear motor. ->9v battery - It gives the power to the robot.

->Jumper wire - It connect all hardware with each other to give signal or current.

SOFTWARE :- Arduino - It is a software which helps to program the microcontroller (arduino uno).

Circuit Diagram

Arduino uno, motor driver, ultrasonic sensor, gear motor, servo motor, 9v battery, wheels, jumper wires all these hardware are connected with each other.

Obstacle Avoiding Robot Circuit Diagram

Code

#include <Servo.h>          //Servo motor library. This is standard library
#include <NewPing.h>        //Ultrasonic sensor function library. You must install this library

//our L298N control pins
const int LeftMotorForward = 7;
const int LeftMotorBackward = 6;
const int RightMotorForward = 4;
const int RightMotorBackward = 5;

//sensor pins
#define trig_pin A1 //analog input 1
#define echo_pin A2 //analog input 2

#define maximum_distance 200
boolean goesForward = false;
int distance = 100;

NewPing sonar(trig_pin, echo_pin, maximum_distance); //sensor function
Servo servo_motor; //our servo name


void setup(){

  pinMode(RightMotorForward, OUTPUT);
  pinMode(LeftMotorForward, OUTPUT);
  pinMode(LeftMotorBackward, OUTPUT);
  pinMode(RightMotorBackward, OUTPUT);
  
  servo_motor.attach(10); //our servo pin

  servo_motor.write(115);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
}

void loop(){

  int distanceRight = 0;
  int distanceLeft = 0;
  delay(50);

  if (distance <= 20){
    moveStop();
    delay(300);
    moveBackward();
    delay(400);
    moveStop();
    delay(300);
    distanceRight = lookRight();
    delay(300);
    distanceLeft = lookLeft();
    delay(300);

    if (distance >= distanceLeft){
      turnRight();
      moveStop();
    }
    else{
      turnLeft();
      moveStop();
    }
  }
  else{
    moveForward(); 
  }
    distance = readPing();
}

int lookRight(){  
  servo_motor.write(50);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
}

int lookLeft(){
  servo_motor.write(170);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
  delay(100);
}

int readPing(){
  delay(70);
  int cm = sonar.ping_cm();
  if (cm==0){
    cm=250;
  }
  return cm;
}

void moveStop(){
  
  digitalWrite(RightMotorForward, LOW);
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);
  digitalWrite(LeftMotorBackward, LOW);
}

void moveForward(){

  if(!goesForward){

    goesForward=true;
    
    digitalWrite(LeftMotorForward, HIGH);
    digitalWrite(RightMotorForward, HIGH);
  
    digitalWrite(LeftMotorBackward, LOW);
    digitalWrite(RightMotorBackward, LOW); 
  }
}

void moveBackward(){

  goesForward=false;

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
  
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorForward, LOW);
  
}

void turnRight(){

  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorForward, LOW);
  
  delay(500);
  
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
 
  
  
}

void turnLeft(){

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);

  delay(500);
  
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
}