Line-Follower Robot

An autonomous two-wheel robot that follows a dark track on a light surface.

← All project briefs

Safety and scope

Lift the wheels during the first motor-direction test. Keep fingers, hair and loose wires away from rotating wheels.

Plan, predict and test

Suggested virtual study time: about 25 minutes. This is a planning estimate, not a validated construction time.

Preparation: Foundation electricity and basic programming logic. Adult supervision for children. Review a foundation lesson ↗

Use paper, a spreadsheet or a simulator. This is not a verified physical assembly guide.

  1. Scenario: Record the actual sensor polarity over line and background. Then model all four pairs of Boolean reflectance inputs.
  2. Expected result: Use a truth table to choose the corresponding direction. A missing sensor must have a defined fault response.
  3. Checkpoint: Write your prediction, test it in the virtual model and explain any difference.

Knowledge check

Are all IR sensor modules active-low over dark surfaces?

A correct answer does not certify the physical system.

Record your validation

Use only virtual inputs and indicators until the actual components, pinouts and electrical limits have been verified.

CaseWhat to record
Normal inputD2/D3 both HIGH → both indicators HIGH; both LOW → both LOW
BoundaryLOW/HIGH → D8 LOW, D9 HIGH; HIGH/LOW → reverse
Missing or invalid inputUnplugged pull-up input can read HIGH; the sketch cannot distinguish this fault. Do not connect motors.
Repeat testRepeat the virtual test, record the actual output and compare with the expected result.

These are test-planning requirements, not recorded hardware results.

Before building: understand the listed components and the relevant low-voltage safety rules. This is a concept brief, not a tested assembly manual.

What it does

Build a mobile robot that can keep itself centred over a marked route without a person steering it.

Engineering principle

Infrared reflectance sensing. A light surface reflects more IR while a dark line reflects less. Two or more reflectance sensors provide left/right position information. The controller turns that difference into motor corrections. A basic build uses threshold decisions; a tuned version can calculate line-position error and apply PID control to reduce overshoot.

Hardware and components

  • Arduino NanoReads the sensors and calculates motor commands.
  • 2 × IR reflectance modulesTCRT5000-type modules sit near the floor and detect the line. Output polarity varies by module; calibrate on the actual surface.
  • L298N H-bridge driverSwitches motor current and direction; the microcontroller pins do not power the motors directly.
  • 2 × BO geared DC motors + wheelsProvide differential drive so the robot can steer by changing each side’s speed.
  • Chassis, battery pack and wiringHold the assembly and supply separate logic/motor power as required.

Suggested build sequence

  1. Mount the sensors low and evenly spaced ahead of the wheels.
  2. Calibrate the sensors over both the track and background; confirm whether black reads HIGH or LOW on the chosen module.
  3. Wire the motor driver, logic supply and motor supply; verify the grounds and polarity before connecting the battery.
  4. Start with slow threshold-based steering, then tune motor speed and correction response.
  5. If the track and hardware justify it, calculate line error and tune a PID controller.

Learning outcomes

  • IR sensor calibration
  • H-bridge motor direction and PWM
  • Differential steering
  • Feedback and PID fundamentals

Possible upgrades

Add a multi-channel sensor array, intersection recognition, speed profiles, lost-line recovery and a PID tuning mode.

Practice the core principle

This simplified exercise is not the full physical project shown above. Test in simulation first; verify real hardware against its datasheet. Children need adult supervision.

Reference components

  • Arduino Uno
  • 2 pushbuttons
  • 2 LEDs
  • 2 × 330 Ω resistors

Connection plan

  • Left virtual sensor switch D2 → GND
  • Right virtual sensor switch D3 → GND
  • Left indicator D8 → 330 Ω → LED → GND
  • Right indicator D9 → 330 Ω → LED → GND

Reference sketch

void setup(){
  pinMode(2,INPUT_PULLUP); pinMode(3,INPUT_PULLUP);
  pinMode(8,OUTPUT); pinMode(9,OUTPUT);
}
void loop(){
  bool left=digitalRead(2)==LOW;
  bool right=digitalRead(3)==LOW;
  digitalWrite(8,!left);
  digitalWrite(9,!right);
  delay(20);
}

How the code works

  1. Inputs represent hypothetical calibrated line sensors.
  2. LOW represents a pressed switch.
  3. Each LED represents one motor command, not a powered motor.
  4. This simple truth table is for reasoning practice, not a validated line-following controller.

Practice sequence

  1. Assemble the switch and LED circuit with power disconnected.
  2. Simulate four combinations of sensor inputs.
  3. Record the corresponding indicator commands.
  4. For a physical rover, choose rated drivers and calibrated sensors under qualified supervision.

Expected result

Create a truth table and verify each virtual motor command.

Troubleshooting

Check input pull-ups and LED polarity; do not connect motors to output pins.

Independent challenge

Design lost-line behaviour and discuss how sensor placement changes steering.

Related briefs