Overview
In a 2 person group for my Intro to Electrical Engineering class, we built an Arduino-based robot that navigates a lightbulb-shaped track using only onboard IR line-sensing, with no external localization. It starts in a marked zone, follows the full loop, detects a horizontal crossbar partway through, executes a 180° turnaround there, returns to the start, and comes to a controlled stop. For full credit, we needed a 19 second lap. Ours finished in 13.9 seconds.
Sensing
- An 8 sensor IR reflectance array reads the track each loop
- Every sensor is calibrated with its own empirically measured min and max reflectance, then normalized to a 0–1000 scale, so all eight can be compared fairly regardless of individual sensitivity or ambient light
- Each sensor carries a fixed positional weight from roughly −15 on the right to +15 on the left. The weighted sum divided by 8 simplifies to how far off the line the robot is, and which way
Control
- Steering correction is
Kp × error + Kd × (error − previous_error), applied differentially, clamped to the 0–255 PWM range - Final tuned values: base speed 250, Kp 0.049, Kd 0.35
- The derivative term matters the most as speed increases. Without it, the robot over-corrects and oscillates across the line
Crossbar Detection
- We had to recognize the crossbar without false-triggering on other dark track features
- The final approach was to count sensors reading strongly black (normalized > 900). If 6 or more of 8 detect at once, a counter increments. Otherwise, it resets to zero immediately, and the turn only triggers after 3 consecutive qualifying loops
- With three states (outbound, returning, finished), the first crossbar hit triggers the turn and the second one triggers the final stop
- The turn itself brakes actively first, with motors at zero held briefly to kill momentum, then turned the wheels in opposite directions at full PWM for a fixed blind duration, and then moves forward to sort itself back onto the line
Testing
- Our tuning was empirical and incremental. We change one or two parameters, run, then hand-log the result
- Base speed was increased in stages (70, 120, 140, 155, 165, 175, 190, 220, 250) with Kp and Kd raised in tandem at each step (from about Kp 0.007 and Kd 0.02 up to the final values)
- Lap time fell from about 21.6s to 13.9s after lots of tuning
- Early failures included one wheel spinning slower (sensor-weighting bug), drifting off the first turn at low speed, false return detection at the wrong track position, and false crossbar triggers
Key Takeaway
All the parameters we controlled were connected. Speed, Kp, Kd, turn timing, and crossbar sensitivity all interact, as raising speed to save time would reintroduce oscillation or false turn triggers, so every change meant re-validating parameters we'd already "solved." Our final configuration was a perfectbalance.