
Obstacle-avoiding robot car
Build a robot that never crashes
A two-wheel Arduino robot that drives on its own, looks left and right with an ultrasonic sensor on a servo, and turns away before it hits a wall. The classic school and university robotics project.
Every required part
Rs 4,378
Parts list
17 items
- Every required part in stock
- Wiring and code included
- Cash on delivery
From our reel · 23 Nov 2026Parts list
Everything you need for the obstacle-avoiding robot car
Required parts are ticked. Untick anything you already have; the total updates as you go.
Main parts
- Rs 960RequiredOrignal Imported 2wd Smart Robot Car Chassis Kit
Includes the acrylic base, two yellow TT motors, wheels, front caster, power switch, brass standoffs and screws.
1Rs 960 each - Rs 410RequiredMotor Driver Module L298N For Arduino Dual h Bridge Motor Driver
The Arduino cannot power motors directly; the L298N drives both of them forwards and backwards.
1Rs 410 each - Rs 210RequiredHC-SR04 Arduino Ultrasonic Sensor
Measures the distance to walls from 2 cm to about 4 m.
1Rs 210 each - Rs 379RequiredTowerPro Servo Motor SG90 MINI SERVO
Turns the sensor left and right so the robot can pick the clearer side.
1Rs 379 each
Power
- Rs 70Required2x 18650 Cell Battery Holder
Two cells in series give 7.4 V: enough for the motors and, through the L298N, the Arduino.
1Rs 70 each - Rs 400RequiredUniversal Double Slots Li-ion Battery Charger for 18650 Cells 3.7v Rechargeable Lithium Ion Batteries
Untick it if you already have an 18650 charger.
1Rs 400 each
Wiring & mounting
- Rs 130RequiredUSB Cable For Arduino Uno Arduino Mega
Untick it if you have a printer-style USB-B cable.
1Rs 130 each - Rs 170Required20cm Pin To Hole Jumper Wire Dupont Line 40 Pin Male To Female Arduino Jumper Wires
Arduino to the L298N and the sensor.
1Rs 170 each - Rs 170Required20cm Pin To Pin Jumper Wire Dupont Line 40 Pin Arduino Male To Male Jumper Wire
Servo plug to the Arduino.
1Rs 170 each - Rs 119OptionalDouble Sided Tape
Quick way to fix the battery holder and servo to the chassis.
1Rs 119 each
Tools
- Rs 459OptionalSoldering Iron Vhan 40W Solder
Only if your motors arrive without wires soldered on.
1Rs 459 each
Optional upgrades
- Rs 69OptionalHCSR04 ultrasonic sensor Bracket
Holds the HC-SR04 neatly on the servo horn instead of glue or tape.
1Rs 69 each - Rs 350OptionalSensor Shield V5 Expansion Board For Arduino Uno R3
Plugs onto the Uno and gives every pin its own 5 V and GND, so the servo and sensor plug straight in.
1Rs 350 each
11 items
Rs 4,378
From our reel
Watch it come together in 12 steps
Watch the full reel
YouTube
1Gather the parts

2Screw on the gear motors

3Wheels + caster ball

4Mount the battery holder

5Add the L298N motor driver

6Arduino on brass standoffs

7Servo at the front

8Ultrasonic 'eyes' on the servo

9Wire it all up

10Upload the code

11It sees the wall… and turns!

12Your robot is ready
How it works
What each part does
The HC-SR04 sends a short burst of ultrasound and times the echo. The Arduino turns that time into a distance: sound travels about 1 cm every 29 microseconds, there and back.
While the path ahead is clear, both motors drive forward. When a wall comes closer than 25 cm, the robot stops, backs off a little, turns the servo to look right and left, and spins towards the side with more space.
The L298N sits between the Arduino and the motors. The Arduino only sends small direction and speed signals; the L298N switches the battery current to the motors. Its built-in 5 V regulator also powers the Arduino from the same battery.
Wiring
Connect it pin by pin
Motor driver (L298N)
| From | To | Note |
|---|---|---|
| L298N ENA | → Arduino D5Remove the ENA jumper cap first | |
| L298N IN1 | → Arduino D7 | |
| L298N IN2 | → Arduino D8 | |
| L298N IN3 | → Arduino D11 | |
| L298N IN4 | → Arduino D12 | |
| L298N ENB | → Arduino D6Remove the ENB jumper cap first | |
| L298N OUT1 / OUT2 | → Left motor | |
| L298N OUT3 / OUT4 | → Right motor |
Sensor and servo
| From | To | Note |
|---|---|---|
| HC-SR04 VCC | → Arduino 5V | |
| HC-SR04 TRIG | → Arduino D9 | |
| HC-SR04 ECHO | → Arduino D10 | |
| HC-SR04 GND | → Arduino GND | |
| Servo orange (signal) | → Arduino D3 | |
| Servo red | → Arduino 5V | |
| Servo brown | → Arduino GND |
Power
| From | To | Note |
|---|---|---|
| Battery + (red) | → Chassis switch, then L298N 12V terminal | |
| Battery − (black) | → L298N GND terminal | |
| L298N 5V terminal | → Arduino 5VKeep the L298N's 5V-enable jumper on | |
| L298N GND terminal | → Arduino GNDAll grounds must be connected |
The code
Ready-to-upload Arduino code
#include <Servo.h>
const int ENA = 5, IN1 = 7, IN2 = 8; // left motor
const int ENB = 6, IN3 = 11, IN4 = 12; // right motor
const int TRIG = 9, ECHO = 10;
const int SERVO_PIN = 3;
const int SPEED = 170; // 0-255: lower it if the robot is too fast
const int STOP_CM = 25; // turn when something is closer than this
Servo eyes;
long distanceCm() {
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
long us = pulseIn(ECHO, HIGH, 30000); // give up after 30 ms (about 5 m)
if (us == 0) return 400; // no echo: nothing in range
return us / 58;
}
// left and right speed from -255 (full reverse) to 255 (full forward)
void drive(int left, int right) {
digitalWrite(IN1, left > 0);
digitalWrite(IN2, left < 0);
digitalWrite(IN3, right > 0);
digitalWrite(IN4, right < 0);
analogWrite(ENA, abs(left));
analogWrite(ENB, abs(right));
}
long lookAt(int angle) {
eyes.write(angle);
delay(350);
return distanceCm();
}
void setup() {
pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
eyes.attach(SERVO_PIN);
eyes.write(90); // look straight ahead
delay(1000);
}
void loop() {
if (distanceCm() > STOP_CM) {
drive(SPEED, SPEED);
delay(50);
return;
}
drive(-SPEED, -SPEED); // back off a little
delay(300);
drive(0, 0);
long right = lookAt(20);
long left = lookAt(160);
eyes.write(90);
delay(200);
if (left > right) drive(-SPEED, SPEED); // spin left
else drive(SPEED, -SPEED); // spin right
delay(400);
drive(0, 0);
}Step by step
Build it
- 1
Build the chassis
Screw the two yellow gear motors to the acrylic base with the long screws from the kit, push the wheels on, and fix the caster ball at the front with the brass standoffs.
- 2
Fit the battery and driver
Stick or screw the 2 × 18650 holder at the back and the L298N in the middle. Run the motor wires to OUT1/OUT2 (left) and OUT3/OUT4 (right).
- 3
Mount the Arduino
Fix the Uno on the remaining standoffs so its USB port faces the back; you will plug the cable in often.
- 4
Add the servo and the eyes
Fix the servo at the front, centre its horn, then mount the HC-SR04 on the horn with the bracket (or double-sided tape) facing forward.
- 5
Wire everything
Follow the wiring tables. Take the two jumper caps off ENA and ENB on the L298N, but leave its 5V-enable jumper on. Double-check that every GND is connected together.
- 6
Upload the code
Switch the battery off, connect the USB cable, select Arduino Uno and the right COM port in the Arduino IDE, and upload the sketch.
- 7
Test on the floor
Unplug the USB cable, put the robot on the floor and switch on. It should drive forward and turn away about 25 cm before a wall.
Tips & troubleshooting
- If a wheel spins backwards, swap that motor's two wires on the L298N.
- If the robot turns towards the wall instead of away, the servo is mounted the other way round: swap the 20 and 160 in the lookAt() lines.
- Charge both 18650 cells fully before testing. Weak cells make the Arduino reset whenever the motors start.
- Switch the battery off while the USB cable is plugged in.
- Clone Unos use the CH340 USB chip. If the COM port does not appear, install the CH340 driver once.
Stuck on wiring or code?
Send us a photo of your build on WhatsApp. We are makers too, and we will help you get it working.
FAQ
Questions people ask
Can I use AA batteries instead of 18650 cells?+
The kit's 4 × AA box gives only 6 V, which is too little once the L298N drops about 2 V. The motors crawl and the Arduino resets. Two 18650 cells (7.4 V) are the reliable choice.
Is this good for a final year project?+
It is a great first robot and a common school or 1st-year project. For an FYP, add Bluetooth control, a line sensor or a camera on top of this base.
Do I need to solder?+
Usually not. Only if your gear motors arrive without wires; then you need two quick solder joints per motor.
Read next
- FYP Electronics Parts List: How to Plan, Budget and Buy Your Final Year Project PartsA step-by-step method for Pakistani students to plan final-year-project electronics: block diagram, compatibility checks, power budget and two complete parts lists with live prices.
- Arduino Kya Hai? Arduino Meaning in Urdu, Kaunsa Board Lein aur Pehla ProjectArduino kya hai, is se kya ban sakta hai, Uno, Nano ya Mega mein se kaunsa lein, shuru ke parts aur pehla LED blink project: aasaan Roman Urdu mein, Pakistan ki live qeematon ke sath.
- Servo Motor Price in Pakistan: SG90 vs MG90S vs MG996RServo motor prices in Pakistan, the real difference between SG90, MG90S and MG996R, 180° and 360° servos, how to wire and power them with an Arduino, and the mistakes that strip gears.
More projects to build
All projects


Pick-and-place robot arm
Build a robot arm that picks things up
All parts
Rs 6,508
3 to 4 hours
11 items





















