Project showcase

Obstacle Avoiding Robot © GPL3+

The Obstacle Avoiding Robot is very easy to make; Its head turns to look left and right and chooses the longer side to drive in!

  • 1,373 views
  • 3 comments
  • 12 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

About this project

How it's Made

For this project, I made my own design using a CAD Software. Then I printed this design on a CNC Machine. The material used is 5mm PVC. I used this material because it's very light; strong enough to support the weight of the components. It's cheap and you can easily find it. Since I don't have a 3d printer, I made the body out of 3 pieces and also bent some of the pieces like the HC-SR04 Ultasonic sensor holder and the motor support in the body.

Custom parts and enclosures

hc-sr04_ultrasonic_sensor_holder_1jBuLNg8mn.DXF
hc-sr04_ultrasonic_sensor_holder_1jBuLNg8mn.DXF
servo_motor_support_bdaXB0p5Kd.DXF
servo_motor_support_bdaXB0p5Kd.DXF
body_(final)_4qEIHPBGIs.DXF
body_(final)_4qEIHPBGIs.DXF

Schematics

Obstacle Avoiding Robot Circuit
Here you can find the schematic that I created for this project.

As you can see, this schematic is very easy:

9v Battery connect to the Motor Shield

The Servo motor connect to Servo1 on the Motor Shield

Left Motor connect to M2 on the Motor Shield

Right Motor connect to M1 on the Motor Shield

The HC-SR04:

VCC connect to the Arduino +5V

GND connect to the Arduino Ground

Trig connect to the Arduino Analog 10

Echo connect to the Arduino Analog 11
Rotating head obstacle avoising robot bb plq43tzw4x

Code

Rotating_Head_Obstacle_Avoiding_Robot_Code.inoArduino
#include <AFMotor.h>      
#include <Servo.h>              
#include <NewPing.h>      

#define TRIG_PIN A10 
#define ECHO_PIN A11 
#define MAX_DISTANCE 300 
#define MAX_SPEED 100
#define MAX_SPEED_OFFSET 40 
#define COLL_DIST 35 
#define TURN_DIST COLL_DIST+15 
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE); 
 
AF_DCMotor leftMotor(2, MOTOR12_8KHZ); 
AF_DCMotor rightMotor(1, MOTOR12_8KHZ); 
Servo myservo;  

int leftDistance, rightDistance; 
int curDist = 0;
String motorSet = "";
int speedSet = 0;


void setup() {
  myservo.attach(10);   
  myservo.write(90); 
  delay(1000); 
 }

void loop() {
  myservo.write(90);  
  delay(90);
  curDist = readPing();  
  if (curDist < COLL_DIST) {changePath();}  
  moveForward();
  delay(500);
 }


void changePath() {
  moveStop();   
  myservo.write(10);  
    delay(500);
    leftDistance = readPing(); 
    delay(500);
    myservo.write(180);  
    delay(700);
    rightDistance = readPing(); 
    delay(500);
    myservo.write(90); 
    delay(100);
    compareDistance();
  }

  
void compareDistance()   
{
  if (leftDistance>rightDistance) 
  {
    turnLeft();
  }
  else if (rightDistance>leftDistance) 
  {
    turnRight();
  }
   else 
  {
    turnAround();
  }
}

int readPing() { 
  delay(70);   
  unsigned int uS = sonar.ping();
  int cm = uS/US_ROUNDTRIP_CM;
  return cm;
}

void moveStop() {leftMotor.run(RELEASE); rightMotor.run(RELEASE);}  

void moveForward() {
    motorSet = "FORWARD";
    leftMotor.run(FORWARD);      
    rightMotor.run(FORWARD); 
    for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2)    
    
  {
    leftMotor.setSpeed(100);
    rightMotor.setSpeed(100); 
    delay(5);
  }
}

void turnRight() {
  motorSet = "RIGHT";
  leftMotor.run(FORWARD);  
  rightMotor.run(BACKWARD);   
  rightMotor.setSpeed(speedSet+MAX_SPEED_OFFSET);      
  delay(350);      
  motorSet = "FORWARD";
  leftMotor.run(FORWARD);      
  rightMotor.run(FORWARD);
        
}  

void turnLeft() {
  motorSet = "LEFT" ;
  leftMotor.run(BACKWARD);      
  leftMotor.setSpeed(speedSet+MAX_SPEED_OFFSET);    
  rightMotor.run(FORWARD);     
  delay(350);  
  motorSet = "FORWARD";
  leftMotor.run(FORWARD);      
  rightMotor.run(FORWARD);     
 
}  

void turnAround() {
  motorSet = "TURNAROUND";
  leftMotor.run(FORWARD);      
  rightMotor.run(BACKWARD);    
  rightMotor.setSpeed(speedSet+MAX_SPEED_OFFSET);      
  
  delay(700); 
  motorSet = "FORWARD";
  leftMotor.run(FORWARD);      
  rightMotor.run(FORWARD);
       
}  

Comments

Similar projects you might like

Magic Lamp

by Nekhil ravi

  • 1,176 views
  • 3 comments
  • 12 respects

PuzzleBox

Project tutorial by Arduino

  • 464 views
  • 0 comments
  • 4 respects

Arduino MKR GSM 1400 and DTMF

by Arduino_Genuino

  • 4,272 views
  • 0 comments
  • 9 respects

Love You Pillow

Project tutorial by Arduino

  • 2,921 views
  • 0 comments
  • 5 respects

Arduino Yun Controller

Project showcase by TATCO Inc

  • 278 views
  • 0 comments
  • 3 respects
Add projectSign up / Login