Skip to content

COD nationwide · Isb & Rwp delivery Rs 400

akCircuit
BeginnerRobots & cars 3 to 4 hours Arduino Uno

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
Obstacle-avoiding robot car: Build a robot that never crashes
From our reel · 23 Nov 2026

Parts list

Everything you need for the obstacle-avoiding robot car

Every part below is in our catalogue at today's price, so the total is what you pay. Required parts are ticked; optional upgrades are not.

Required parts are ticked. Untick anything you already have; the total updates as you go.

Main parts

Power

Wiring & mounting

Tools

Optional upgrades

11 items

Rs 4,378

From our reel

Watch it come together in 12 steps

Watch the full reel

YouTube
  1. Step 1: Gather the parts

    1Gather the parts

  2. Step 2: Screw on the gear motors

    2Screw on the gear motors

  3. Step 3: Wheels + caster ball

    3Wheels + caster ball

  4. Step 4: Mount the battery holder

    4Mount the battery holder

  5. Step 5: Add the L298N motor driver

    5Add the L298N motor driver

  6. Step 6: Arduino on brass standoffs

    6Arduino on brass standoffs

  7. Step 7: Servo at the front

    7Servo at the front

  8. Step 8: Ultrasonic 'eyes' on the servo

    8Ultrasonic 'eyes' on the servo

  9. Step 9: Wire it all up

    9Wire it all up

  10. Step 10: Upload the code

    10Upload the code

  11. Step 11: It sees the wall… and turns!

    11It sees the wall… and turns!

  12. Step 12: Your robot is ready

    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

Switch the power off while you wire, and connect every GND together unless the table says otherwise.

Motor driver (L298N)

FromToNote
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

FromToNote
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

FromToNote
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

Copy it into the Arduino IDE, change the settings at the top if your build needs it, and upload.
Obstacle-avoiding robotBoard: Arduino UnoServo (built in)
obstacle_robot.ino
#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. 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. 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. 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. 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. 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. 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. 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.

Ask on WhatsApp

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

More projects to build

All projects