All projects
RoboticsIntermediate 4 hours

Line Follower Robot

Classic robotics starter project. Two IR sensors detect the line, and an L298N motor driver controls two DC motors.

Required components

  • Arduino UNO
  • 2× IR Sensors
  • L298N Motor Driver
  • 2× DC Motors
  • Robot Chassis
  • 9V Battery
Get this kit

Circuit diagram

L298N receives 9V battery power and outputs to two DC motors. Arduino controls L298N via 4 digital pins. IR sensors send digital HIGH/LOW to A0 and A1.

Interactive 3D circuit viewer coming in the Virtual Lab.

Step-by-step guide

  1. 1

    Assemble chassis with motors and wheels.

  2. 2

    Mount IR sensors at the front, 1cm above ground.

  3. 3

    Wire L298N: IN1–IN4 to pins 2,3,4,5. Motors to OUT1–4.

  4. 4

    Connect IR sensor outputs to A0 (left) and A1 (right).

  5. 5

    Power the L298N from a 9V battery, Arduino from the 5V regulator.

  6. 6

    Upload code and place on a black-tape track.

Code

const int L=A0, R=A1;
void setup() { for (int p=2;p<=5;p++) pinMode(p, OUTPUT); }
void drive(int l, int r) {
  digitalWrite(2, l>0); digitalWrite(3, l<0);
  digitalWrite(4, r>0); digitalWrite(5, r<0);
}
void loop() {
  int l = digitalRead(L), r = digitalRead(R);
  if (!l && !r) drive(1,1);
  else if (l && !r) drive(0,1);
  else if (!l && r) drive(1,0);
  else drive(0,0);
}

Need help?

Stuck on a step?

Ask the Botix AI Tutor — it knows this project end-to-end.

Open AI Tutor