Overview
Designed for the 14th Annual RIT Dubai Mechanical Engineering / Robotics Competition, MazeBot is an autonomous, omnidirectional maze-solving robot engineered completely from first principles—spanning parametric Autodesk Inventor chassis housings, custom 3D-printed Mecanum wheels, dual-core ESP32 FreeRTOS navigation firmware, and a companion Bluetooth control cockpit. Although scheduling circumstances prevented the robot from competing on event day, MazeBot was fully assembled, calibrated, and validated in autonomous maze trials inside a custom test arena, earning a Robotics Competition Appreciation Certificate from Providence English Private School (Innovation Club).
Sensor acquisition, closed-loop yaw stabilization, and autonomous maze decisions run continuously on CPU Core 1, while classic Bluetooth telemetry streaming, remote driving inputs, EEPROM trim persistence, and heartbeat watchdog monitoring execute independently on CPU Core 0 without introducing blocking communication delays into the control loop.
Key achievements include designing 100% custom 3D-printed Mecanum wheels and a modular cruciform chassis anchored with M3 heat-set brass inserts, implementing non-blocking dual-core FreeRTOS task isolation, engineering lateral Mecanum wall-hugging paired with a MPU-6050 gyro heading lock, building automatic dead-end corridor backtracking alongside a 3-stage pitch ramp exit controller, and developing a custom MIT App Inventor binary telemetry cockpit.
Technical Architecture & Circuit Design
(Because the original 2024 schematic archive was lost, the hardware topology and GPIO pinout below have been reconstructed directly from the production firmware MAZEBOTDualCore2.0.ino, physical chassis wiring, and CAD assemblies.)
Power Distribution & Signal Conditioning
- Primary Power & Regulation: A 7.4 V 3000 mAh 2S LiPo battery supplies high-current motor power directly through the kill-switch stage while an LM2596 DC-DC buck converter regulates a clean 5 V rail for the ESP32
VINpin, ultrasonic transducers, and the high-voltage side of the logic shifters. - Bi-Directional Logic Level Translation: Because the ESP32 operates strictly at 3.3 V GPIO logic while the
HC-SR04ultrasonic echo pulses andL298Nstages interface with 5 V rails, 2× 4-channel bi-directional logic level shifters sit directly beside the IMU inside the left electronics pocket. - Safety Kill-Switch Interlock (
GPIO 4&GPIO 39):GPIO 4(KillSwitch) is pulledHIGHduring armed operation to energize the motor power switch. Triggering the externalRISINGhardware interrupt onGPIO 39(InterruptPin), sending Bluetooth kill button8, or losing the Bluetooth heartbeat for more than10 simmediately drivesGPIO 4LOWto cut actuator power.
Tech Stack
Embedded Systems & Core Algorithms
- Microcontroller & RTOS: ESP32 DevKit running FreeRTOS dual-core task scheduling (
xTaskCreatePinnedToCorepinningCommunicationsto Core 0 andActionto Core 1). - Autonomous Maze Engine:
40 Hz(25 ms) ultrasonic polling with500 mswall-presence debouncing, lateral Mecanum corridor centering, reverse-pulse braking, andCorridorStartingDistdead-end backtracking (StuckSituation()). - Inertial Heading & Ramp Control:
MPU6050_lightsensor fusion over I²C (SDA = 21,SCL = 22) maintaining a yaw deadband (absolutePOS()) and 3-stage pitch ramp exit detection (AngleY > 20°<= -20°|AngleY| <= 2°). - Flash Persistence: Non-volatile
EEPROMcalibration storage (EEPROM_SIZE = 4) retaining individual motor trim compensation (TrimA–TrimD) across reboots.
Hardware & Electronics
- Dual H-Bridge Motor Drives (
2× L298N): Motor A (IN1=33, IN2=32, PWM=18), Motor B (IN3=14, IN4=27, PWM=19), Motor C (IN1=13, IN2=12, PWM=15), and Motor D (IN3=26, IN4=25, PWM=2), mapped to EEPROM trims0–3. - Ultrasonic Sensing Array (
3× HC-SR04): Left (Trig=5, Echo=34), Right (Trig=23, Echo=35,300 cm/3500 µstimeout), and Front (Trig=17, Echo=36,400 cm/10000 µstimeout). - Safety & Power Stage:
7.4 V 3000 mAh2S LiPo,LM25965 V buck module,GPIO 4kill switch,GPIO 39interrupt input, and2×4-channel bi-directional level shifters.
Mechanical Design & Companion Software
- 3D CAD & Fabrication: Parametrically modeled in Autodesk Inventor (
Mazebot.iam,Chasis.ipt,BoardSeater.ipt,EncloserTop.ipt,BattaryChasis.ipt,UltraSonicSensorEnclosure.ipt) and AutoCAD (Maze Layout.dwg,Ramp.dwg), fabricated via FDM 3D printing with M3 brass threaded inserts. - Mobile Cockpit: Custom MIT App Inventor Android application (
MAZEBOT.aia) with custom Adobe Photoshop UI icons communicating over classic Bluetooth SPP ("MAZEBOT").
100% Custom CAD & 3D-Printed Mecanum Drive
Every mechanical element on MazeBot was designed from scratch in Autodesk Inventor and fabricated in-house. The lower chassis (BattaryChasis.ipt) cradles the 7.4 V 3000 mAh LiPo pack beneath the cruciform electronics deck (Chasis.ipt) to keep the center of gravity low, while dedicated sensor pockets (UltraSonicSensorEnclosure.ipt) recess all three HC-SR04 transducers 3 cm inside the outer bumper perimeter.
All four Mecanum wheels (Macanum Wheel.iam) were fabricated as multi-part assemblies featuring mirrored helical side plates (WheelAPart1–3.stl and WheelBPart1–3.stl), structural WheelCore.stl hubs, Rotary coupler.stl motor adapters, and -angled individual Roller.stl barrels pinned with steel M3 hardware.
Omnidirectional Kinematics & Calibration Equations
Because all three ultrasonic housings sit recessed by MotorSensorDist = 3 cm inside the wheel envelope, and because lateral Mecanum strafing magnifies motor-to-motor friction asymmetry, raw measurements and PWM commands pass through calibrated software transforms:
- Recessed Side-Wall Clearance Compensation:
- Trim-Compensated Lateral Strafing Duty Cycle (
Left()/Right()):
void Right(byte Speed = 100){
analogWrite(MotorASpeed, PerToAnalog(constrain((Speed - map(TrimA, 0, 100, 100, 0)),0,100)) );
analogWrite(MotorBSpeed, PerToAnalog(constrain((Speed - map(TrimB, 0, 100, 100, 0)),0,100)) );
analogWrite(MotorCSpeed, PerToAnalog(constrain((Speed - map(TrimC, 0, 100, 100, 0)),0,100)) );
analogWrite(MotorDSpeed, PerToAnalog(constrain((Speed - map(TrimD, 0, 100, 100, 0)),0,100)) );
BackMotor(MotorA1, MotorA2, "Left");
ForMotor(MotorB1, MotorB2, "Right");
ForMotor(MotorC1, MotorC2, "Left");
BackMotor(MotorD1, MotorD2, "Right");
}
void Left(byte Speed = 100){
analogWrite(MotorASpeed, PerToAnalog(constrain((Speed - map(TrimA, 0, 100, 100, 0)),0,100)) );
analogWrite(MotorBSpeed, PerToAnalog(constrain((Speed - map(TrimB, 0, 100, 100, 0)),0,100)) );
analogWrite(MotorCSpeed, PerToAnalog(constrain((Speed - map(TrimC, 0, 100, 100, 0)),0,100)) );
analogWrite(MotorDSpeed, PerToAnalog(constrain((Speed - map(TrimD, 0, 100, 100, 0)),0,100)) );
ForMotor(MotorA1, MotorA2, "Left");
BackMotor(MotorB1, MotorB2, "Right");
BackMotor(MotorC1, MotorC2, "Left");
ForMotor(MotorD1, MotorD2, "Right");
}Dual-Core FreeRTOS Firmware & Autonomous Pipeline
To ensure ultrasonic pulseIn timeouts never freeze incoming Bluetooth kill commands, setup() calibrates the MPU-6050 gyro/accelerometer offsets, opens a 6 s Bluetooth handshake window (automatically arming Algorithm_State = 1 if no operator connects), and forks two pinned FreeRTOS tasks across Core 0 and Core 1:
Running both cores independently keeps the 10 ms Bluetooth parser responsive even when UltraFront waits up to 10,000 µs on long corridor echoes. If a connected mobile operator fails to refresh telemetry within 10 s, Core 0 immediately cuts motor power via Kill().
void DualCore(){
xTaskCreatePinnedToCore(
Communications, /* Task function. */
"Task1", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
2, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
xTaskCreatePinnedToCore(
Action, /* Task function. */
"Task2", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
2, /* priority of the task */
&Task2, /* Task handle to keep track of created task */
1); /* pin task to core 1 */
}Closed-Loop Heading Hold, Backtracking & Ramp Exit
The autonomous state machine (Algorithm()) combines four real-time behaviors so the chassis stays centered in tight corridors, recovers from cul-de-sacs, and detects the exit ramp purely through inertial pitch telemetry:
- Wall Debouncing & Lateral Strafing: Each ultrasonic channel samples at
40 Hzand latchesSeenWall*Delayedonly after a wall stays within10 cmfor500 ms, allowing pure Mecanum strafing (Left()/Right()) to hold a1 cm ± 1 cmside clearance without turning off-axis. - Closed-Loop Gyro Yaw Lock (
absolutePOS()): Continuously corrects heading drift against a±3°deadband, turning cleanly wheneverZOffsetsteps by±90°:
- Dead-End Corridor Displacement (
CorridorDistDetect()): RecordsCorridorStartingDistafter each turn soStuckSituation()can reverse back to the corridor entrance and invert the previous turn if all three debounced wall flags trigger simultaneously:
- 3-Stage Pitch Ramp Exit (
DetermineEndOfMaze()): WatchesAngleYfor a> 20°climb to boost forward speed to100%, drops to40%with a100 msreverse braking pulse upon cresting (AngleY <= -20°), and executesGetOutOfMaze()once level (|AngleY| <= 2°).
void absolutePOS(){
byte threshold = 3;
if(millis() - ZOffsetStoptime >= 500 && StoptimePassed == 0){
StoptimePassed = 1;
ZOffset = mpu.getAngleZ();
}
if(AngleZ > threshold && !(AngleZ < threshold && AngleZ > -threshold) && RotateClockWise_State == 0 && RotateAntiClockwise_State == 0 && StoptimePassed == 1){
RotateClockwise(45);
rotatedStop = 0;
StopPulseIntervalTimer = millis();
}
if(AngleZ < -threshold && !(AngleZ < threshold && AngleZ > -threshold) && RotateClockWise_State == 0 && RotateAntiClockwise_State == 0 && StoptimePassed == 1){
RotateAntiClockwise(45);
rotatedStop = 0;
StopPulseIntervalTimer = millis();
}
if((AngleZ < threshold && AngleZ > -threshold && rotatedStop == 0) || millis() - StopPulseIntervalTimer >= 2 && rotatedStop == 0){
Stop();
// Serial.println("I am happening");
rotatedStop = 1;
if(RotationClockwiseAlg == 1 || RotationAntiClockwiseAlg){
CorridorStartingDist = DistenceFront;
Companion Android Cockpit & Binary Protocol
To calibrate lateral strafing trims and inspect live ultrasonic/IMU telemetry without serial cables inside the maze, the custom MIT App Inventor mobile app sends compact integer commands (DataType 1–4: 13 movement/system buttons, PWM speed, telemetry request, and EEPROM motor trims) and receives a 19-byte big-endian telemetry stream (TrimA–TrimD, Algorithm_State, DistenceLeft, DistenceRight, DistenceFront, scaled AngleZfromStart, scaled AngleZ, DistenceMovedAcrossCorridor, and CorridorStartingDist).
Testing & Autonomous Maze Trials
Challenges & Lessons Learned
Decoupling Blocking Sensors from Bluetooth Watchdogs
Early single-loop prototypes suffered sluggish responsiveness whenever triple ultrasonic pings (3500–10000 µs timeouts) coincided with Bluetooth reads or EEPROM trim updates. Moving Bluetooth() and the 10 s safety watchdog onto FreeRTOS Core 0 while keeping all sensor sampling, gyro integration, and motor control on Core 1 immediately stabilized loop timing and ensured emergency kill signals never waited behind a stalled sonar echo.
Compensating 3D-Printed Mecanum Friction Asymmetry
While 100% custom 3D-printed Mecanum wheels gave full packaging control inside tight competition dimensions, subtle roller and motor friction differences caused noticeable yaw drift during lateral strafing (Left() / Right()). Rather than guessing constants in code and re-flashing repeatedly, pairing per-wheel EEPROM trims (TrimA–TrimD) adjusted live over Bluetooth with active MPU-6050 closed-loop yaw correction (absolutePOS()) kept lateral corridor centering crisp and repeatable.
Lessons Carried Forward
- Debounce before trusting sonar in tight corners: Requiring
500 mscontinuous detection (SeenWall*Delayed) eliminated false corner triggers caused by glancing oblique reflections off foam maze walls. - Document schematics alongside code: Losing the original wiring diagram made reconstructing the pinout from
MAZEBOTDualCore2.0.inoessential—reinforcing the habit of keeping versioned architecture flowcharts and pin tables directly inside every project repository.

