Info page · no simulation · Arduino and electronics
BLDC Motor with an ESC and Arduino
How a brushless motor and its speed controller (ESC) work, and how an Arduino sets the throttle with a servo-style signal.
This topic cannot be run safely or meaningfully in the simulator, so this page explains it with diagrams, calculations and sample code instead. Everything here is original.
What you will learn
- How an ESC makes a rotating field from DC
- Why the ESC needs an arming signal
- How to set the throttle with writeMicroseconds
In short
A brushless motor has three coils and magnets on the rotor. The ESC switches the battery current through the coils in order so that a magnetic field rotates and pulls the rotor round. The Arduino does not drive the motor. It sends the ESC a pulse every 20 ms. A 1000 microsecond pulse means stop and a 2000 microsecond pulse means full throttle.
Try this next
- Add a button for a soft start.
- Read the motor speed with an IR sensor and a slotted disc.
- Make a throttle that never jumps more than 5 percent per step.
Safety: take the propeller off for every test. A small BLDC motor and a LiPo battery can hurt fingers badly and the LiPo can catch fire. Fit a fuse, never short the battery, charge it in a fireproof bag and never leave it unattended.
How it works
Inside the ESC a small processor switches six MOSFETs. It reads the voltage on the unused coil (back-EMF) to know where the rotor is. Without a rotor sensor it needs the motor to turn a little to start, which is why you hear a short start-up buzz.
Arming and throttle
- When the ESC gets power it expects 1000 us for about 2 seconds. It then beeps and is armed.
- If the first signal is above the minimum, the ESC refuses to start (safety).
- 1000 us to about 1100 us is stop, then the speed rises up to 2000 us.
- To reverse the direction swap any two of the three motor wires.
#include <Servo.h>
Servo esc;
const int ESC_PIN = 9;
const int POT = A0;
void setup() {
esc.attach(ESC_PIN, 1000, 2000);
esc.writeMicroseconds(1000); // minimum: arming signal
delay(3000); // wait for the ESC beeps
while (analogRead(POT) > 50) { } // do not start until the knob is at zero
}
void loop() {
int us = map(analogRead(POT), 0, 1023, 1000, 2000);
esc.writeMicroseconds(us);
}Parts list
| Part | What to look for |
|---|---|
| Brushless motor (outrunner, for example 1000 kV) | Check the maximum current and voltage |
| ESC (for example 30 A) with BEC | Current rating about 1.5 x motor maximum |
| LiPo battery 3S, with connector | Use a LiPo bag and a fuse |
| Servo cable / jumper wires | ESC signal to the pin, ESC black wire to Arduino GND |
| 10 k potentiometer | For the throttle |
| Strong clamp or test stand | Fix the motor before power on |
Do and do not
- Do join the ESC signal ground to the Arduino ground.
- Do power the Arduino from USB. The ESC BEC only needs its red wire left unconnected when the Arduino has its own power.
- Do keep the motor wires short and twisted.
- Do not use a 2S battery on an ESC that needs 3S or more.
- Do not connect or disconnect the battery with the throttle up.
- Do not test with the propeller fitted.