MECHATRONICS / CONTROL SYSTEMS · INDEPENDENT HARDWARE PROJECT

ESP32 dual-axis self-levelling gimbal

A two-axis stabilisation demonstrator integrating an MPU6050 inertial sensor, ESP32 firmware, complementary filtering, PID control, MG996R servos, a custom two-layer KiCad PCB and a modified 3D-printed Fusion 360 frame.

CONTROLESP32 · MPU6050 · complementary filter · independent roll/pitch PID
HARDWARECustom carrier PCB · MG996R servos ×2 · PLA frame
VALIDATED SCOPELimited-angle correction; servo travel restricted to ±5° around neutral

01 / PROJECT BRIEF

What the prototype was designed to do

The objective was to keep a moving platform approximately level by estimating its roll and pitch, calculating corrective commands and driving two servo axes. The design combined control software with a physical structure, electrical power distribution and a browser-based monitoring interface.

2 axesRoll and pitch correction
±5°Validated servo command travel about calibrated neutral
70 × 55 mmTwo-layer carrier PCB footprint
60% infillPLA FDM structural parts

Scope: This is a working limited-angle engineering demonstrator, not a precision-stabilised or wide-range commercial gimbal. The reported ±5° figure refers to restricted servo motion, not measured platform attitude accuracy.

02 / CLOSED-LOOP CONTROL

Sensor fusion, feedback and servo correction

An MPU6050 mounted on the moving platform provides accelerometer and gyroscope readings. The ESP32 uses both measurements to estimate attitude, compares it with the requested target and commands roll/pitch correction through two MG996R servos.

01Measure

Acquire MPU6050 accelerometer and gyroscope values over I²C.

02Estimate

Combine integrated gyro rate and accelerometer attitude using a complementary filter.

03Control

Calculate roll/pitch error and proportional-derivative correction, with integral gain at zero.

04Actuate

Apply correction around calibrated servo neutral positions within constrained travel.

Complementary filter and feedback
Attitude estimate
θ̂k = α(θ̂k−1 + ωk Δt) + (1 − α)θacc,k
Control error
e(t) = θsetpoint(t) − θ̂(t)
PID law
u(t) = Kpe(t) + Ki ∫e(t) dt + Kd de(t)dt
α = 0.96. Final tuning used Ki = 0, so the implemented controller operated as a PD controller, although the firmware supports PID.
AxisKpKiKd
Roll1.50.00.1
Pitch1.50.00.1

Controller gains were adjusted for the assembled prototype, not identified from a measured dynamic model. The filter reduces gyroscope drift while retaining short-term gyro responsiveness; it cannot correct mechanical backlash or insufficient servo supply current.

03 / ELECTRICAL & PCB DESIGN

From breadboard to a manufactured carrier PCB

A compact two-layer KiCad board replaced the breadboard wiring, with socketed ESP32 headers, servo connectors, a remote MPU6050 connector, labelled power input and mounting holes. The carrier approach kept the major modules removable for testing and reuse.

ItemDesign / connectionEngineering purpose
ESP32 Dev BoardSocketed headers; USB-powered controllerFirmware, servo commands and Wi-Fi dashboard
MPU6050I²C SDA GPIO 21, SCL GPIO 22; remote 4-pin connectionMeasures orientation of the moving platform rather than fixed base
MG996R ×2Roll signal GPIO 13; pitch GPIO 19Independent axis actuation; GPIO 19 replaced bootstrap-related GPIO 12
Servo supply18650 batteries in parallel → MT3608 boost → external 5 V railAvoids drawing servo current from the ESP32 logic supply
Bulk / local capacitors1000 µF on servo rail; 100 nF local decouplingSupports transient rail behaviour; does not guarantee current capacity
PCB routing1.0 mm 5 V/GND; 0.4 mm 3.3 V; 0.3 mm signal tracesWider current-carrying paths than the control signals
KiCad electrical schematic; select to open the full-resolution file
KiCad schematic and connector integration - Expand ↗
KiCad three-dimensional rendering of the ESP32 custom gimbal carrier PCB
Routed PCB: 70 × 55 mm with labelled headers and M3 mounting - Expand ↗
Photographs of both sides of manufactured ESP32 gimbal carrier PCB
Manufactured PCB, front and rear - Expand ↗
Assembled gimbal internal electronics, carrier PCB and power components mounted inside enclosure
PCB and wiring integrated into the physical enclosure - Expand ↗

Power limitation: Large or abrupt servo movements produced unstable behaviour consistent with inadequate transient supply capability. A bulk capacitor and separate rail helped the design, but the demonstration still required small actuation limits. Voltage transient magnitude and peak current were not instrumented.

04 / CAD & MANUFACTURING

Modified two-axis frame and printed enclosure

The starting bracket and platform geometry was based on the HowToMechatronics self-stabilising platform. I adapted the model for a two-axis ESP32 implementation by removing yaw hardware and designing the electronics box, PCB mounting arrangement, cable cutouts and removable lid.

Fusion 360 CAD model of the gimbal mechanical assembly and electronics enclosure
Full Fusion 360 assembly - Expand ↗
CAD model of gimbal roll-servo bracket
Replaceable roll-servo bracket - Expand ↗
Fusion 360 electronics box featuring PCB mounting and routing cutouts
Electronics enclosure with PCB, power and wire clearance - Expand ↗
3D-printed electronics box and removable lid for the gimbal
Manufactured enclosure and removable lid - Expand ↗
01

Removable hardware

Socketed ESP32, detachable IMU and mechanically secured PCB enabled disassembly without destroying components.

02

Manufacturable design

Separate PLA FDM brackets, screw mounting, simple rectangular cutouts and a friction-fit lid reduced complexity.

03

IMU placement

The sensor attaches to the moving platform so the controller measures the attitude of the element being stabilised.

04

Structural compromise

Printed parts showed flex and slight deformation; static neutral offsets compensated the resting angle but could not eliminate the mechanical compliance.

PCB fabrication and 3D printing received student project manufacturing support from PCBWay. Sponsorship supported fabrication, not a claim of product certification.

05 / FIRMWARE & DASHBOARD

Control modes and disconnect handling

The PlatformIO / Arduino firmware runs the sensor-feedback loop and a local ESP32-hosted web server. The dashboard provides live roll/pitch values, sliders for commanded setpoints, a return-to-level control and a heartbeat that switches the system back to stabilisation if browser updates stop.

Web endpointPurpose
/dataRoll and pitch telemetry as JSON
/modeToggle stabilisation and manual setpoint control
/setpointUpdate desired roll/pitch angles
/heartbeatKeep-alive for setpoint mode; revert when absent
ESP32 gimbal dashboard preview showing roll and pitch indicators and control modes
Dashboard preview from project documentation - Expand ↗
ESP32 gimbal breadboard electronics prototype before PCB fabrication
Earlier breadboard testing before carrier PCB assembly - Expand ↗
Final firmware's servo limiting
constexpr int ROLL_NEUTRAL = 99;
constexpr int PITCH_NEUTRAL = 85;

constexpr int ROLL_MIN_POSITION = ROLL_NEUTRAL - 5;
constexpr int ROLL_MAX_POSITION = ROLL_NEUTRAL + 5;

constexpr int PITCH_MIN_POSITION = PITCH_NEUTRAL - 5;
constexpr int PITCH_MAX_POSITION = PITCH_NEUTRAL + 5;

Neutral values account for physical resting offsets. The ±5° restriction applies to the servo command around these calibrated positions; it is not an angle-error measurement. The OLED used in early development was omitted from the final physical build.

06 / VALIDATION

Development sequence and demonstrated behaviour

01

Wokwi simulation

Checked basic sensor fusion, servo commands, Wi-Fi interface logic and control modes before powering physical hardware.

02

Breadboard test

Confirmed IMU communication, servo directions, setpoint control and operation using separated controller/servo supplies.

03

PCB and mechanical integration

Finished KiCad routing and DRC, ordered the PCB, soldered the board and assembled printed parts and power electronics.

04

Limited-angle demonstration

Recorded observable roll/pitch correction and dashboard telemetry with both servo axes restricted to ±5° of command travel around calibrated neutral.

Evidence boundary: Physical photographs, KiCad images, code, design files and a demonstration video support completion of the prototype and limited-angle correction. No traceable settling-time measurements, calibrated angular-accuracy data or recorded supply-transient waveforms are provided. Precision stabilisation and high-disturbance performance are not claimed.

07 / DESIGN LESSONS

Why the final range was limited

The electronics and mechanical structure constrained achievable control performance. Sudden servo movements could exceed the practical power-delivery capability of the battery/boost arrangement, while structural flex and alignment offsets complicated tuning. Restricting actuation produced a demonstrable, repeatable operating condition for the completed project.

Future iteration: Rebuild the hardware, log command and attitude data, independently measure angle response, instrument the 5 V rail during servo transients, improve bracket stiffness and evaluate a higher-current 5–6 V regulator. These are planned experiments, not completed validation.