Smart maze-solving robot powered by Arduino. The robot follows black lines, learns intersections during a dry run, simplifies the recorded path, and then replays the optimal route for a fast solve.
- PID-based line following with five IR reflectance sensors.
- Intersection detection and path recording for maze solving.
- Path simplification to remove loops before the timed run.
- Onboard push button to toggle between a learning lap and the final run.
- Built-in LED signaling for quick status feedback.
- Arduino Uno (or compatible) microcontroller.
- Dual-channel motor driver (e.g., L298N/L293D).
- Two DC gear motors with encoders optional.
- Five line sensors plus two side turn sensors.
- Optional ultrasonic or forward-facing IR sensors (see
sketch_jan05a.ino). - Push button and indicator LED.
- 7–12 V battery pack suitable for the chosen motors and driver.
| Component | Pin(s) |
|---|---|
| Left motor driver input | 2, 3 |
| Right motor driver input | 4, 5 |
| Left motor enable (PWM) | 10 |
| Right motor enable (PWM) | 11 |
| Turn sensors | 6 (left), 7 (right) |
| Line sensors | A0 (far left), A2 (near left), A3 (center), A4 (near right), A5 (far right) |
| Status LED | 8 |
| Push button | 9 |
- Wire the robot according to the pinout above and your motor driver’s datasheet.
- Install the Arduino IDE or
arduino-cli. - Open
final.ino, select Arduino Uno (or your board) and the correct port. - Upload the sketch.
- Place the robot at the maze entrance and press the button once to start the dry run. Press the button again to replay the optimized path.
- Adjust
kp,ki, andkdnear the top offinal.inoto suit your maze’s contrast and your motor driver’s responsiveness. Start withki = 0and increase slowly to avoid windup. - Use
initial_motor_speed,rotating_speed, andforward_speedto match your drive train and traction. - If you only need to focus on PID behavior, try the dedicated tuning sketch
Final_PID.ino, which isolates the line-following logic.
final.ino– primary firmware for maze discovery and optimized playback.Final_PID.ino– pared-down sketch for experimenting with PID gains on a six-sensor layout.sketch_jan05a.ino– prototype that mixes line following with additional sensors such as ultrasonic rangefinders.
Issues and pull requests are welcome. Please keep code formatted (the repository
uses clang-format defaults) and include concise descriptions of hardware
setups or tuning parameters that affect behavior.