Overview
On November 5, 2026, our team (PEPS Robotic — Almoukhtar Amiouni, Ahmed Areeb, and Rayyan Ameer) secured 1st Place at ALFRED (Autonomous Line Following Robot Endurance Race) during the 16th Annual Engineering Competition hosted by Rochester Institute of Technology (RIT) Dubai in partnership with vfrog. Building upon our 2nd Place finish at the 15th Annual competition the previous year, the robot was engineered for deterministic tracking and rapid trackside adaptability—packing high-speed straight tracking, instant corner pivots, blind gap bridging, real-time obstacle avoidance, and wireless parameter tuning into an Arduino Uno (ATmega328P) compiled to 32,148 / 32,256 bytes Flash (99.7%) and 1,728 / 2,048 bytes SRAM (84.4%).
To eliminate blocking delays on a single-core 8-bit MCU, src/handwritten.cpp divides execution across independent asynchronous timing domains: a 100 Hz PD 5-channel floor line follower, a 30 Hz VL53L1X laser Time-of-Flight radar sweep, a 28 Hz HuskyLens AI vision pipeline, and a time-division multiplexed HM-10 BLE telemetry channel streaming live diagnostics to our RoboCar v3.0 Web Bluetooth Cockpit.
Beyond the firmware, winning required surviving a brutal final 24 hours: rebuilding the motor stack around our 15th-competition PCA9685 shield after the 16th kit's shield burnt out the night before, replacing broken Bluetooth header pins and performing mechanical surgery on a broken power switch 3 hours before boarding the school bus, and adapting on the fly when the event-day arena diverged sharply from the published track specification.
Hardware, Dual-Rail Power & Multi-Rate Architecture
To ensure consistent motor torque and brownout-free servo actuation across an entire competition day, the chassis runs a custom dual-converter power distribution architecture fed from a 2S LiPo battery pack (7.4–8.2 V, staying within the competition's 6–9 V battery input rule):
- Main 12 V Motor Power Rail (Step-Up Boost Converter): Boosts the
2S LiPopack up to a regulated 12 V supply dedicated to the 4WD gear motors, preventing speed and turn-timing drift as the battery discharges. - Isolated 5 V Servo Rail (
LM2596Step-Down Buck Converter): Supplies a dedicated, current-isolated 5 V rail exclusively for the front radar servo (D4), shielding the Arduino Uno,VL53L1Xlaser sensor,HuskyLenscamera, andHM-10BLE module from voltage sag during rapid sweeps.
Rather than relying on delay() calls that stall sensors during motion, loop() schedules five independent asynchronous millis() domains on every MCU cycle while profiling worst-case loop latency (maxLoopMs) and PD interval jitter (maxPdGapMs):
Because Wire runs in 400 kHz fast mode with a 3 ms bus hang timeout (Wire.setWireTimeout) and HuskyLens uses a 20 ms drive timeout, no I²C sensor stall can starve the differential motor loop or drop incoming E-Stop packets.
Tech Stack
Embedded Systems & Core Algorithms
- Multi-Rate Scheduler: Asynchronous
millis()execution across100 HzPD tracking,30 HzVL53L1X ranging,80 msservo micro-sweeping,28 HzHuskyLens AI vision,10 Hzbattery telemetry, and2 HzLED matrix updates. - 5-Channel Line & Corner Engine: Timed
150 msintersection suppression disarm, pre-intersection error memory (preIntersectionError), post-intersection300 msspeed capping, dynamic pre-/post-pivot braking, and350 ms/800 msstraight gap bridging. - Curve Estimator & Avoidance: Asymmetric attack/release exponential moving average (
curveLatchDir) feeding Path A (outer-shoulder curve dodge) vs. Path B (4-point radar scan +±20°swivel straight dodge) with zero-floatPROGMEMarctan re-entry alignment. - Persistent Tuning Storage: 34-parameter
CarConfigstruct stored in ATmega328P EEPROM (EEPROM_MAGIC = 0xE305) with live validation and two-way$SET/$PACK synchronization.
Hardware & Electronics
- Microcontroller & Shield: Arduino Uno (
ATmega328P,16 MHz,32,148 / 32,256 BFlash,1,728 / 2,048 BSRAM) paired with our salvaged 15th-competition KeyestudioPCA9685I²C 4WD motor shield (0x47/0x40auto-detect,500 HzPWM,TB6612channels0–7). - Dual-Rail Power System:
2S LiPo(7.4–8.2 V, monitored onBATTERY_PIN = A1) feeding a 12 V DC-DC step-up boost converter for the 4WD motors and anLM25965 V step-down buck converter exclusively for the radar servo rail. - 5-Channel Floor IR Array: Center 3-channel array (
L = D6,M = D7,R = D8, active-HIGH) extended with wide-stance auxiliary wing sensors (FL = D13,FR = D12, inverted active-LOW). - Laser Radar, AI Vision & Display:
VL53L1XToF sensor (0x29) on digital servo pinD4(servoCenter = 82°),DFRobot HuskyLensAI camera (400 kHzI²C),HM-10BLE (9600 baud), and front8×16LED matrix (D9/D10).
Companion Software & Fabrication
- Web Bluetooth Cockpit (PWA / Android APK): Responsive
RoboCar v3.0app (web/index.html,web/app.js) with live telemetry gauges, geometric curvature profiler, radar servo trim tool, thought stream, and 34 EEPROM tuning sliders. - CAD & Custom Hardware Mounts: Custom Autodesk Inventor 3D-printed boom arm and brackets positioning the HuskyLens camera lookahead angle, radar servo, and auxiliary wing IR sensors.
// 5-Channel Line Tracking Floor Sensors (Socket P1 + Auxiliary Wing Sensors)
const byte sensor_L = 6;
const byte sensor_M = 7;
const byte sensor_R = 8;
const byte sensor_FL = 13; // Far Left wing sensor (D13)
const byte sensor_FR = 12; // Far Right wing sensor (D12)
const byte SERVO_PIN = 4; // Radar Servo on Arduino Digital Pin D4
// IR Receiver Pin
// Battery Voltage Sensor & Front 8x16 LED Matrix (Dedicated GPIO Pins)
const byte BATTERY_PIN = A1; // Battery Voltage on A1 (Shield)
const byte MATRIX_SDA_PIN = 9; // Front LED Matrix SDA (Brown wire on D9)
const byte MATRIX_SCL_PIN = 10; // Front LED Matrix SCL (White wire on D10)
// =========================================================================
// 2. Dynamic Configuration & EEPROM Storage100 Hz PD Line Tracking & Validation Trials
High-speed endurance tracks punish naive PID controllers on sharp turns, cross-tape intersections, broken-line gaps, and straights ending in obstacles. followLine() combines four mathematical safeguards inside its 10 ms control tick:
- Progressive Dual-Gain PD Steering: Applies gentler proportional gain (
kpGentle = 27) during minor centerline drifts and switches immediately to aggressive proportional gain (kpSharp = 52) with derivative damping (kd = 26) when outer sensors engage (|error| >= 1.5):
- Asymmetric EMA Curve Consistency Classifier: Distinguishes rapid straightaway PD oscillation from genuine bends using speed-normalized attack/release exponential moving averages:
- Distance-Proportional Obstacle Approach Governor: Smoothly ramps speed from
baseSpeedStraightdown toward a28 PWMcrawl inside65 cm(obstacleDistCm = 14 cm) regardless of curve state, guaranteeing clean evasion entry without sliding past the target:
- Zero-Float HuskyLens Pre-Entry Heading Angle: Converts camera arrow deltas into integer degrees via a
PROGMEMatanlookup during obstacle return arcs (alignWithLineVector()), triggering an in-place counter-pivot or tight counter-arc whenever approach steepness reaches :
Within 150 ms of exiting an intersection, L && M && R center-bar suppression disarms automatically so tight bends right after a cross-tape are caught immediately by the outer wing sensors (D12/D13), while preIntersectionError preserves directional damping across intersections and 300 ms mild speed capping stabilizes exit momentum.
Tactical Obstacle Avoidance & Vision Return
When currentForwardDist drops to <= 14 cm (obstacleDistCm), dodgeObstacle() snapshots curveLatchDir and selects between Path A (outer-shoulder curve bypass) or Path B (4-point radar ghost verification, standoff reverse to tooCloseDistCm = 10 cm, and ±20° clearance swivel scan) before handing re-entry angle correction to HuskyLens AI:
We validated the full multi-obstacle evasion stack extensively on our earlier test track before competition day, verifying smooth S-curve tracking, reliable obstacle detection, outer-shoulder bypass arcs, and clean line reacquisition across three consecutive obstacles along the tape.
Web Bluetooth Cockpit & Two-Way EEPROM Sync
Instead of re-flashing the Arduino over USB between heats, RoboCar v3.0—a responsive Web Bluetooth PWA packaged as a native Android APK—communicates directly over the HM-10 BLE GATT serial channel (9600 baud). On connect, it automatically issues $GET,ALL to pull all 34 CarConfig parameters from EEPROM (0xE305), echoes every tuned constant back via $P,key,val acknowledgments, highlights modified parameters against their factory defaults (MODIFIED / Orig:), and visualizes real-time loop frequency, battery voltage, radar clearance, evasion state phases, and the robot's live thought stream.
Pre-Competition Crisis, Race-Day Deviations & Lessons Learned
The Night-Before Shield Burnout & 15th-Shield Transplant
The evening before the competition (November 4), the 16th-edition Keyestudio KS0559 motor shield burnt out completely. With zero time to source a replacement, I pulled our 15th-competition Keyestudio 4WD shield out of storage. Unlike the KS0559—which drove motors directly from Arduino digital/PWM pins with inverted 255 - speed logic—the 15th shield drives four TB6612 motor channels over I²C through a PCA9685 12-bit PWM controller.
Between 10:25 PM and 11:18 PM across four rapid commits (dd7a8f0 → 1762760), I rewrote the entire motor driver layer in src/handwritten.cpp: integrating Adafruit_PWMServoDriver (0x47/0x40 auto-detect), inverting forward/reverse polarity (FORWARD = 4095, BACKWARD = 0), swapping left/right motor bank assignments (M12_IS_LEFT = false), detaching the radar servo off the PCA9685 onto Arduino pin D4 (Servo library) so motor PWM could run at a high-torque 500 Hz instead of 50 Hz, relocating the battery monitor pin (A0 → A3 → final A1), and trimming verbose prints so the extra library still fit inside 32 KB Flash.
void drive(int leftSpeed, int rightSpeed) {
leftSpeed = constrain(leftSpeed, -255, 255);
rightSpeed = constrain(rightSpeed, -255, 255);
lastLeftDrive = leftSpeed;
lastRightDrive = rightSpeed;
int leftDir = (leftSpeed >= 0) ? FORWARD : BACKWARD;
int leftPwm = (int)(((long)abs(leftSpeed) * 4095L) / 255L);
int rightDir = (rightSpeed >= 0) ? FORWARD : BACKWARD;
int rightPwm = (int)(((long)abs(rightSpeed) * 4095L) / 255L);
if (M12_IS_LEFT) {
setMotor(1, leftDir, leftPwm);
setMotor(2, leftDir, leftPwm);
setMotor(3, rightDir, rightPwm);
setMotor(4, rightDir, rightPwm);
} else {
setMotor(1, rightDir, rightPwm);
setMotor(2, rightDir, rightPwm);
setMotor(3, leftDir, leftPwm);
setMotor(4, leftDir, leftPwm);
}
}3 Hours Before the Bus: Broken BLE Pins & Power Switch Surgery
Just 3 hours before I had to leave for school on competition morning, the replacement shield threw two more hardware failures at once under intense time pressure:
- Snapped Bluetooth Header Pins: The HM-10 header pins on the year-old 15th shield were already fatigued from last year's competition and broke completely. I had to desolder and replace the header on the spot while watching the clock tick down toward departure.
- Mechanical Switch-Mechanism Surgery: The replacement shield's onboard power switch was also broken. Directly desoldering and moving the working switch from the burnt 16th shield onto the 15th board was impossible because their pinouts and board positions didn't match. Instead, I opened the switch housings themselves, carefully extracted the internal sliding button mechanism from the 16th shield's switch, and transplanted the internal mechanism directly into the 15th shield's switch body—restoring reliable power switching just in time to film our final 5:49 AM validation run 11 minutes before catching the 6:00 AM bus.
Solving the 4:18 AM 78-Byte HM-10 BLE Overflow
At 4:18 AM, restoring the 1 Hz $FPS diagnostic packet initially pushed Flash to 32,240 / 32,256 bytes (100.0% — 16 bytes free) and broke all live Cockpit updates (distance, battery, and MCU/PD Hz froze while fragmented garbage flooded the Diagnostics box). Tracing the UART stream revealed that transmitting $T (53 bytes) immediately followed by $FPS (25 bytes) in the same tick created a 78-byte burst at 9600 baud—overflowing both the 64-byte Arduino UART TX buffer and the 20-byte HM-10 BLE MTU so \r\n terminators dropped mid-packet.
Converting sendBluetoothTelemetry() to Time-Division Multiplexing (TDM)—dedicating slots 1–9 strictly to $T and slot 10 exclusively to $FPS—capped every burst at <= 53 bytes with ~45 ms of idle bus recovery between frames, dropping Flash back down to 32,148 / 32,256 bytes (99.7%).
void sendBluetoothTelemetry() {
if (!telemetryActive)
return;
unsigned long now = millis();
if (now - lastTelemetryTime < 100)
return; // 10 Hz telemetry stream
lastTelemetryTime = now;
static byte telemCount = 0;
if (++telemCount >= 10) {
telemCount = 0;
// Transmit $FPS benchmark frame on dedicated 100ms time slot.
// By alternating slots instead of bursting with $T, the UART buffer never overflows
// and HM-10 BLE stack never chokes or drops characters.
Serial.print(F("$FPS,"));
Serial.print((unsigned int)loopCycleCount);
sendCommaVal(pdCycleCount);
sendCommaVal(maxLoopMs);
sendCommaVal(maxPdGapMs);
sendCommaVal(lastDodgeDurationMs);
Serial.println();
loopCycleCount = 0;
pdCycleCount = 0;
maxLoopMs = 0;
maxPdGapMs = 0;
return;
}Published Competition Spec vs. Event-Day Arena Reality
One of the biggest engineering surprises happened when we actually saw the official arena. The published RIT Dubai ALFRED technical specification described an approximately 5 × 5 m progressive three-level course with 20 mm black tape, clean start-to-end tracks, and 3D-printed obstacles positioned alongside the line.
On competition day, however, the physical arena diverged drastically from those published specs:
- Compact Maze Footprint (
~1 × 1 m): Instead of a sweeping5 × 5 mstart-to-end endurance track, the layout was compressed into a tight maze barely1 × 1 macross, with adjacent paths packed tightly together. - Narrower
~15 mmLine Width: The tape measured roughly15 mmwide rather than the stated20 mm, tightening sensor margin across sharp bends. - Unused Obstacle Avoidance: The obstacles weren't even full height as specified and had to be double-stacked—and ultimately weren't positioned in the robot's line of travel, meaning our entire VL53L1X + HuskyLens obstacle-dodging state machine was never even triggered during official runs.
Even though our hardest-worked subsystem never got to run on stage, the architecture we built for worst-case reliability paid off immediately: timed 150 ms intersection disarm, wide-stance 5-channel IR tracking, dynamic pre-/post-pivot braking, and instant trackside EEPROM tuning over RoboCar v3.0 let us dial down straightaway speeds (90 PWM) and tighten corner response for the cramped 1 × 1 m maze in seconds—securing 1st Place.


