Skip to content
Lab404 Electronics
Build Guide

How to Build a Line Follower Robot in Lebanon: Complete Build Guide

Published 18 June 2026 · By Lab404 Electronics

The line follower is where most robotics engineers start — and for good reason. It covers the full stack of a real robotics project: sensors reading the environment, a microcontroller making decisions, actuators responding in real time, and a feedback loop tying them together. It's also the project most likely to be assigned in a first-year engineering lab, used in a local competition, or built over a weekend to prove out a concept. This guide is the complete walkthrough for how to build a line follower robot in Lebanon, including a full parts list you can source locally, wiring logic, code structure, and the mistakes that waste the most time on a first build.

How a Line Follower Robot Works

The operating principle is straightforward: two IR sensors mounted at the front of the robot point downward at the surface. A black line on a white surface (or white on black) reflects IR light differently — white reflects most of it back, black absorbs most of it. The sensors output a digital HIGH or LOW depending on what surface they're over.

The microcontroller reads both sensors continuously and uses the combination of readings to determine what the robot should do. Both sensors on white (line between them): go straight. Left sensor on black (drifted right): turn left. Right sensor on black (drifted left): turn right. Both sensors on black: stop or handle based on last known state. The microcontroller sends signals to a motor driver, which amplifies them to drive two DC gear motors. That's the complete system: sense, decide, act.

Complete Parts List

Every component below is available locally through Lab404 Electronics. Reference the SKUs when requesting a quote to avoid substitution or back-and-forth on specifications.

IR Obstacle / Line Sensors × 2

These modules include an IR emitter and phototransistor with an onboard comparator and sensitivity potentiometer. The digital output goes directly to a microcontroller GPIO pin. Two sensors are the minimum for basic line following; three or five sensors enable smoother PID control and junction detection. Start with two for a first build.

LB-IR-SENS-01

Arduino Uno or Arduino Nano

Either board works. The Uno is easier to wire during prototyping; the Nano fits more compactly on a small chassis. Both have enough GPIO — you only need four digital output pins for motor control and two digital input pins for the sensors. If this is a first build, use the Uno and save the Nano for when chassis size starts to matter.

LB-ARD-UNO-R3 / LB-ARD-NANO-V3

L298N Motor Driver Module

The L298N handles up to 2A per channel and runs on 5V–35V on the motor supply. It has a built-in 5V regulator that can power the Arduino directly off the motor battery, simplifying the power architecture. The BTS7960 is the upgrade path for higher current or lower heat at load, but the L298N is sufficient for a standard build.

LB-DRV-L298N

DC Gear Motors × 2 (with wheels)

Yellow TT gear motors (1:48 ratio) are the standard choice: cheap, widely compatible with standard robot chassis, and matched to most L298N current ratings. They run on 3V–6V and deliver enough torque to move a lightweight chassis at a controlled speed.

LB-MOT-GEAR-DC-01

2WD Robot Chassis

Acrylic or aluminum 2WD chassis kits include motor mounts, a battery tray, standoffs, and a caster wheel. The mounting hole pattern is matched to the TT gear motors above. Avoid building on a custom chassis for a first build — the standard kit keeps mechanical variables fixed so debugging stays focused on electronics and code.

LB-CHASSIS-2WD-01

Battery Pack (7.2V–9V)

A 7.4V 2S Li-ion pack gives clean, stable voltage and recharges between sessions. A 6×AA holder is cheaper and easier for students to swap during lab sessions. Power the motor driver directly from the battery; use the L298N's onboard regulator to supply the Arduino.

LB-PWR-BATT-7V2 / LB-PWR-AA-HOLDER

Jumper Wires, Breadboard, USB Cable

Use the breadboard for prototyping sensor connections before soldering. The USB cable is for uploading code to the Arduino.

LB-WIRE-JMP-SET / LB-BB-400 / LB-USB-A-B

Wiring Overview

Power: Connect the battery pack positive to the L298N VIN pin and negative to GND. The L298N's 5V output connects to the Arduino VIN. Share a common GND between the L298N and Arduino.

Motors: Motor A (left) connects to L298N OUT1 and OUT2. Motor B (right) connects to OUT3 and OUT4. If a motor spins backward on first test, swap its two wires at the terminal.

Motor control pins: L298N IN1, IN2, IN3, IN4 connect to Arduino D5, D6, D7, D8. ENA and ENB connect to D9 and D10 for PWM speed control. If speed control isn't needed initially, pull ENA and ENB HIGH with a jumper to run motors at full speed.

IR sensors: Left sensor OUT → D2. Right sensor OUT → D3. Both sensor VCC → Arduino 5V. Both GND → Arduino GND.

Before uploading any code, verify motor directions manually: power the robot while holding it off the surface, set IN1 HIGH and IN2 LOW, and confirm the left motor drives forward. Reverse wiring at the L298N terminal if needed. Sorting this mechanically first eliminates a class of bugs that looks like a logic error.

Code Logic

Simple If/Else (Beginner)

This is the right starting point. The robot will follow the line but with bang-bang behavior — correcting aggressively when it drifts rather than making smooth adjustments.

read leftSensor
read rightSensor

if leftSensor = WHITE and rightSensor = WHITE:
    drive both motors forward at full speed

if leftSensor = BLACK and rightSensor = WHITE:
    slow left motor, run right motor forward  // turn left

if leftSensor = WHITE and rightSensor = BLACK:
    slow right motor, run left motor forward  // turn right

if leftSensor = BLACK and rightSensor = BLACK:
    stop both motors (or maintain last turn direction)

PID Control (Intermediate)

PID replaces binary correction with a continuous one. Start with only the P term and tune Kp until the robot follows the line without oscillating. Add Kd to dampen wobble. Add Ki only if there's consistent drift in one direction — most student line followers run well on P or PD control without Ki.

error = leftSensorValue - rightSensorValue
correction = (Kp × error) + (Kd × (error - lastError)) + (Ki × sumError)

leftMotorSpeed  = baseSpeed + correction
rightMotorSpeed = baseSpeed - correction

clamp both speeds to [0, maxSpeed]
lastError = error
sumError += error

Common Mistakes

Sensor height too high or too low. IR sensors have a narrow optimal range — see the sensor selection guide for full specs on IR modules and alternatives — typically 5–15 mm from the surface. Too far and the reflection is too diffuse; too close and the chassis clips the ground on turns. Mount at 10 mm and adjust from there.

Motor wiring not verified before coding. Spending an hour debugging code logic when a motor is physically wired backward is the most common time-waster on a first build. Verify motor direction mechanically first, always.

Forgetting common ground. If the Arduino and the L298N are powered separately without a shared GND, control signals float unpredictably. All GND pins on all components must connect to the same ground rail.

Wrong surface. A printed black line on matte white paper works. A line on a glossy surface, under direct sunlight, or on a surface with visible grain will cause unreliable sensor readings that no amount of code tuning will fix. Test the surface before debugging the circuit.

PID tuning in the wrong order. Trying to tune all three terms simultaneously is how builds stall for days. Tune P first, then D, then I — and only add a term when the previous one is stable.

Get Your Parts Quoted Today

Lab404 Electronics carries every component on the list above — locally stocked, same-day dispatch, delivery anywhere in Lebanon within 24 business hours. Formal invoicing available for university purchasing departments. No overseas shipping, no customs risk, consistent part batches for class-sized builds.