Skip to content

Motor · ESP32 guide

Controlling Brushless Motor (BLDC) with ESC with ESP32

How a 30A ESC drives an A2212 brushless motor: wiring, the 1000–2000 µs throttle signal, arming, calibration and sizing.

Updated November 16, 2026 Arduino C++ESP32ServoAlso forArduino Uno

What is the BLDC ESC?

A brushless DC (BLDC) motor has no brushes, so it can't run from a plain DC supply. It needs an ESC (electronic speed controller): a small board that switches the battery current through the motor's three wires in the right order, thousands of times a second. Your Arduino or ESP32 never powers the motor. It only sends the ESC a small throttle signal saying how fast to go.

This page uses the kit most makers start with: an A2212 1000KV motor, a 30A ESC and a 3S LiPo, as used on F450 quadcopters, RC planes and test rigs. You'll learn what each wire does, how the throttle signal works, why ESCs need arming and calibration, and how to size an ESC and battery. To drive one from a board, follow the Arduino Uno guide or the ESP32 guide.

Example kit specifications

Example kit
A2212 1000KV outrunner + 30A ESC + 3S 2200 mAh LiPo
ESC continuous / burst current
30 A / 40 A for 10 s (Hobbywing Skywalker 30A)
ESC input
2–3S LiPo (7.4–11.1 V nominal, 12.6 V full)
BEC output
5 V, 2 A linear (Skywalker 30A); many generic 30A ESCs list 5 V 3 A
Control signal
Servo-style PWM: 1000–2000 µs pulse at 50 Hz (after calibration)
Hobbywing default range
1100–1940 µs until you calibrate
Motor KV
1000 rpm per volt (no load): about 11,100 rpm on 11.1 V
Motor current
12 A for 60 s; best efficiency at 4–10 A
Motor no-load current
0.5 A at 10 V
Thrust (3S, 1045 prop)
About 700–800 g
Motor wires
3 phase wires, 3.5 mm bullet connectors

ESC figures from the Hobbywing Skywalker V2 manual; motor figures are the common A2212 1000KV listing. Check your own ESC's label: current, cell count and BEC rating vary by model.

ESC wires and where they go

  • Thick red (BAT+)

    Goes to
    LiPo + via XT60 or Deans
    Notes
    Check polarity before plugging in: reversed polarity can destroy the ESC
  • Thick black (BAT−)

    Goes to
    LiPo −
  • 3 motor wires

    Goes to
    The 3 motor wires (bullet connectors)
    Notes
    Any order works. Swap any two to reverse direction, with the LiPo unplugged
  • Signal (white, yellow or orange)

    Goes to
    Board PWM pin
    Notes
    Servo-style throttle pulse
  • Ground (black or brown, thin)

    Goes to
    Board GND
    Notes
    Required: the signal is measured against this ground
  • Red, thin (BEC +5 V)

    Goes to
    Leave unconnected if the board has USB or its own supply
    Notes
    Can power a receiver or a board on its own; never in parallel with USB

Wiring & code

Setting up BLDC ESC with ESP32

Library

ESP32Servo by Kevin Harrington

Library Manager: ESP32Servo

In this guide you'll control a brushless motor from an ESP32: a potentiometer becomes the throttle, the sketch arms the ESC safely, ramps the speed smoothly and caps it for bench testing. You'll also run a one-time calibration sketch so the ESC uses the full 1000–2000 µs range. At the end, you'll replace the knob with a throttle slider on your phone, with a failsafe that stops the motor if the connection drops.

It takes about 30 minutes. The motor never starts on its own: the sketch waits until the knob is at zero.

Danger

Propeller OFF for every test on this page. An A2212 on 3S spins at roughly 11,000 rpm with no load and can pull about 800 g of thrust with a 10-inch prop: enough to cut fingers. Clamp the motor down, keep hands clear, and unplug the LiPo before touching any wire.

What you need

  • ESP32 DevKit

    Qty
    1
    Notes
    Powered from USB
  • A2212 1000KV brushless motor

    Qty
    1
    Notes
    Or any 2–3S outrunner
  • 30A brushless ESC

    Qty
    1
    Notes
    SimonK, BLHeli or Hobbywing Skywalker
  • 3S LiPo, 2200 mAh, XT60

    Qty
    1
    Notes
    Charged with a proper balance charger
  • 10 kΩ potentiometer

    Qty
    1
    Notes
    The throttle knob
  • Jumper wires

    Qty
    5
    Notes
    Male-female for the ESC's servo plug
  • Clamp or motor mount

    Qty
    1
    Notes
    The motor must not move

How it fits together

There are two separate circuits, joined only by the signal and its ground:

  • Power circuit: LiPo → ESC → motor. Tens of amps, thick wires. The ESP32 never touches it.
  • Control circuit: USB → ESP32 → signal pin → ESC. A few milliamps.

The ESC's servo plug has three wires. Signal goes to GPIO18, the thin ground goes to GND, and the thin red wire (the ESC's 5 V BEC output) stays unconnected, because the ESP32 already has power from USB.

Wiring: ESC and potentiometer to ESP32

  • ESC signal (white/yellow/orange)ESP32 GPIO18

    Why
    Throttle pulse
  • ESC ground (thin black/brown)ESP32 GND

    Why
    Shared reference for the signal
  • ESC thin red (BEC 5 V)Not connected: tape it

    Why
    The ESP32 is on USB
  • Potentiometer ends3V3 and GND

    Why
    Throttle knob supply
  • Potentiometer middle pinESP32 GPIO34

    Why
    Knob position
  • ESC 3 motor wiresMotor's 3 wires

    Why
    Any order; swap two to reverse
  • ESC thick red/blackLiPo XT60

    Why
    Connected last, in step 6

Wire it up, step by step

  1. 1Remove the propeller and clamp the motor down.
  2. 2Plug the ESC's three motor wires into the motor's bullet connectors.
  3. 3Connect the ESC signal wire to GPIO18 and the thin ground wire to GND. Tape the thin red wire's pin.
  4. 4Wire the potentiometer: outer pins to 3V3 and GND, middle pin to GPIO34.
  5. 5Connect the ESP32 to your computer by USB. Leave the LiPo unplugged.
  6. 6Run the calibration sketch below (once per ESC), then upload the throttle sketch. Connect the LiPo only when the sketch tells you to.

Set up the IDE and calibrate (once per ESC)

  1. In Arduino IDE 2, install esp32 by Espressif Systems from the Boards Manager and select ESP32 Dev Module.
  2. In Library Manager, install ESP32Servo by Kevin Harrington. It generates servo pulses with the ESP32's LEDC hardware.
  3. Upload the calibration sketch below with the LiPo unplugged:
sketch.ino
// ESC throttle calibration (run ONCE per ESC). PROPELLER OFF.
// 1. Upload with the LiPo DISCONNECTED. 2. Open Serial Monitor (115200).
// 3. Follow the prompts. Sets the ESC range to 1000-2000 us.
#include <ESP32Servo.h>
Servo esc;

void waitForEnter() {
  while (Serial.available()) Serial.read();
  while (!Serial.available()) {}
  delay(50);
  while (Serial.available()) Serial.read();
}

void setup() {
  Serial.begin(115200);
  esc.setPeriodHertz(50);
  esc.attach(18, 1000, 2000);
  esc.writeMicroseconds(2000);                      // MAXIMUM first
  Serial.println(F("Sending 2000 us (max). Connect the LiPo to the ESC now."));
  Serial.println(F("When the ESC beeps to say max is stored, press Enter."));
  waitForEnter();
  esc.writeMicroseconds(1000);                      // then MINIMUM
  Serial.println(F("Sending 1000 us (min). Wait for the confirmation beeps."));
  delay(4000);
  Serial.println(F("Done. Unplug the LiPo. Upload the throttle sketch."));
}

void loop() {}

Open the Serial Monitor at 115200 baud and follow the prompts: plug in the LiPo while the sketch sends 2000 µs, press Enter after the "max stored" beeps, then wait for the "min stored" beeps. Unplug the LiPo. The exact tones depend on your ESC; the main page explains arming and calibration.

Arming at minimum throttle every power-up, and the one-time calibration from 2000 µs to 1000 µs.

The throttle sketch

sketch.ino
// BLDC motor + 30A ESC + ESP32: potentiometer throttle with safe start
// PROPELLER OFF while testing. ESC signal -> GPIO18, ESC signal ground -> GND,
// ESC red BEC wire NOT connected (the ESP32 runs from USB). Pot: 3V3 / GPIO34 / GND.
#include <ESP32Servo.h>

const int ESC_PIN = 18;
const int POT_PIN = 34;
const int  MIN_US  = 1000;   // after calibration: 0 % throttle
const int  MAX_US  = 2000;   // after calibration: 100 % throttle
const int  LIMIT_US = 1500;  // bench-test cap: change only when you are ready
const int  STEP_US  = 10;    // max change per 20 ms: smooth ramp, no sudden jumps

Servo esc;
int outUs = MIN_US;

void setup() {
  Serial.begin(115200);
  esc.setPeriodHertz(50);
  esc.attach(ESC_PIN, MIN_US, MAX_US);
  esc.writeMicroseconds(MIN_US);           // minimum throttle from the very start

  Serial.println(F("Turn the pot fully DOWN, then connect the LiPo to the ESC."));
  while (analogRead(POT_PIN) > 80) {        // refuse to start with the knob up
    delay(100);
  }
  Serial.println(F("Pot at zero. Waiting 5 s for the ESC to arm..."));
  delay(5000);
  Serial.println(F("Armed. Turn the pot slowly."));
}

void loop() {
  int target = map(analogRead(POT_PIN), 0, 4095, MIN_US, LIMIT_US);
  if (target < MIN_US + 20) target = MIN_US;          // small dead zone = clean stop

  if (target > outUs)      outUs = min(outUs + STEP_US, target);  // ramp up gently
  else if (target < outUs) outUs = target;                        // stop at once

  esc.writeMicroseconds(outUs);

  static unsigned long lastPrint = 0;
  if (millis() - lastPrint > 250) {
    lastPrint = millis();
    Serial.print(F("Pulse: "));
    Serial.print(outUs);
    Serial.print(F(" us  Throttle: "));
    Serial.print((outUs - MIN_US) / 10);
    Serial.println(F(" %"));
  }
  delay(20);
}

How the code works

  • Minimum first. esc.writeMicroseconds(1000) runs before anything else, so the ESC sees minimum throttle the moment the LiPo is connected and arms instead of entering calibration.
  • Knob must be at zero. The while loop refuses to continue until the potentiometer is turned fully down. A knob left halfway can't start the motor by surprise.
  • Ramp up, stop at once. The output rises by at most 10 µs every 20 ms (0 to 50 % takes about a second) but drops to minimum instantly when you turn the knob down.
  • LIMIT_US = 1500 caps the bench test at half throttle. Raise it towards 2000 only when the motor is mounted properly and you need full power.
  • Dead zone. Readings within 20 µs of minimum become exactly 1000 µs, so the motor stops cleanly instead of twitching.
  • setPeriodHertz(50) tells ESP32Servo to produce the standard 50 Hz frame. The ADC reads 0–4095 on the ESP32, hence the different map() range.

What you should see

With the LiPo unplugged, open the Serial Monitor (115200 baud), turn the knob fully down, then connect the LiPo:

Output
Turn the pot fully DOWN, then connect the LiPo to the ESC.
Pot at zero. Waiting 5 s for the ESC to arm...
Armed. Turn the pot slowly.
Pulse: 1000 us  Throttle: 0 %
Pulse: 1180 us  Throttle: 18 %
Pulse: 1340 us  Throttle: 34 %
Pulse: 1000 us  Throttle: 0 %

Level up: a throttle slider on your phone

Replace the knob with a web page. The ESP32 joins your Wi-Fi and serves a slider; the page sends the throttle every 300 ms, and the slider snaps back to zero when you let go. If the ESP32 hears nothing for 1 second (phone locked, Wi-Fi dropped, tab closed), it cuts to minimum. That failsafe matters more than the slider.

Put your Wi-Fi name and password in the sketch, upload, and open the address it prints in the Serial Monitor on your phone:

sketch.ino
// BLDC motor + 30A ESC + ESP32: throttle slider in your phone's browser,
// with a failsafe that stops the motor if the phone goes quiet.
// PROPELLER OFF. ESC signal -> GPIO18, ESC signal ground -> GND, ESC red BEC wire NOT connected.
#include <WiFi.h>
#include <WebServer.h>
#include <ESP32Servo.h>

const char* WIFI_SSID = "YourWiFi";
const char* WIFI_PASS = "YourPassword";

const int ESC_PIN  = 18;
const int MIN_US   = 1000;
const int LIMIT_US = 1500;          // bench-test cap
const unsigned long FAILSAFE_MS = 1000;

Servo esc;
WebServer server(80);
int targetUs = MIN_US, outUs = MIN_US;
unsigned long lastCommand = 0;

const char PAGE[] PROGMEM = R"html(
<!doctype html><meta name=viewport content="width=device-width,initial-scale=1">
<h2>ESC throttle</h2><p>Propeller off. Release = stop.</p>
<input id=t type=range min=0 max=100 value=0 style="width:90%">
<p id=v>0 %</p>
<script>
const t=document.getElementById('t'),v=document.getElementById('v');
function send(){fetch('/set?p='+t.value);v.textContent=t.value+' %';}
t.oninput=send; setInterval(send,300);               // keep-alive for the failsafe
['mouseup','touchend'].forEach(e=>t.addEventListener(e,()=>{t.value=0;send();}));
</script>)html";

void setup() {
  Serial.begin(115200);
  esc.setPeriodHertz(50);
  esc.attach(ESC_PIN, MIN_US, 2000);
  esc.writeMicroseconds(MIN_US);                 // minimum before anything else

  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) delay(250);
  Serial.print("Open http://");
  Serial.println(WiFi.localIP());

  server.on("/", [] { server.send_P(200, "text/html", PAGE); });
  server.on("/set", [] {
      int p = constrain(server.arg("p").toInt(), 0, 100);
      targetUs = map(p, 0, 100, MIN_US, LIMIT_US);
      lastCommand = millis();
      server.send(200, "text/plain", "ok");
  });
  server.begin();
}

void loop() {
  server.handleClient();
  if (millis() - lastCommand > FAILSAFE_MS) targetUs = MIN_US;   // phone gone: stop

  static unsigned long lastStep = 0;
  if (millis() - lastStep >= 20) {
    lastStep = millis();
    if (targetUs > outUs) outUs = min(outUs + 10, targetUs);     // gentle ramp up
    else outUs = targetUs;                                        // instant stop
    esc.writeMicroseconds(outUs);
  }
}

Warning

Software is not an emergency stop. Keep the LiPo connector within reach and unplug it if anything goes wrong. The failsafe covers a lost connection, not a crashed sketch or a wiring fault.

Troubleshooting

Common problems and fixes

  • ESC keeps beeping, never arms

    Likely cause
    Signal not at minimum, or no common ground
    Fix
    Make sure the ESC ground goes to ESP32 GND; the sketch sends 1000 µs before the LiPo goes in
  • Sketch stuck at 'Turn the pot fully DOWN'

    Likely cause
    Knob not at zero, or pot wired backwards
    Fix
    Turn it the other way, or swap the pot's outer wires
  • Motor reaches full speed at a quarter of the knob

    Likely cause
    ESC not calibrated
    Fix
    Run the calibration sketch
  • Motor only twitches

    Likely cause
    Loose bullet connector or throttle too low
    Fix
    Push the bullets home; turn the knob a little further
  • Spins the wrong way

    Likely cause
    Phase order
    Fix
    Unplug the LiPo, swap any two motor wires
  • ESP32 resets when the motor starts

    Likely cause
    BEC red wire connected while on USB
    Fix
    Disconnect and tape the thin red wire
  • Web page loads but motor stops after a second

    Likely cause
    Failsafe: commands not arriving
    Fix
    Keep the page open and the phone awake; stay close to the router

Frequently asked questions

Why not use analogWrite()? It makes a high-frequency PWM with a duty cycle, not the 50 Hz, 1000–2000 µs pulse the ESC expects. Use the ESP32Servo library.

Can I power the ESP32 from the ESC's BEC instead of USB? Yes: connect the thin red wire to the ESP32 board's 5V (VIN) pin, not 3V3, and remove USB. Never both at once.

How do I control more than one ESC? Attach another Servo object to another pin. Each ESC needs its own signal wire; the grounds all join.

Can I use a different signal pin? Yes, any output-capable GPIO works. Avoid input-only pins 34–39 and the boot-strapping pins 0, 2, 12 and 15.

What to build next

  • Thrust stand: mount the motor on an HX711 load cell and measure grams of thrust against throttle.
  • Battery monitor: read the LiPo voltage through a divider and stop the motor below 3.5 V per cell.
  • Two-motor drive: a second ESC on another pin for a hovercraft or boat.
  • Pin reference: the ESP32 pinout guide lists the safe output pins.

Keep learning

Related guides & projects