Skip to content

COD nationwide · Isb & Rwp delivery Rs 400

akCircuit
IntermediateRobots & cars 4 hours Arduino Nano

Competition line follower robot

Build a line follower that wins

A light, fast line follower with a 5-sensor IR array, an Arduino Nano, two N20 metal-gear motors and a TB6612 driver, steered by PID code that takes curves smoothly. Built for university robotics competitions.

Every required part

Rs 5,458

Parts list

21 items

  • Every required part in stock
  • Wiring and code included
  • Cash on delivery
Competition line follower robot: Build a line follower that wins
From our reel · 18 Dec 2026

Parts list

Everything you need for the competition line follower robot

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

You also need (most homes have these)

  • A practice trackBlack electrical tape (about 19 mm) on a white chart sheet or floor tiles.

17 items

Rs 5,458

From our reel

Watch it come together in 12 steps

The reel of this build goes live on 18 Dec 2026, 7 pm. Follow us to watch it:

YouTube Instagram Facebook
  1. Step 1: The parts

    1The parts

  2. Step 2: The competition track

    2The competition track

  3. Step 3: Mount the motors

    3Mount the motors

  4. Step 4: IR sensor array up front

    4IR sensor array up front

  5. Step 5: Brain + motor driver

    5Brain + motor driver

  6. Step 6: Wire it up

    6Wire it up

  7. Step 7: Calibrate black & white

    7Calibrate black & white

  8. Step 8: Upload PID code

    8Upload PID code

  9. Step 9: Smooth on the curves

    9Smooth on the curves

  10. Step 10: Full speed!

    10Full speed!

  11. Step 11: Team goes wild

    11Team goes wild

  12. Step 12: Trophy time

    12Trophy time

How it works

What each part does

Each IR sensor shines infrared light down and checks whether it bounces back: white reflects, black absorbs. The five readings tell the Nano where the line is, from far left (−2) to far right (+2).

PID control turns that position error into steering. The P part steers harder the further the line is off-centre, and the D part reacts to how fast the error changes, which damps the wobble. One wheel speeds up while the other slows down, so the robot glides through curves instead of jerking.

When the line disappears, the robot keeps turning the way it last saw it, which brings it back onto sharp bends.

Wiring

Connect it pin by pin

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

Sensors

FromToNote
IR array VCC / GND→ Nano 5V / GND
IR array OUT1 … OUT5 (left to right)→ Nano A0 … A4

Motor driver (TB6612FNG)

FromToNote
STBY→ Nano D4
PWMA / AIN1 / AIN2→ Nano D5 / D7 / D8Left motor
PWMB / BIN1 / BIN2→ Nano D6 / D9 / D10Right motor
A01 / A02→ Left motor
B01 / B02→ Right motor
VCC→ Nano 5V
VM→ Battery + (after the switch)
GND→ Battery − and Nano GND

Power

FromToNote
Battery + → switch→ Nano VIN and TB6612 VM
Battery −→ Nano GND and TB6612 GND

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.
PID line followerBoard: Arduino Nano (ATmega328P; try “Old Bootloader” if the upload fails)
line_follower.ino
const int SENSORS[5] = {A0, A1, A2, A3, A4};  // left to right
const int PWMA = 5, AIN1 = 7, AIN2 = 8;       // left motor
const int PWMB = 6, BIN1 = 9, BIN2 = 10;      // right motor
const int STBY = 4;

const int BASE = 150;          // base speed (0-255)
const float KP = 35, KD = 18;  // tune these on your track

int lineLevel;                 // what a sensor reads over the line (HIGH or LOW)
float lastError = 0;

void motor(int pwmPin, int in1, int in2, int speed) {
  speed = constrain(speed, -255, 255);
  digitalWrite(in1, speed >= 0);
  digitalWrite(in2, speed < 0);
  analogWrite(pwmPin, abs(speed));
}

void setup() {
  for (int pin : SENSORS) pinMode(pin, INPUT);
  pinMode(PWMA, OUTPUT); pinMode(AIN1, OUTPUT); pinMode(AIN2, OUTPUT);
  pinMode(PWMB, OUTPUT); pinMode(BIN1, OUTPUT); pinMode(BIN2, OUTPUT);
  pinMode(STBY, OUTPUT);
  digitalWrite(STBY, HIGH);
  // Switch on with the middle sensor over the line: whatever it reads now means "line".
  lineLevel = digitalRead(SENSORS[2]);
  delay(1000);
}

void loop() {
  const int weights[5] = {-2, -1, 0, 1, 2};
  int sum = 0, count = 0;
  for (int i = 0; i < 5; i++) {
    if (digitalRead(SENSORS[i]) == lineLevel) {
      sum += weights[i];
      count++;
    }
  }

  float error;
  if (count == 0) error = lastError > 0 ? 2.5 : -2.5;  // line lost: keep turning the way it went
  else if (count == 5) error = 0;                       // crossing: go straight
  else error = (float)sum / count;

  float correction = KP * error + KD * (error - lastError);
  lastError = error;
  motor(PWMA, AIN1, AIN2, BASE + correction);
  motor(PWMB, BIN1, BIN2, BASE - correction);
  delay(5);
}

Step by step

Build it

  1. 1

    Lay out the chassis

    Fix the two motor brackets at the back corners of the board, the caster at the front centre, and the sensor bar at the very front, about 3 to 5 mm above the floor.

  2. 2

    Add the electronics

    Stick the two mini breadboards in the middle: the Nano on one, the TB6612 on the other. Put the battery holder and switch between the wheels to keep the weight low and central.

  3. 3

    Wire it

    Follow the tables. Motors go to A01/A02 and B01/B02; all grounds join. The battery feeds both the Nano's VIN and the driver's VM through the switch.

  4. 4

    Upload the code

    Upload with the battery switched off. Then place the robot with the middle sensor exactly over the black line and switch on: it learns what “line” looks like at power-up.

  5. 5

    Tune the PID

    Start with BASE 100, KP 25, KD 0. Raise KP until it follows curves, add KD until the wobble stops, then raise BASE for speed. Change one number at a time.

Tips & troubleshooting

  • If a wheel turns backwards, swap that motor's two wires on the driver.
  • If it turns away from the line, swap the left and right motor wire pairs.
  • Each sensor on the array has a small blue trimmer: adjust it so its LED switches cleanly between white and black.
  • Lighter is faster: trim long wires and keep the battery close to the wheels.

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

Why not an L298N?+

The L298N loses about 2 V and is heavy. The TB6612 loses very little, so the same battery gives faster motors, and it weighs a few grams.

My robot oscillates left and right on straights.+

KP is too high or KD too low. Lower KP a little, then raise KD until the wobble stops.

Can it handle 90° turns?+

Yes, the “line lost” rule turns it back onto sharp corners. For very fast tracks, upgrade to the QTR-8A array in the parts list.

Read next

More projects to build

All projects