Skip to the content
4 layers52.8 × 56.4 mmESP32 Motor Controller, the printed circuit board in 3D

Design and development of a portable, self contained closed loop Field Oriented Controller (FOC) for Brushless DC (BLDC) motors built on the ESP32 S3 via a custom designed PCB.

Size
52.8 × 56.4 mm
Copper layers
4
Thickness
1.66 mm
Parts
154
Nets
114
Pads
612
Tracks, vias
1,264, 270
Pours
42
Routed
Yes
KiCad
KiCad 9.0 (file 20241229)
Created
3 Nov 2025
Updated
2 Nov 2026

Overview

ESP32 Motor Controller is an open-source printed circuit board by Angelpele, from the Angelpele/Integrated_FOC_BLDC_Actuator repository on GitHub, published under the MIT licence. It is a 4-layer board of 52.8 × 56.4 mm with 154 parts on 114 nets, routed with 1,264 tracks and 270 vias.

It is built around the MCP2551-I/SN-HG, ESP32-S3-WROOM-1-N8 and DRV8302DCAR, with the MT6701CT-AKD-R, BMI270 and TLV75733PDBV among its other parts. Its parts include 54 capacitors, 43 resistors, 11 diodes, 7 transistors and 5 ICs. It belongs with the robots and motor control boards and the ESP32 boards of this library.

Main components

12

README

README.md

Integrated FOC BLDC Actuator

A portable, self-contained closed loop Field Oriented Controller (FOC) for Brushless DC (BLDC) motors built on the ESP32-S3 via a custom designed PCB. This project focuses on the development of a robust FOC controller for BLDC motors to be integrated into future robotic systems, such as robotic arms or other kind of robots. The controller combines the advantages of different motor technologies, offering:

  • The speed of a BLDC motor
  • The precision of a stepper motor
  • The torque provided by cycloidal gear reductions

Both CAD and 3D printed preliminary models


Features and Goals

  • High Performance: Closed-loop sinusoidal PWM (SPWM) field-oriented control for precise speed, position, and torque management.
  • Integrated Protection: Reverse polarity protection (RPP), fault detection for overvoltage, overcurrent, DRV8302 hardware faults (NFAULT/NOCTW), magnetic encoder field anomalies and IMU fault.
  • Advanced Sensors: Magnetic encoder (MT6701) for precise motor shaft angle, BMI270 IMU for 3D acceleration and gyroscope tracking, and NTC thermistor for temperature monitoring.
  • Modularity: Designed for portability and adaptability across multiple robotic platforms. Independent sensor and driver classes with clean interfaces.
  • Multi-Task Architecture: FreeRTOS task scheduler on dual cores with semaphore and mutex protected shared data and a hardware timer ISR for all the control loops.
  • CAN Bus Communication: MCP2551 transceiver for daisy chain communication in robotic systems.
  • Power Bus Connection: Dual XT30 connectors provide easy connection between different motors in the same bus.

Hardware

Core Components

  • Microcontroller: ESP32-S3 WROOM (dual core, 240 MHz)
  • Motor Driver: DRV8302 3 phase gate driver with integrated current sense amplifiers
  • Sensors:
    • MT6701 Magnetic Encoder: SSI interface, 14 bit resolution (16384 counts/rev), diametrically magnetized rotor for absolute shaft angle
    • BMI270 IMU: 3 axis accelerometer and gyroscope via 3 wire SPI
    • NTC Thermistor: B=3380 K, real time board temperature monitoring with Steinhart Hart equation
    • PVDD Voltage Divider: Resistor divider on ADC2 for bus voltage monitoring
  • CAN Transceiver: MCP2551 for multi motor communication at up to 1 Mbps

Protection Features

  • Reverse polarity protection with integrated MOSFET and parallel zener diode
  • TVS protection against exterior ESD discharges
  • Overvoltage detection on PVDD (configurable threshold) with immediate driver shutdown
  • DRV8302 hardware fault latch (NFAULT + NOCTW) with software latch counter and hysteresis
  • MT6701 magnetic field anomaly detection
  • IMU wrong data detection
  • Watchdog timer (WDT) subscription on all FreeRTOS tasks to catch runaway loops

Soldered PCB V1


Mechanical Design

  • Cycloidal Gearbox: For torque amplification and precision gain, 15:1 gear reduction. Features dual disc configuration to supress motor vibrations.
  • Modified motor coupling: The motor and gearbox coupler presents a D slot to transfer the rotation power without the need for small screws as in previous versions.
  • Integrated bearings: Metallic bearings offer a smooth movement of the gearbox with outer steel pins.
  • Integrated Motor: 5010 750KV motor integrated into the enclosure.
  • Integrated PCB: The PCB support has been designed to be as compact as possible, reading the magnet from the motor axis and preventing external cables outside the casing.
  • Custom PCB (V1): Compact integration of ESP32-S3, DRV8302, MT6701, BMI270, MCP2551, and NTC. Schematic available in ESP32_Motor_Controller_V1.pdf.
  • Custom PCB (V2): Several improvements implemented and corrected errors from V1:
    • Voltage upgrade: Input raised to 36 V (MOSFET max 40 V); RPP, TVS diode, phase voltage dividers, and MOSFET selection updated accordingly (targeting ≥50 V rating).
    • Dual configuration for higher power motors and lower power ones (16V vs 36V).
    • Passives:
      • Large-value caps (22 µF, 1 µF) moved to 0805+ for voltage headroom
      • All MOSFET line power caps in 0805
      • GVDD/AVDD/DVDD decoupling can stay 0603 (16 V rated)
      • BOM consolidated to reuse values/footprints.
    • Layout:
      • Power and sensor zones separated
      • Routing improved with stitching vias
      • External pull-up resistors added on I2C lines
    • Gate series resistance tuned.
    • Schematic available in ESP32_Motor_Controller_V2.pdf.

Mechanical CAD Design


Firmware Architecture

State Machine

The main task runs a three-state machine:

text
SYSTEM_INIT → SYSTEM_CALIBRATION → SYSTEM_RUNNING
  • INIT: Initializes MT6701 and DRV8302. Retries on failure.
  • CALIBRATION: Sets up MCPWM, performs current sense offset calibration (DC_CAL pulse, 500 samples averaged), and magnetic encoder field quality check (1000 samples).
  • RUNNING: Monitors faults in the main loop; all control logic runs in ISR-driven FreeRTOS tasks.

Control Loop (Timer ISR at 20 kHz)

A hardware timer (APB clock / 80 divider = 1 MHz, alarm at 50 µs) triggers task notifications at divided rates:

TaskRateCorePriority
focLoop20 kHz110
magLoop5 kHz19
drvLoop500 Hz08
telemetryLoop100 Hz02

All shared data (drv_pkg, mag_pkg) is protected by FreeRTOS mutexes.

SPWM Generation

DRV::update_spwm() runs three stages:

  1. Alignment (Open loop): Ramps duty cycle over 500 ms to lock rotor to a known electrical angle. Computes elec_offset from the MT6701 reading at alignment.
  2. Frequency Ramp: Linearly ramps electrical_freq from 2 Hz to target_electrical_freq (20 Hz default) at 100 Hz/s.
  3. Closed Loop SPWM: Uses MT6701 angle + elec_offset + pole pairs (7) to compute instantaneous electrical angle.

Motor parameters (5010 750KV, 14 poles, 270 mΩ phase resistance, 40 A max) are defined as constexpr in DRV.h.

Current Sensing

  • Two shunt channels (SO1, SO2) on ADC1 with DRV8302 internal amplifier (gain selectable via GAIN pin, default 40×, R_shunt = 10 mΩ)
  • DC offset calibration via DC_CAL pin pulse at startup, sanity-checked against 12-bit midpoint (valid range 1000–3000)
  • Third phase current reconstructed as I_C = -(I_A + I_B)

Software

  1. Motor Calibration: Automated at boot — current sense offset calibration and magnetic field quality verification.
  2. Real Time Telemetry: UART serial output at 100 Hz: PVDD voltage, phase currents, raw ADC values, NFAULT/NOCTW states, NTC temperature, and encoder angle/status.
  3. Debug Mode: debug_mode_enabled flag bypasses the state machine for rapid hardware-in-the-loop testing.
  4. Fault Override: Per-subsystem override flags (DRV::set_override, MT6701::set_override) for bench testing without a valid magnetic field or full power stage.

Integration with ROS2 and a graphical PID tuning interface are planned for future iterations.


References

Parts

154
QtyValueFootprintReferences
130.1uFCapacitor_SMD:C_0402_1005MetricC202, C204, C205, C305, C322, C402, C406, C409, C501, C502, C503, C507, C508
1010uFCapacitor_SMD:C_0805_2012MetricC104, C105, C106, C107, C108, C109, C110, C111, C112, C113
910kResistor_SMD:R_0402_1005MetricR103, R201, R303, R304, R305, R403, R410, R415, R509
610RResistor_SMD:R_0603_1608MetricR401, R402, R406, R407, R411, R412
6FH4008GSPackage_DFN_QFN:PQFN-8-EP_6x5mm_P1.27mm_GenericQ401, Q402, Q403, Q404, Q405, Q406
51N4002Diode_SMD:D_SOD-123D102, D302, D401, D402, D403
40.1uFCapacitor_SMD:C_0603_1608MetricC306, C307, C308, C321
4100kResistor_SMD:R_0402_1005MetricR310, R404, R409, R414
41uFCapacitor_SMD:C_0603_1608MetricC114, C115, C201, C320
4MountingHoleMountingHole:MountingHole_3.2mm_M3MP_1, MP_2, MP_3, MP_4
30.1uFCapacitor_SMD:C_0805_2012MetricC312, C315, C316
30RResistor_SMD:R_0402_1005MetricR501, R502, R503
31nFCapacitor_SMD:C_0402_1005MetricC318, C403, C404
32.2 uFCapacitor_SMD:C_0805_2012MetricC401, C405, C408
20.01RResistor_SMD:R_2512_6332MetricR405, R408
2100RResistor_SMD:R_0603_1608MetricR506, R507
210kResistor_SMD:R_0603_1608MetricR308, R312
22.2nFCapacitor_SMD:C_0402_1005MetricC309, C310
22.2uFCapacitor_SMD:C_0805_2012MetricC311, C313
23V3LED_SMD:LED_0603_1608MetricD201, D204
25,1kResistor_SMD:R_0402_1005MetricR101, R102
2560pFResistor_SMD:R_0402_1005MetricC504, C505
256RResistor_SMD:R_0603_1608MetricR202, R205
256RResistor_SMD:R_0402_1005MetricR301, R302
2TS-1088-AR02016TS-1088-AR02016:SW_TS-1088-AR02016SW1, SW2
2XT30PW-MXT30PW-M:AMASS_XT30PW-MJ101, J102
1-kInductor_SMD:L_0603_1608MetricFB
10.015uFCapacitor_SMD:C_0402_1005MetricC304
10.022uFCapacitor_SMD:C_0402_1005MetricC303
1100kResistor_SMD:R_0603_1608MetricR313
11100RResistor_SMD:R_0603_1608MetricR204
1121RResistor_SMD:R_0603_1608MetricR504
112uHSM7850 Inductor:SM7850L301
112uHCapacitor_SMD:C_0603_1608MetricC319
1150RResistor_SMD:R_0603_1608MetricR203
115pFCapacitor_SMD:C_0402_1005MetricC317
116VLED_SMD:LED_0603_1608MetricD203
11uFCapacitor_SMD:C_0402_1005MetricC506
12.2uFCapacitor_SMD:C_0603_1608MetricC302
1200kResistor_SMD:R_0402_1005MetricR307
122uFCapacitor_SMD:C_0805_2012MetricC203
13.3kResistor_SMD:R_0402_1005MetricR311
13V3TestPoint:TestPoint_Pad_D1.0mmTP9
14.7uFCapacitor_SMD:C_0805_2012MetricC314
14k7Resistor_SMD:R_0402_1005MetricR505
152.3kResistor_SMD:R_0603_1608MetricR309
15VLED_SMD:LED_0603_1608MetricD202
15VTestPoint:TestPoint_Pad_D1.0mmTP13
186.6kResistor_SMD:R_0402_1005MetricR306
1AVDDTestPoint:TestPoint_Pad_D1.0mmAV
1A_SENSETestPoint:TestPoint_Pad_D1.0mmA
1B360B3030A:B3030AD301
1BMI270BMI270:XDCR_BMI270U501
1BZT52C18Diode_SMD:D_SOD-123D101
1B_SENSETestPoint:TestPoint_Pad_D1.0mmB
1CANJumper:SolderJumper-2_P1.3mm_Open_Pad1.0x1.5mmJP3
1CAN1Connector_JST:JST_PH_S2B-PH-K_1x02_P2.00mm_HorizontalJ502
1CAN2Connector_JST:JST_PH_S2B-PH-K_1x02_P2.00mm_HorizontalJ503
1C_SENSETestPoint:TestPoint_Pad_D1.0mmC
1Conn_01x01_PinConnector_PinHeader_2.00mm:PinHeader_1x01_P2.00mm_VerticalExt_Cap101
1DRV8302DCARDRV8302:DRV8302U301
1ESP32-S3-WROOM-1RF_Module:ESP32-S3-WROOM-1UESP 32
1GNDTestPoint:TestPoint_Pad_D1.0mmGND
1Hall EncoderConnector_JST:JST_PH_S5B-PH-K_1x05_P2.00mm_HorizontalJ501
1MCP2551-I_SNMCP2551-I_SN:SOIC127P599X175-8NU502
1MT6701CT-AKDMT6701CT-STD-R:SOIC127P600X175-8NIC501
1NTC 10kResistor_SMD:R_0603_1608MetricTH1
1PESDNC2Diode_SMD:D_0201_0603MetricTVS101
1PVDDTestPoint:TestPoint_Pad_D1.0mmPV
1Pad401MountingHole:MountingHole_2.5mm_Pad_ViaMP1
1Pad402MountingHole:MountingHole_2.5mm_Pad_ViaMP2
1Pad403MountingHole:MountingHole_2.5mm_Pad_ViaMP3
1SMAJ30CADiode_SMD:D_SMCTVS103
1SOLDER - RPPJumper:SolderJumper-2_P1.3mm_Open_Pad1.0x1.5mmJP1
1SOLDER - XRPPJumper:SolderJumper-2_P1.3mm_Open_Pad1.0x1.5mmJP2
1SRV05-4Package_TO_SOT_SMD:SOT-23-6TVS102
1TLV75733PDBVPackage_TO_SOT_SMD:SOT-23-5U2
1USB_C 3.1Connector_USB:USB_C_Receptacle_Palconn_UTC16-GUSB-C
1XRS80P06FXRS80P06F:XRS80P06FQ1

Similar boards

  • 4 layers100 × 75 mmDF ESC rev01 1, the printed circuit board in 3D

    DF ESC rev01 1

    ivanmendezalonso/KICAD_repo

    Aqui estaran todos las carpetas de proyectos

    194 parts
  • 4 layers113 × 100.2 mmSTM32 - BLDC Driver, the printed circuit board in 3D

    STM32 - BLDC Driver

    FredrikLLarsen/STM32F411_DRV8302_FOC_PCBA

    162 parts
  • 4 layers69 × 39 mmJPBms2, the printed circuit board in 3D

    JPBms2

    jakepoz/jpbms

    JPBms is a simple BMS for solar charging and balancing a 3-cell lithium ion battery.

    132 parts2
  • 2 layers46.3 × 53.3 mmLilypad V5, the printed circuit board in 3D

    Lilypad V5

    LilypadVR/LilypadVR

    Full Body Tracking for VR, based on SlimeVR

    61 parts
  • 2 layers187.5 × 45 mmGamma spectrometer, the printed circuit board in 3D

    Gamma spectrometer

    Motokichirou/gamma-spectrometer

    NaI(Tl) gamma spectrometer: STM32G474 + R1307 PMT + 4-board stack, KiCad schematics, LTspice simulations

    231 parts
  • 2 layers70 × 35 mmTLF35584 breakout, the printed circuit board in 3D

    TLF35584 breakout

    rusefi/rusefi

    rusefi - GPL internal combustion engine control unit

    41 parts1.2k
  • 4 layers150 × 90 mmMotherboard, the printed circuit board in 3D

    Motherboard

    Foosa7/koi_8x8

    The controller board for Koi 8×8. Carries a Raspberry Pi Pico (RP2040) and hosts up to 8 daughterboards in PCIe-x4 card-edge slots, addressing each board's DAC/ADC over a shared SPI bus. Formerly codenamed MOBO.

    56 parts2

Questions

How big is the ESP32 Motor Controller PCB?

It measures 52.8 × 56.4 mm and has 4 copper layers, 1.66 mm thick.

What parts does the ESP32 Motor Controller use?

154 parts, built around the MCP2551-I/SN-HG, ESP32-S3-WROOM-1-N8, DRV8302DCAR and MT6701CT-AKD-R. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the ESP32 Motor Controller KiCad files?

From the Angelpele/Integrated_FOC_BLDC_Actuator repository on GitHub, at the commit this page was made from: the board is Hardware/ESP32_Motor_Controller/ESP32_Motor_Controller.kicad_pcb and its schematic Hardware/ESP32_Motor_Controller/CONTROLLER [2].kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the ESP32 Motor Controller design in my own project?

Its repository publishes it under the MIT licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).