ExpertRobotics
Line-Following Robot
Build a two-motor robot that follows a dark tape line using reflectance sensors and proportional steering.
Parts from the database
- STM32F103C8T6 ร 1Use on a supported development board
- DRV8833PWPR ร 1Dual H-bridge motor driver; use on a breakout
Other supplies
- STM32 development boardCommon build supply
- DRV8833 motor-driver breakoutCommon build supply
- two small geared motors/chassisCommon build supply
- three IR reflectance sensor modulesCommon build supply
- separate low-voltage motor supplyCommon build supply
- USB supply for programmingCommon build supply
Amazon links may be affiliate links. As an Amazon Associate, Electronics Hobby Hub earns from qualifying purchases.
Connections
- Connect three sensor outputs to ADC-capable MCU pins and power them at their rated voltage.
- Connect two PWM+direction pairs from STM32 to the DRV8833 module; follow its exact truth table.
- Power motors from a separate supply within driver and motor ratings; share ground with logic.
- Mount sensors close to the floor and ahead of the wheels; keep ambient light shielding consistent.
Build steps
- Calibrate each reflectance sensor over the actual tape and floor; record min/max values.
- Verify left/right motor polarity with wheels lifted and tune a low safe speed.
- Compute line position from the three sensor readings and adjust left/right PWM proportionally.
- Test on a broad, high-contrast loop, then reduce track width or increase speed only after stable laps.
Software and firmware setup
Firmware is required, but a complete STM32 sketch is not included yet. Use an STM32 Arduino core or a supported STM32 toolchain, read the three reflectance sensors on ADC-capable pins, and implement the proportional steering described above. Confirm the DRV8833 truth table and motor polarity at low speed with wheels lifted.
Test your build
The robot should correct toward the tape and recover from small offsets. Sensor calibration and chassis alignment matter more than high speed.
Troubleshooting
- If it turns away from the line, reverse sensor polarity or correction sign.
- If it oscillates, lower proportional gain and speed; if it drifts, increase gain gradually.
- If the MCU resets, separate motor power and route motor leads away from sensor wiring.
Safety and limitations
Lift the wheels during initial tests, use low-voltage battery packs, and keep the robot away from stairs, roads, pets and people.
Manufacturer and platform documentation
Community Notes for This Project
These are unverified visitor contributions, separate from the build guide and manufacturer specifications. Verify technical advice against the linked datasheets before relying on it.
Set up the comments service to load community notes.