DIY Arduino Projects For BeginnersRobotics

Obstacle avoidance robot

In this Arduino tutorial, you will learn how to design an obstacle avoidance robot. Previously, I made a tutorial on how to design RC car with a smartphone. The RC robotic car is controlled with a smartphone. You have to download the remoteXY application on your smartphone, then you connect the RC car to your phone via Bluetooth.
However, for the obstacle avoidance robot, the robotic car is autonomous, you do not have to control the car yourself. Once you’ve uploaded the sketch to the Arduino board and turn on the car, the robot car will move on its own, and avoid colliding with any obstacle on its course.

obstacle avoidance robot

Design materials

The same material used to make the chassis in the previous RC car is what I used again in this one but with a little finetuning. The only difference is that I added a wooden stem to the front of the car to hold the ultra-sonic sensor that collects information about obstacles in front of the car. See image below.

obstacle avoidance robot
Figure 1: Obstacle avoidance robot
  • Arduino board
  • L298 motor driver
  • Three 3.7V lithium ion batteries
  • Some jumper wires
  • Breadboard cut
  • One caster wheel
  • Two gear motors
  • Two wheels
  • Switch
  • Ultra sonic sensor

the circuit diagram of the design is below

obstacle avoidance robot
Figure 2: Obstacle avoidance robot

Connect the parts as shown in the circuit diagram and assemble the parts on the body of the car as shown in figure 1 above.

Upload the Arduino code shown below to the Arduino board.

int trigPin = 9;      // trig pin of HC-SR04
int echoPin = 10;     // Echo pin of HC-SR04

int out_1 = 4;        
  int out_2 = 5;       
    int out_3 = 6;      
      int out_4 = 7;      
long duration;
 int distance;

void setup() {
  
  delay(random(500,2000));  
  
  pinMode(out_1, OUTPUT);      
    pinMode(out_2, OUTPUT);
      pinMode(out_3, OUTPUT);
        pinMode(out_4, OUTPUT);
           pinMode(trigPin, OUTPUT);         
             pinMode(echoPin, INPUT);          
   
}

void loop() {

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);   
  digitalWrite(trigPin, HIGH);     
  delayMicroseconds(10);
   digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH); 
  distance = duration*0.034/2;   
  delay(10);

   
    
  if (distance >= 50)            
  {
    digitalWrite(out_1, HIGH);                    
     digitalWrite(out_2, LOW);
       digitalWrite(out_3, HIGH);                                
         digitalWrite(out_4, LOW);    
                                              
  }

  if (distance < 50)
  {
  digitalWrite(out_1, LOW);                
    digitalWrite(out_2, LOW);
    digitalWrite(out_3, HIGH);                                
    digitalWrite(out_4, LOW);  
    delay(300);  
    
   
  }
  }
    

This code is a very simple one, you can adjust the code to give your car a different motive style. I will be making more robotic projects like this, so endeavor to subscribe to my channel on YouTube, you don’t miss any my tutorial.

See these other robotic tutorials

Arduino RC robotic car with arduino
Arduino robotic gripper
Arduino Bluetooth controlled scrolling text display
Arduino password enabled door lock

Leave a Reply

Your email address will not be published. Required fields are marked *