Two-sensor line tracer
Explore lesson 61 and compare the model's four sensor decisions.
Open the experiment
Choose lesson 61, Two-sensor line tracer, then Run. The program reads left/right inputs and drives a virtual model. Try a curved track, straight track, floor without a line, and all-black floor. Manual sensor input lets you test A0/A1 classifications.
Pause keeps the current position. Stop and the experiment's start-position control restore the starting state. These virtual readings and positions are not measurements from real equipment through USB.
Compare the four decisions
| Left sensor | Right sensor | Left / right PWM | Result |
|---|---|---|---|
| White | White | 120 / 120 | Straight |
| Black | White | 60 / 150 | Correct left |
| White | Black | 150 / 60 | Correct right |
| Black | Black | 0 / 0 | Stop motor output |
The program evaluates a decision every 20 ms. Store both readings for the same decision cycle. The two analog conversions are still sequential.
Both-white cannot distinguish a centered line from complete line loss. Try the floor-without-line experiment. Sharp bends, intersections, wide lines, and automatic recovery after losing the line are outside this example's scope.
Understand the reference hardware
The reference has two sensing channels, each with an infrared emitter and phototransistor, plus a controller board, DRV8833 motor-driver module, two motors, and a separate suitable motor supply. Four optical components make two channels, not four independent line sensors.
Left/right inputs use A0/A1. Motor-driver inputs use D5/D6 and D10/D11. The circuit, module, power ratings, LED current limiting, and actual optical pinouts need checking before assembly. Artwork labels describe terminal functions, not physical lead order.
Ask your teacher or provider for the checked reference circuit and the actual module documentation before wiring. Use a driver module with its required supporting circuitry; the drawing is not a direct wiring plan for a bare motor-driver IC. Never connect motor power positive to controller 5V.
Calibrate real sensors separately
Virtual white 180, black 820, and threshold 500 are example values, not physical measurements. Measure each actual sensor over white and black, check that the ranges are distinct, and set each threshold separately. In the reference pull-up circuit, stronger white reflection is expected to lower the reading.
Correct height, shielding, and wiring before trying to solve overlapping readings with a threshold alone. Check motor direction with wheels raised and supervised power control. PWM zero can coast; real stopping distance, slip, and noise differ from the model.
Use Controller board for the separate compilation and upload workflow.