HomeExperiments
Line Following with the Infrared Array
Robotics

Line Following with the Infrared Array

Use Alvik's three infrared line sensors to read a black track on white paper, then write a proportional controller that keeps the robot centred on the line.

55 min (set-up 20 min)
Sensors

What students learn

Students learn how reflective infrared sensors distinguish black from white, how three readings become an error signal, and how proportional control converts that error into a steering correction — the simplest closed-loop controller in robotics.

The science behind this experiment

  • Each line sensor is an infrared emitter paired with a detector. White paper reflects most of the infrared back and black tape absorbs it — but Alvik's firmware reports line strength, so the black line gives the HIGHER reading and white the lower one. Measure both yourself before writing any control code.
  • Three sensors give a position estimate, not just a yes/no: comparing left and right readings tells the robot which way it has drifted and by how much.
  • A bang-bang (on/off) controller only knows "too far left" or "too far right", so it always overshoots and produces a zig-zag path.
  • A proportional controller makes the correction proportional to the error: small drift, small correction; large drift, large correction. That is the P in PID.
  • Gain Kp sets how aggressively the robot reacts. Too low and it responds sluggishly and cuts corners; too high and it overshoots repeatedly, which is oscillation.

Key relation: error = (right − left) ÷ (right + centre + left), which lands between about −1 and +1. correction = Kp × error; left_speed = base + correction, right_speed = base − correction, both in rpm.

Equipment used

  • Arduino® Alvik robot
  • Black electrical tape or a thick black marker
  • White paper or card (A1 sheet or several A4 taped together)
  • Ruler for drawing a 2 cm wide line
  • Stopwatch to time a full lap
  • A lamp, to test the effect of changing light

Questions for students

  • Your proportional controller cuts the inside of tight corners. What extra information — about how fast the error is changing, or how long it has persisted — would help, and which letter of PID does each correspond to?
  • The threshold you chose works on this paper under this lighting. How would you make the robot calibrate itself automatically at the start of every run?

What to expect

The bang-bang version follows the line but wobbles visibly from side to side. The proportional version tracks the line smoothly on gentle curves; with Kp too high it oscillates, with Kp too low it cuts corners and loses the line. Three cheap infrared sensors are enough to turn a position error into a steering command. Proportional control — correction proportional to error — replaces jerky on/off behaviour with smooth tracking, and tuning the gain is a trade-off between responsiveness and stability that appears in every control system, from robots to aircraft.

Run this experiment in your classroom

This experiment is part of ATP Volta — a self-contained mobile science lab that turns an ordinary classroom into a working STEM laboratory, with over 200 experiments in physics, chemistry, biology, robotics and engineering. Gali, the AI tutor built into ATP Connect, guides students through each step and answers their questions at the bench.

See the ATP Volta mobile science labTalk to our team

The full experiment library

Eighty-six guided experiments across physics, chemistry and biology — each with learning goals, equipment, background theory and questions for students. Browse the library

Physics 42
Chemistry and biology 44