- Explain closed-loop line following in plain language.
- Trace information from input to output.
- Test one subsystem independently.
- Recognize a common failure and respond safely.
- Modify the example without changing several variables at once.
The central idea: closed-loop line following
A line follower measures the line's position relative to the robot, calculates an error, and changes left and right motor commands to reduce that error.
Treat the system as a chain of observable inputs, explicit processing, a decision, and an output. That makes the design easier to explain and gives you a place to test when something fails. A working result is not enough: record what input produced it and what evidence shows the result is correct.
Follow the information through the system
Read the diagram from left to right. Each arrow is a boundary where data, electrical signals, or commands move between parts. Test those boundaries separately before combining the whole system.
When the line appears left of center, the controller slows the left wheel or speeds the right wheel, then measures again.
- Calibrate light and dark surfaces.
- Begin with proportional correction.
- Limit correction and speed.
line sensors → position error → controller → motor difference → new sensor reading ↺Parts and responsibilities
Use beginner-safe, low-voltage parts and confirm the exact pinout and voltage for your board revision. Disconnect power before changing wiring. Motors need a suitable driver and separate motor power; never draw motor current from a GPIO pin.
| Part | Purpose |
|---|---|
| Line sensor array | Measures line position |
| Microcontroller and motor driver | Calculates correction and drives motors |
| Two-wheel chassis and matte test track | Provides motion and a repeatable course |
Test before you trust the result
Start with a normal case, then test a boundary case and a failure case. For software, try empty, unexpected, and extreme inputs. For hardware, begin with wheels raised or actuators disconnected, keep a physical power switch within reach, and verify safe stopping behavior.
Write down the expected result before each test. If the observation differs, stop and find the first boundary where the expected signal disappeared. This method is slower than changing many things at once, but it produces evidence instead of guesses.
- Test one input with a known value.
- Observe the intermediate value before the final action.
- Confirm a safe response when input is missing or invalid.
- Repeat the same test to check consistency.
Important terms
- Closed loop
- Control that uses feedback to update action.
- Setpoint
- The desired measured state.
- Error
- Difference between desired and measured state.
- Gain
- How strongly output responds to error.
- Saturation
- A limit beyond which output cannot increase.
Mini project: prototype closed-loop line following
- Calibrate sensors over track and background.
- Display calculated error.
- Test motor directions raised.
- Run slowly on a wide curve.
- Increase one gain in small steps.
Common mistakes and debugging
- Tuning at full speed.
- Changing speed and gain together.
- Ignoring sensor mounting height.
- Letting outputs exceed motor limits.
Independent challenge
Record lap behavior at three proportional gains and explain undercorrection versus oscillation.
Check your understanding: 10 questions
What is the main purpose of closed-loop line following?
What does “Closed loop” mean in this lesson?
How is “Setpoint” used?
Why should you test one boundary or subsystem at a time?
What should the system do when an input is missing or invalid?
In your own words, what does “Closed loop” mean?
In your own words, what does “Setpoint” mean?
In your own words, what does “Error” mean?
In your own words, what does “Gain” mean?
In your own words, what does “Saturation” mean?
Quiz answers
Reveal all 10 answers after your attempt
- A line follower measures the line's position relative to the robot, calculates an error, and changes left and right motor commands to reduce that error.
- Control that uses feedback to update action.
- The desired measured state.
- It reveals where the expected value or behavior first changes, so debugging is based on evidence.
- It should reject the input, report the problem, or move to a documented safe state instead of guessing.
- Control that uses feedback to update action.
- The desired measured state.
- Difference between desired and measured state.
- How strongly output responds to error.
- A limit beyond which output cannot increase.
Summary
closed-loop line following becomes manageable when you identify the input, processing, decision, output, and evidence of success. Build the smallest version, test it, then make one measured change.
Continue learning
Continue to the next lesson, which builds on this model with one additional capability.
Choose a connected learning pathSources and further reading
Prepared 2026-10-02. Editorially completed for the course. Software examples are designed for current Python 3; verify board, operating-system, library, and hardware details against the linked primary documentation before a physical build.