In this Arduino tutorial, you will learn how to design an obstacle avoiding 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 avoiding robot, the robotic car is autonomous, you do not have to control the car yourself. Once you’ve uploaded the the Arduino code 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.
Design materials – Obstacle Avoiding Robot
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 ultrasonic sensor that collects information about obstacles in front of the car. See image below.

- Arduino board
- L298 motor driver
- Three 3.7V lithium ion batteries
- Some jumper wires
- Breadboard cut
- One caster wheel
- Two DC Motor With Wheel
- Switch
- HC-SR04 Ultrasonic sensor
Circuit diagram – Obstacle Avoiding 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.
Arduino code
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