Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

A line-following robot is a small mobile robot that uses sensors to detect a dark line and adjust its motors to stay on track. This project connects physics, electronics, coding, and engineering design in one hands-on build. It is useful because the same ideas appear in factory robots, delivery vehicles, and automated machines that follow paths or detect edges.

For grades 7 to 12, it is a manageable project that still shows real feedback control.

Understanding Line-Following Robot Project

The sensors work by sending out infrared light, then measuring how much light returns from the surface. White paper reflects more infrared light than black tape in most classroom setups. The sensor output is not perfectly fixed.

Room lighting, shiny tape, battery voltage, and the height of the sensor above the floor can all change the reading. Calibration gives the robot useful reference values before it starts moving. Place each sensor over the light background, record its reading, then place it over the dark line and record that reading.

A midpoint between the two readings is often a good starting threshold. Test the threshold on several parts of the track because tape can have uneven surfaces.

Sensor placement affects how the robot behaves. Put the sensors near the front of the chassis so they detect a turn before the wheels pass it. If they are too far apart, a narrow line may fit between them and become hard to detect.

If they are too close together, the robot may react late on sharp bends. The sensors should be the same height from the ground and face straight down. A small change in angle can make one sensor receive more reflected light than the other.

This can create a false steering error even when the robot is centered. Mechanical details matter here. Loose wires, uneven wheels, and a crooked sensor mount can cause problems that look like coding mistakes.

The program runs as a repeating control loop. It reads the sensors, decides where the line is, changes motor commands, then repeats many times each second. With simple bang-bang control, the robot makes a strong left correction or a strong right correction.

This is easy to build and understand, but it often produces a zigzag path. The robot crosses the line, corrects too much, then crosses it again. Lower motor speed can reduce this effect.

A proportional controller makes the correction grow as the measured error grows. PID control adds two more parts. The integral part responds to an error that lasts for a long time.

The derivative part responds to how quickly the error is changing. These features can make motion smoother, though poor settings can make the robot shake or drift.

PWM controls average motor power by switching the power rapidly on and off. A higher duty cycle means power is on for more of each cycle, so the motor usually spins faster. Motors are not identical, even when they look the same.

One wheel may move faster because of friction, gearbox differences, or weight distribution. Set a base speed that is slow enough for the sharpest turn on the track. Then adjust the left and right motor values around that base speed.

Keep motor power separate from sensor power when possible. Motors can create electrical noise and sudden voltage drops that cause unstable sensor readings or reset the controller.

A good test track includes straight sections, gentle curves, tight corners, and a line that ends. Test one change at a time. First confirm that each sensor reports light and dark reliably.

Next check that a left correction really turns the robot left. Then tune speed and control values. Record what happened during each run, including battery level and surface type.

When the robot loses the line, add a recovery rule such as turning in the last known direction until a sensor finds the line again. This project teaches an important engineering habit. Reliable performance comes from measuring, testing, and improving small details rather than guessing.

Key Facts

  • Two IR sensors can detect line position by comparing left and right reflected light values.
  • If left sensor sees black and right sensor sees white, turn left by slowing or reversing the left motor.
  • If right sensor sees black and left sensor sees white, turn right by slowing or reversing the right motor.
  • Bang-bang control uses simple on or off decisions, such as error < 0 turn left and error > 0 turn right.
  • PID control can be written as correction = Kp e + Ki ∫e dt + Kd de/dt.
  • Motor speed depends on PWM duty cycle, with duty cycle = on time / total period.

Vocabulary

IR sensor
An infrared sensor shines infrared light and measures how much light reflects back from a surface.
Motor driver
A motor driver is a circuit that lets a low-power controller safely control higher-current motors.
Calibration
Calibration is the process of measuring sensor readings on known surfaces so the robot can make accurate decisions.
Control loop
A control loop repeatedly senses, decides, acts, and checks again to reduce an error.
PWM
Pulse width modulation controls average motor power by rapidly switching voltage on and off.

Common Mistakes to Avoid

  • Placing the sensors too far apart makes the robot lose the line because neither sensor may detect the edge during a turn.
  • Skipping calibration is wrong because black tape, white paper, room lighting, and sensor height can all change the readings.
  • Connecting motors directly to a microcontroller pin is unsafe because motors need more current than most controller pins can supply.
  • Using full speed before testing control logic causes overshooting because the robot moves farther before each sensor update can correct it.

Practice Questions

  1. 1 A robot reads 820 on white paper and 230 on black tape from one IR sensor. Choose a threshold halfway between them and state whether a reading of 500 should be treated as black or white.
  2. 2 A PWM signal has a period of 20 ms and is on for 6 ms. Calculate the duty cycle as a percentage and explain whether this is closer to low, medium, or high motor power.
  3. 3 A robot wiggles rapidly left and right while following the line. Explain how changing sensor spacing, speed, or control logic could reduce this motion.