svg
Sub-Millisecond PID
PROJECT // HW-04 Autonomous Robotics 16-Channel IR Array Closed-Loop PID Control

High-Speed Autonomous Line Follower Robot

Modular Dual-Board Architecture Designed in EasyEDA: 16-Channel IR Sensor Array, Custom ESP32 Controller, Dual H-Bridge Motor Drivers, and Onboard Battery Management.

Sensor Bar

16-Channel IR Array

Ultra-wide 16-channel phototransistor bar delivering high spatial resolution to track sharp bends, 90° corners, and line crossings without blind spots.

EasyEDA

Dual-Board System

Modular architecture splitting the front sensor bar from the central controller to isolate high-frequency optical signals from inductive motor spikes.

Dual H-Bridge

Motor & Power Stage

High-current dual H-bridge motor drivers, flyback protection diodes, low-ESR bulk capacitors, and wide copper planes for aggressive acceleration.

Live Tuning

OLED & Field Tuning

Integrated 0.96" OLED display and onboard tactile push buttons enable live field adjustment of PID constants (Kp, Ki, Kd) without computer connection.

// HARDWARE DESIGN LIFECYCLE Designed on EasyEDA: Dual-Board Architecture

Autonomous line tracking at high velocities poses severe electrical challenges: inductive voltage spikes and EMF noise from rapid motor switching can corrupt sensitive analog IR sensor readings. To conquer this, the hardware was split into two dedicated custom PCBs designed in EasyEDA:

Subsystem 1 Optical Array

16-Channel IR Sensor Bar

Schematic features 16 matched IR emitter-receiver pairs mounted in an elongated linear geometry at the front bumper. Provides a continuous spatial gradient across a 150mm track span, resolving acute curves and sharp angled turns.

✓ 150mm Linear Front Coverage
Subsystem 2 Central Base Board

ESP32 Core & Power BMS

Schematic titled base board featuring the ESP32 microcontroller running dual-core FreeRTOS PID loops, onboard 3.3V buck step-down regulation, battery voltage divider for fuel-gauging, and tactile input buttons.

✓ 240MHz FreeRTOS Control Loop
Subsystem 3 PCB Layout & Traces

High-Current Trace Routing

Routed in EasyEDA with 40-mil power traces for dual H-bridge motor outputs, flyback suppression diodes, star ground return paths to eliminate ground bounce, and isolated signal routing for the I2C OLED display.

✓ 40-mil Traces & Star Grounding
// CLOSED-LOOP PID MOTOR CONTROL Sub-Millisecond Loop

To maintain maximum forward velocity without oscillating off the track, the ESP32 executes a weighted average position algorithm across the 16 IR sensors:

// Weighted Center of Mass Calculation & Differential PID Output

Position = (∑ (Sensor[i] × Weight[i])) / (∑ Sensor[i]);

Error = Position - Target_Center;

// Differential PID Correction

Output = (Kp * Error) + (Ki * Integral) + (Kd * Derivative);

Left_Motor = Base_Speed + Output;

Right_Motor = Base_Speed - Output;

The Proportional term (Kp) responds instantly to line offset, the Derivative term (Kd) dampens overshoot on sharp entry into corners, and the Integral term (Ki) removes steady-state drift on sweeping turns.

// INTERACTIVE SIMULATOR Interactive PID Response Simulator
PID LOOP RUNNING

Live Sensor Gradient & Motor Differential

Adjust the simulated track curve to see the 16-channel sensor array detect position and observe how the ESP32 computes differential motor speeds:

Simulated Line Offset: Centered (0 mm)
16-CHANNEL IR SENSOR BAR (LIVE BEAM MATRIX) Active: S8, S9
1
S1
2
S2
3
S3
4
S4
5
S5
6
S6
7
S7
8
S8
9
S9
10
S10
11
S11
12
S12
13
S13
14
S14
15
S15
16
S16
Left Motor PWM 200 (80%)
Right Motor PWM 200 (80%)
PID Correction STABLE (0) Both motors balanced
// POWER INTEGRITY & NOISE SUPPRESSION Battery Management & Noise Suppression

DC brushed gearmotors generate continuous high-frequency inductive flyback spikes during PWM switching. Without isolation, these transients can reset the ESP32 microcontroller or cause erratic ADC conversions.

Dedicated Dual Ground Planes

Analog optical ground and digital/motor high-current ground meet only at a single star point at the battery input.

Onboard Buck Regulation

Efficient DC-DC buck converter drops battery voltage (7.4V LiPo / 2S) down to an ultra-clean 3.3V rail with high ripple rejection.

Flyback Clamping

Fast Schottky diodes across motor terminals clamp reverse inductive spikes instantly.

Hardware Calibration Buttons

Tactile buttons connected to interrupt pins allow cycling through PID parameters and setting calibration offsets directly on the track.

// HARDWARE SPECIFICATIONS Robotics Stack & Electronics
10 Specifications
PCB Design Suite

EasyEDA (Dual 2-Layer Boards)

Microcontroller

ESP32 Dual-Core 240MHz Core

Sensor Array

16-Channel High-Density IR Bar

Motor Driver

Dual H-Bridge High-Current Driver

Actuators

Micro Metal Gearmotors (High-RPM)

Onboard Telemetry

0.96" I2C OLED (128x64)

Control Algorithm

High-Frequency PID (Weighted Average)

User Interface

Tactile Push Buttons (On-Board Tuning)

Power System

LiPo Battery with Regulated BMS & Filtering

Grounding Strategy

Star Ground & Isolated Motor Copper Pour

// PIT-STOP TELEMETRY Onboard Dashboard

OLED Interface & Live Telemetry

The 0.96" SSD1306 I2C OLED display mounted directly on the controller board provides an interactive pit-stop dashboard:

Live 16-sensor optical bar graph
Real-time battery voltage monitoring
Push-button PID tuning menu (Kp, Ki, Kd)
Lap timer & track speed analytics
Return to All Projects