Project showcase
Obstacle Avoiding Robot- Compact

Obstacle Avoiding Robot- Compact © Apache-2.0

It's a obstacle avoiding robot which uses HC-SRF-05 for obstacle detection. Best of its class, compact, rechargeable and precisely made.

  • 17 views
  • 0 comments
  • 0 respects

Components and supplies

Ard nano
Arduino Nano R3
You can use any other arduino board, probably an arduino UNO if you are new.
×1
51gzz5eu9pl. sx425
Ultrasonic Sensor - HC-SR04 (Generic)
I am currently using a HC-SRF-05 now because its more precise. if you want to upgrade to same you can do it, you don't need to change the code.
×1
09670 01
SparkFun Dual H-Bridge motor drivers L298
This is the motor driver I am using. its best because its small and compact for my compact robot.
×1
BO motor with wheel
you can use from 60 rpm to 150 rpm.
×1
18650 lithium Ion battery
I am using 4 18650 lithium ion cell connected in series. Buy from the link to get some discount
×1
Castor wheel
Buy from the link and get discount.
×1
Sg90 servo motor 180 degrees sg90 micro
SG90 Micro-servo motor
×1
E switch eg1218 image 75px
Slide Switch
×1
11026 02
Jumper wires (generic)
×1

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

Its very easy project, all you need to do is get the components together. The only skill required here might be some basic skills of soldering. Plug in the robots after assembly and upload the code. You can get a detailed tutorial on my blog too.

Watch the video for more:

Code

Code for Autonomous RobotArduino
Just copy and paste it on to your Arduino IDE or download it. Don't forget to include or install the NEwping library
//This is the code for the robot
// make sure to  include the NewPing and Servo Libraries  before uploading else it will show error

#include <NewPing.h>
#include <Servo.h>
#define TRIG_PIN A4
#define ECHO_PIN A5
#define MAX_DISTANCE 200
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);
Servo myservo;

boolean goesForward = false;
int distance = 100;
int speedSet = 0;

//Motor A
const int motorPin1  = 11;
const int motorPin2  = 10;
//Motor B
const int motorPin3  = 6;
const int motorPin4  = 5;


void setup()
{


  myservo.attach(9);
  myservo.write(115);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  
}


void loop()
{

  int distanceR = 0;
  int distanceL =  0;
  delay(40);

  if (distance <= 15)  // Adjust the value 15 accordingly to let your robot stop at desired distance from the robot
  {
    moveStop();
    delay(100);
    moveBackward();
    delay(600);
    moveStop();
    delay(200);
    distanceR = lookRight();
    delay(200);
    distanceL = lookLeft();
    delay(200);
    if (distanceR >= distanceL)
    {
      turnRight();
      moveStop();
    } else
    {
      turnLeft();
      moveStop();
    }
  }
  
  else
  {
    moveForward();
  }
  distance = readPing();
}





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

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

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



}


void moveStop() {
  analogWrite(motorPin1, 0);
  analogWrite(motorPin2, 0);
  analogWrite(motorPin3, 0);
  analogWrite(motorPin4, 0);
}


void moveForward() {
  analogWrite(motorPin1, 255);   //the value 0 - 255 here is a PWM so you can change it to increase or decrease your motor speed
  analogWrite(motorPin2, 0);
  analogWrite(motorPin3, 235);    // this one too is the PWM for other motor
  analogWrite(motorPin4, 0);

}
void moveBackward() {

  analogWrite(motorPin1, 0);
  analogWrite(motorPin2, 255);
  analogWrite(motorPin3, 0);
  analogWrite(motorPin4, 255);

}
void turnRight() {
  analogWrite(motorPin1, 255);
  analogWrite(motorPin2, 0);
  analogWrite(motorPin3, 0);
  analogWrite(motorPin4, 255);
  delay(500);
  moveForward();

}

void turnLeft() {
  analogWrite(motorPin1, 0);
  analogWrite(motorPin2, 255);
  analogWrite(motorPin3, 255);
  analogWrite(motorPin4, 0);
  delay(500);
  moveForward();
}

Schematics

Wiring diagram
Just connect the wire as shown. You can connect a switch in between the battery and the l298 circuit.
Wiring diagram of robot pyrfmw4kpc

Comments

Similar projects you might like

Ground-Based Obstacle Avoiding Robot

Project showcase by Xavier Tan

  • 5,312 views
  • 1 comment
  • 20 respects

Obstacle Avoiding Car

Project showcase by Adam

  • 6,772 views
  • 2 comments
  • 20 respects

Project 1: 2WD Obstacle Avoiding Robot

Project showcase by HDA Robotics

  • 10,987 views
  • 8 comments
  • 24 respects

Robotic Car controlledover Bluetooth with Obstacle Avoidance

Project showcase by S.Ranjith Reddy

  • 10,224 views
  • 8 comments
  • 18 respects

Arduino Obstacle Avoidance Robot with Ultrasonic HC-SR04

Project showcase by Jorge Rancé

  • 11,980 views
  • 8 comments
  • 28 respects
Add projectSign up / Login