Drives on its own and steers around anything in its path.
Built and tested by Anju.A · Industrial Robotics Institute

A classic autonomous robot that never bumps into things. An HC-SR04 ultrasonic sensor at the front measures the distance ahead; when something is within 20 cm, the Arduino stops, reverses and turns right, then carries on forward.
| Component | Qty |
|---|---|
| Arduino Uno | 1 |
| Ultrasonic Sensor (HC-SR04) | 1 |
| L298N Motor Driver Module | 1 |
| BO Gear Motors | 2 |
| Robot Chassis with Wheels | 1 |
| 18650 Lithium Cells | 2 |
| 2-cell 18650 Battery Holder with Switch | 1 |
| Jumper Wires | As needed |
| From | Connect to |
|---|---|
| Ultrasonic VCC | 5V |
| Ultrasonic GND | GND |
| Ultrasonic TRIG | Pin 2 |
| Ultrasonic ECHO | Pin 3 |
| L298N IN1 (left motor) | A0 |
| L298N IN2 (left motor) | A1 |
| L298N IN3 (right motor) | A2 |
| L298N IN4 (right motor) | A3 |
| Battery + | L298N 12V |
| Battery − | L298N GND |
| Arduino GND | L298N GND |
Complete, tested Arduino C++ code for this project. Copy it into Arduino IDE and upload it to the Arduino Uno.
int trigPin = 2;
int echoPin = 3;
int LM1 = A0;
int LM2 = A1;
int RM1 = A2;
int RM2 = A3;
long duration;
int distance;
int getDistance()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
return duration * 0.034 / 2;
}
void forward() { digitalWrite(LM1, HIGH); digitalWrite(LM2, LOW); digitalWrite(RM1, HIGH); digitalWrite(RM2, LOW); }
void backward() { digitalWrite(LM1, LOW); digitalWrite(LM2, HIGH); digitalWrite(RM1, LOW); digitalWrite(RM2, HIGH); }
void right() { digitalWrite(LM1, HIGH); digitalWrite(LM2, LOW); digitalWrite(RM1, LOW); digitalWrite(RM2, HIGH); }
void stopRobot() { digitalWrite(LM1, LOW); digitalWrite(LM2, LOW); digitalWrite(RM1, LOW); digitalWrite(RM2, LOW); }
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
}
void loop()
{
distance = getDistance();
if (distance < 20)
{
stopRobot();
delay(500);
backward();
delay(1000);
right();
delay(1000);
}
else
{
forward();
}
}A classic autonomous robot that never bumps into things. An HC-SR04 ultrasonic sensor at the front measures the distance ahead; when something is within 20 cm, the Arduino stops, reverses and turns right, then carries on forward.
You need: Arduino Uno (1), Ultrasonic Sensor (HC-SR04) (1), L298N Motor Driver Module (1), BO Gear Motors (2), Robot Chassis with Wheels (1), 18650 Lithium Cells (2), 2-cell 18650 Battery Holder with Switch (1), Jumper Wires. Software: Arduino IDE.
Yes. It is rated beginner and takes about 2–3 hours to build, using the Arduino Uno. The guide on this page explains every connection and step.
The complete, tested Arduino C++ code is free on this page. Copy it into Arduino IDE and upload it to the board.
Yes. IRI sells a kit with the parts for this project (PRJ-098). Message IRI on WhatsApp at +91 86060 82634 for the kit price and delivery details.