Project showcase
Obstacle avoiding robot

Obstacle avoiding robot © GPL3+

In this project, I built an obstacle avoiding robot using an ultrasonic sensor and an Arduino microcontroller.

  • 13,041 views
  • 5 comments
  • 7 respects

Components and supplies

Apps and online services

About this project

For any problem contact me.

Code

robot software Arduino
#define echopin  8 // echo pin
#define trigpin 9 // Trigger pin


int maximumRange = 30;
long duration, distance;

void setup() {
  Serial.begin (9600);
  pinMode (trigpin, OUTPUT);
  pinMode (echopin, INPUT );
  pinMode (4, OUTPUT);
  pinMode (5, OUTPUT);
  pinMode (13, OUTPUT);
  pinMode (6, OUTPUT);
  pinMode (7, OUTPUT);
}

void loop ()
{

  {
    digitalWrite(trigpin,LOW);
    delayMicroseconds(2);
    
    digitalWrite(trigpin,HIGH);
    delayMicroseconds(10);
    
    duration=pulseIn (echopin,HIGH);
    
    distance= duration/58.2;
    delay (50);
    Serial.println(distance);
  }
  
  if (distance >= 30 ){
    digitalWrite(4,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(6,LOW);
    digitalWrite(7,LOW);
    delay (200);
  }
  
  else if (distance >=15 && distance <= 25) {
    digitalWrite (4,HIGH);
    digitalWrite (5,LOW);
    digitalWrite (6,LOW);
    digitalWrite (7,LOW);
    delay (1000);
  }
 else if (distance < 15){
   digitalWrite (4, LOW);
   digitalWrite (5, LOW);
   digitalWrite (6,HIGH);
   digitalWrite (7,HIGH);
   delay (1000);
   digitalWrite (4,LOW);
   digitalWrite (5,HIGH);
   digitalWrite (6,LOW);
   digitalWrite (7, LOW);
   delay (1000);
   
     
 }

}
servo softwareArduino
#include <Servo.h>
 
Servo myservo;
 
int pos = 0;
 
void setup()
{
  myservo.attach(9);
}
 
void loop()
{
  for(pos = 0; pos < 180; pos += 1)
  {
    myservo.write(pos);
    delay(15);
  }
  for(pos = 180; pos>=1; pos-=1)
  {
    myservo.write(pos);
    delay(15);
  }
}

Schematics

obstacle robot
Obstacle%20robot
servo control
Untitled%20sketch bb

Comments

Similar projects you might like

Ground-Based Obstacle Avoiding Robot

Project showcase by Xavier Tan

  • 6,106 views
  • 1 comment
  • 21 respects

Project 1: 2WD Obstacle Avoiding Robot

Project showcase by HDA Robotics

  • 12,075 views
  • 9 comments
  • 25 respects

Obstacle Avoiding Car

Project showcase by Adam

  • 7,070 views
  • 2 comments
  • 20 respects

Arduino Obstacle Avoidance Robot with Ultrasonic HC-SR04

Project showcase by Jorge Rancé

  • 11,827 views
  • 7 comments
  • 28 respects

Transformer's Baby: Arduino Avoiding Obstacle Robot

Project tutorial by diyProjectsStepByStep

  • 2,969 views
  • 0 comments
  • 13 respects
Add projectSign up / Login