Built-in project · Arduino Uno R3

Brushless motor on an ESC, on an Arduino Uno

An A2212 1000KV on a 30 A ESC from pin 9: setup() arms it at 1000 us, then a thumb stick on A0 opens the throttle up to 11,100 rpm on 3S. The whole build, an Arduino Uno and 3 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate Runs in your browser. Free, and no account needed.

The parts retail for about $49. On Mokxi they're free.

Brushless motor on an ESC · Arduino Uno R3live0.000 s 0.00x
Hold the button
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// A brushless motor on a 30 A ESC, its throttle on a thumb stick.
//
//   ESC SIG -> pin 9    ESC GND -> GND    (leave the ESC's red 5V wire off:
//                                          the Uno has its own supply)
//   ESC BAT+ / BAT- -> a 3S LiPo, 11.1 V
//   joystick VRY -> A0, VCC -> 5V, GND -> GND
//
// An ESC is driven like a servo: 1000 us is stopped and 2000 us is full. It
// will not spin until it has armed, and it arms only on low throttle after its
// start-up tones, so setup() holds 1000 us for three seconds. The stick at
// rest is low throttle; push it either way from the middle to open it up, as
// an RC transmitter's throttle stick does from the bottom.

#include <Servo.h>

Servo esc;
const int ESC_PIN = 9;

void setup() {
  Serial.begin(9600);
  esc.attach(ESC_PIN, 1000, 2000);
  esc.writeMicroseconds(1000);
  Serial.println("Mokxi Uno: arming the ESC at 1000 us");
  delay(3000);
  Serial.println("armed: push the stick");
}

void loop() {
  // How far the stick is from the middle, past a small dead band.
  int off = abs(analogRead(A0) - 512) - 20;
  int us = 1000 + (long)constrain(off, 0, 491) * 1000 / 491;
  esc.writeMicroseconds(us);
  static unsigned long last = 0;
  if (millis() - last > 500) {
    last = millis();
    Serial.print("throttle ");
    Serial.print(us);
    Serial.println(" us");
  }
  delay(20);
}

Parts list

4 parts, plus the jumper wires. They retail for about $49; on Mokxi they're free.

How it is wired

7 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Ground: Arduino Uno R3 pin GND; Brushless motor and 30 A ESC pin GND
  • Arduino Uno R3 pin 9; Brushless motor and 30 A ESC pin SIG
  • Arduino Uno R3 pin 5V; Thumb stick pin VCC
  • Ground: Arduino Uno R3 pin GND; Thumb stick pin GND
  • Arduino Uno R3 pin A0; Thumb stick pin VRY
  • Brushless motor and 30 A ESC pin BAT+; Battery: AA, coin cell, LiPo pin V+
  • Brushless motor and 30 A ESC pin BAT-; Battery: AA, coin cell, LiPo pin V-

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.