Project tutorial
3D-Printed Arduino Obstacle Avoiding Robot

3D-Printed Arduino Obstacle Avoiding Robot © GPL3+

A simple obstacle avoiding robot with 3D-printed and salvaged parts.

  • 4,920 views
  • 0 comments
  • 9 respects

Components and supplies

Necessary tools and machines

3drag
3D Printer (generic)

About this project

Thanks UTSOURCE.net to offer electronic components for this project!

you can check UTSOURCE.net, they deal in all kinds of electronic components, for example, Arduino board, Motor driver, proximity sensors, and many more.

Watch the video! part 1 and part 2


Code

codeC/C++
you can change the pin number accordingly
int trigPin = 12;      // trig pin of HC-SR04
int echoPin = 13;     // Echo pin of HC-SR04


int revleft4 = 5;       //REVerse motion of Left motor
int fwdleft5 = 4;       //ForWarD motion of Left motor
int revright6 = 3;      //REVerse motion of Right motor
int fwdright7 = 2;      //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 dont get proper movements of your robot then alter the pin numbers
  if (distance > 20)            
  {
    digitalWrite(fwdright7, HIGH);                    // move forward
    digitalWrite(revright6, LOW);
    digitalWrite(fwdleft5, HIGH);                                
    digitalWrite(revleft4, LOW);                                                       
  }

  if (distance < 25)
  {
    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);
  }

}
codeC/C++
you can change the code according to your setup
int trigPin = 12;      // trig pin of HC-SR04
int echoPin = 13;     // Echo pin of HC-SR04


int revleft4 = 5;       //REVerse motion of Left motor
int fwdleft5 = 4;       //ForWarD motion of Left motor
int revright6 = 3;      //REVerse motion of Right motor
int fwdright7 = 2;      //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 dont get proper movements of your robot then alter the pin numbers
  if (distance > 20)            
  {
    digitalWrite(fwdright7, HIGH);                    // move forward
    digitalWrite(revright6, LOW);
    digitalWrite(fwdleft5, HIGH);                                
    digitalWrite(revleft4, LOW);                                                       
  }

  if (distance < 25)
  {
    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);
  }

}

Custom parts and enclosures

3D file 1
3D file 2

Schematics

Comments

Similar projects you might like

Obstacle Avoiding Car

Project showcase by Team Adam

  • 30,533 views
  • 4 comments
  • 45 respects

Project 1: 2WD Obstacle Avoiding Robot

Project showcase by HDA Robotics

  • 35,006 views
  • 16 comments
  • 41 respects

Ground-Based Obstacle Avoiding Robot

Project showcase by Xavier Tan

  • 10,458 views
  • 2 comments
  • 31 respects

Tito - Arduino UNO 3D-printed robot

Project tutorial by Camilo Parra Palacio

  • 18,787 views
  • 20 comments
  • 52 respects

Bluetooth Controlled & Obstacle Avoiding Arduino Robot

Project showcase by KureBas Robotics

  • 17,034 views
  • 19 comments
  • 31 respects
Add projectSign up / Login