A real-time operating system (FreeRTOS) based micromouse robot that solves line-following mazes using state machines and task-based concurrency.
This project implements a sophisticated maze-solving robot using:
- Arduino Nano (ATmega328P) microcontroller
- FreeRTOS for multitasking and real-time control
- QTR Sensors for line detection (8-sensor array)
- TB6612 Motor Driver for motor control
- State Machine Architecture for robot behavior management
- ✅ Line following with PID control
- ✅ Automatic sensor calibration
- ✅ Left-hand and right-hand maze solving rules
- ✅ Intersection detection and turn execution
- ✅ Path optimization and simplification
- ✅ Recovery mechanism for lost line detection
- ✅ Watchdog task for timeout monitoring
- ✅ Multi-threaded task scheduling with FreeRTOS
Motor Control (TB6612):
- AIN1: Pin 5
- AIN2: Pin 4
- PWMA: Pin 3
- BIN1: Pin 6
- BIN2: Pin 8
- PWMB: Pin 9
Sensors:
- QTR-8 Array: A0-A7 (Analog Pins)
Control Switches:
- SW1 (Start/Restart): Pin 10
- SW2 (Left Rule): Pin 11
- SW3 (Right Rule): Pin 12
Indicators:
- LED: Pin 7
- Connect TB6612 motor driver to specified pins
- Connect 8-sensor QTR array to analog pins A0-A7
- Connect switches with pull-up resistors to digital pins
- Connect 2 DC motors to motor driver outputs
- PlatformIO (recommended) or Arduino IDE
- Arduino Framework
- Dependencies:
- QTRSensors (v4.0.0+)
- FreeRTOS (feilipu/FreeRTOS v10.5.1+)
- Arduino core libraries
# Install dependencies
platformio lib install
# Build the project
platformio run
# Upload to Arduino Nano
platformio run --target upload
# Monitor serial output
platformio device monitor --baud 9600- IDLE: Waiting for calibration command
- CALIBRATING: Swinging left/right to calibrate sensors
- EXPLORING: Solving the maze following selected rule
- RECOVERY: Recovering when line is lost
- FINISHED: Maze solved, ready for optimized run
- Power on the robot
- Press SW1 to start calibration
- Robot swings left/right to calibrate sensor thresholds
- Press SW2 for left-hand rule or SW3 for right-hand rule
- Robot explores and solves the maze
- LED indicates status (blinking = calibrating/exploring, solid = finished)
- StateMachine Task (Priority 2): Executes state handlers every 50ms
- Watchdog Task (Priority 3): Monitors for timeouts and hangs
kp = 0.161 // Proportional gain
kd = 0.54 // Derivative gain
BaseSpeed = 230
MaxSpeed = 255- Flash: 67.8% (20834 / 30720 bytes)
- RAM: 74.2% (1519 / 2048 bytes)
The robot sends debug information at 9600 baud:
- State transitions
- Sensor calibration values
- Maze solution path
- Error messages and warnings
- Robot spins in place: Check sensor wiring and calibration
- Motor not moving: Verify motor driver pins and power supply
- Poor line following: Adjust PID constants and sensor thresholds
- Timeout errors: Increase timeout values or check line continuity
See LICENSE file for details.