Introduction: ESC Programming on Arduino (Hobbyking ESC)

Picture of ESC Programming on Arduino (Hobbyking ESC)

Hello Community,

I'm going to show you, how to program and use the Hobbyking ESC. I just found a few information and tutorials, which really didn't help me very much, so i decided to program an own sketch, which is very simple to understand.

Important to know:

* ESC means Electronic Speed control
* The ESC has a 5v(not used), GND and Signal Pin like a Servo
* You control it like a Servo with  write() http://arduino.cc/de/Reference/ServoWrite
* or writeMicroseconds  http://arduino.cc/de/Reference/ServoWriteMicroseconds

In my Example i use writeMicroseconds, because it is easier to understand.
So let's go...

Step 1: Getting ESC Information

Picture of Getting ESC Information

You really should remark the Amperevalue of your ESC. This tutorial is only tested on 20 AMP ESC :
http://www.hobbyking.com/hobbyking/store/__15202__hobby_king_20a_esc_3a_ubec.html

I can't really promise, that this is working with an other ESC but i think so, because in the english manual are 20 and 30 Amp ESC's described. In the German version is a generalisation from 10 to 120 Amp, thats why I think this could work for every ESC.

Source:
German: http://tom-620.bplaced.net/rc_modelle/zubehoer/regler/hobby_king/hk_80A_regler_deutsch.pdf
English: http://www.hobbyking.com/hobbyking/store/uploads/811103388X7478X20.pdf

Step 2: Connection to Arduino

Picture of Connection to Arduino

I tried it with an arduino uno R3. I think it's also possible with an e.g. arduino Duemilanove or Mega.

First you have to connect the ESC to you lipo or NiMH. When you have done that you connect the ESC like so:

*  Black to GND
* White/Yellow to PIN 9


Because you connected the ESC to your battery, the ESC is put under voltage. Thats why it It is important, that you DON'T connect the red wire to your 5v Port, because it could destroy your computer's USB Port.

On this picture you can see the correct connection between ESC and Arduino (Mega).

Picture source: http://1.bp.blogspot.com/-eqDaRgO5FjU/T9U3avwT2-I/AAAAAAAAALE/-8pj4qD12Q0/s1600/Figure2_2_edit.jpg

Step 3: Upload Sketch

Picture of Upload Sketch

Just copy and paste this Code to your IDE:






/*
Coded by Marjan Olesch
Sketch from Insctructables.com
Open source - do what you want with this code!
*/
#include <Servo.h>


int value = 0; // set values you need to zero

Servo firstESC, secondESC; //Create as much as Servoobject you want. You can controll 2 or more Servos at the same time

void setup() {

  firstESC.attach(9);    // attached to pin 9 I just do this with 1 Servo
  Serial.begin(9600);    // start serial at 9600 baud

}

void loop() {

//First connect your ESC WITHOUT Arming. Then Open Serial and follo Instructions
 
  firstESC.writeMicroseconds(value);
 
  if(Serial.available()) 
    value = Serial.parseInt();    // Parse an Integer from Serial

}

Step 4: Understanding and Programming an ESC

Picture of Understanding and Programming an ESC

ESC are programable like IC's or even your Arduino. You just don't have a language to program,  but a menu made of sounds.

To come in this menu, which runs infinite btw you just have to do following Steps:

* Connect your ESC
* Configure the code (as much as ESC's you have and Pin-configuration)
* You should hear nothing, because the Arduino sends a zero
* Open your Serial Monitor and send '2000'. it means the highest Signal the ESC can receive
* You will hear the sounds which are described on the picture ( Source: Manual: http://www.hobbyking.com/hobbyking/store/uploads/811103388X7478X20.pdf)


The Hobbyking ESC's can receive a Signal between 700 and 2000 us(microseconds). 700 means throttle at lowest position and 2000 on the highest Position. If you want to know what exactly you du, when you pick a menu visit the manual.

Example:
- Write 2000 us
- Wait until D-D-D-D to chose lipo as batterytype
- When it apperas, write at the third 'D' 700 in your Serial ( short delay, thats why you have to send it at the third 'D')
- ESC will make a sound, and the Option is chosed.



I Hope i could help you with this tutorial.

Visit my Youtubechannel:   http://www.youtube.com/diiaf

Comments

ethanmm120 (author)2016-06-06

Found how to calibrate traxxas XL 2.5. Hope this helps:

#include <Servo.h>

#define MAX_SIGNAL 2300

#define NETRUAL 1400

#define MIN_SIGNAL 400

#define MOTOR_PIN 9

Servo motor;

void setup() { //open serial monitor

Serial.begin(9600);

Serial.println("Uno online. Software launch sucessful");

delay(100);

Serial.println("Calabration set for TRAXXAS XL 2.5. Please wait for further instruction.");

delay(100);

Serial.println("Begin calibration with ESC powered off and LiPo attached. Connect control wire and grnd to Arduino. Press any key when complete");

while (!Serial.available());

Serial.read();

motor.attach(MOTOR_PIN);

Serial.println("Output at NEUTRAL. Please press and hold ESC calibration button. Light shall flash green then red. Release the button");

delay(1000);

Serial.println("Wait for ESC to blink red once. Then press any key");

while (!Serial.available());

Serial.read();

Serial.println("Now outputting maximum output.");

motor.writeMicroseconds(MAX_SIGNAL);

delay(1000);

Serial.println("Wait for ESC to blink red twice. Then press any key");

while (!Serial.available());

Serial.read();

Serial.println("Sending minimum output");

motor.writeMicroseconds(MIN_SIGNAL);

delay(1000);

Serial.println("ESC should blink green once. If not, calbration has failed. Please atempt agian");

}

void loop() {

}

AlphonsusA (author)ethanmm1202017-07-29

I tried it on my XL5 esc but it didn't work. Could you please tell me if there are any modifications I'd have to make to the code? Thanks!

SantitheGreat (author)ethanmm1202016-10-10

Worked perfectly!

khbilen (author)2017-05-17

Here is my two cents. Should work for any ESC. You may need to play
with delay times. Choose your own speed as you wish, between HI and LO.

/*** ***/

#include <Servo.h>

Servo esc;

void setup()
{
esc.attach(9);
delay(5000);
esc.write(179); // HI
delay(5000);
esc.write(1); // LO
delay(5000);
esc.write(90); // MID
delay(10000);

esc.write(120); // SPEED

}

void loop()
{
}

chebhou (author)2015-04-15

thanks for the tutorial really helpful ;

working on ESC ( hobbywings 20A skywalker ) , you have to first calibrate the throttle range : set arduino to 1800 (the max for this esc ) you'll hear 2 beeps set the arduino to 1300 (min ) you'll hear 3 beeps and one long beep (you 're done now ) set the arduino to any value( 1300 -1800) the motor should be spinning now , next time just set it to 1300 before starting ( no need for calibration )

stevenleeyongwah (author)chebhou2017-05-17

Thank you so much. this method works for my esc. Thankssssssss. hahahha

stevenleeyongwah (author)2017-05-15

It works

. Damn it. I am damn happy.

kn04 (author)2016-12-26

Hi I've been trying to get my esc to work with a few different intro guides that i've found online, but the only thing that happens once I connect everything up with the motor and the battery as well is that it keeps beeping every couple of seconds and does not stop.

This is the hardware I'm using:

Turnigy Plush 40A ESC

Turnigy Aerodrive D3536/8 1000KV brushless outrunner motor

Zippy compact 4 cell 14.8V LiPo battery

- Sainsmart Arduino Nano (using D6 = pin 9, at least according to some google searches)

I've tried the above code, also starting with 700, 2000, and a few other numbers as well and nothing seems to work. Motor doesn't move at all, and as mentioned above just keeps beeping. Appreciate any help you might be able to provide. Thanks for your help.

joaopinela (author)kn042017-01-23

Hello,

I have the same situation... just

beep .....beep.... beep every 2 seconds.

did you find the reason?

thanks.

PeterG98 (author)2016-12-06

hello, love this tutoral, and I'm using it to power 4 esc/motors.

I've pretty much just quadrupled your send routines:

firstESC.writeMicroseconds(value);

secondESC.writeMicroseconds(value);

thirdESC.writeMicroseconds(value);

fourthESC.writeMicroseconds(value);

Running the motors without props they run fine for as long as I need, but I put some small 6" props on for testing, and after about 10 seconds at least one motor slows and stops. Eventually two go, then three.

I'm running 2300kva, I would have thought these motors could have handled it.

Is there something I'm missing?

OlivierL23 (author)PeterG982017-01-06

Did you check the max amperage your ESC can provide vs the rating for the engine? Are your engines overheating because of too much power?

PeterG98 (author)OlivierL232017-01-06

It turned out to be power supply, I was using the wrong sort. Stuck a LiPo on it and everything is good.

I forgot I posted this otherwise I would have updated it, thanks for the reply though.

vgajjar1 (author)2017-01-01

Hi,

Nice post !

can i use Arduino Nano V3 instead of UNO ?

If yes, than how to do it ?

Thanks in advance !

Regards,

Vishal

guruji1 (author)2017-01-01

Hi thanks for this info. I have esc's that don't run prop; do you think by reprogramming them can fix the problem? Thanks.

joaopinela made it! (author)2016-12-30

Hello Everyone,

I have been trying to bet my ESC running but no luck and no sound whatsoever :(

I am powering my Red Brick 60A ESC with a laptop battery (is this ok?).

Also my ESC appears to not have a BEC (no where does it say BEC). so I connected the arduino to the ESC like so:

white - pin9 arduino

red - 5V

black - GND

this is the last code I tested. Again, no sound. Very strange. I tested the voltage from the battery and from the arduino, and it is working..

Can anyone please point me in the right direction?

Thank you and have a great assemblable 2017 :P

#include <Servo.h>

int value = 0; // set values you need to zero

Servo firstESC;

const int ESC=9; //

void setup() {

firstESC.attach(9); // attached to pin 9 I just do this with 1 Servo

pinMode(ESC,OUTPUT);

Serial.begin(9600); // start serial at 9600 baud

Serial.println("starting arm....");

firstESC.writeMicroseconds(0);

delay(1000);

firstESC.writeMicroseconds(2000);

delay(1000);

firstESC.writeMicroseconds(700);

delay(1000);

Serial.println("fimarm...");

}

void loop() {

firstESC.writeMicroseconds(value);

if(Serial.available()){

value = Serial.parseInt(); // Parse an Integer from Serial

Serial.print("typed>"+value);

}

}

joaopinela (author)2016-12-30

Hello Everyone,

I have been trying everything to get my ESC to work. I have the following code..

I believe my ESC does not have BEC, it is a RedBrick 60A ESC.

I powered the ESC with a standard laptop type battery (in the picture).

I connected:

white - PIN9

red - 5V

black - GND

my ESC does not make any sounds.

Can anyone please help in finding out the problem?

Because no sound whatsoever :(

I measured the voltage and the battery powers the ESC and arduino also powers the red pin on the ESC.

This is one of the codes I tried.

#include <Servo.h>

int value = 0; // set values you need to zero

Servo firstESC;

const int ESC=9; //

void setup() {

firstESC.attach(9); // attached to pin 9 I just do this with 1 Servo

pinMode(ESC,OUTPUT);

Serial.begin(9600); // start serial at 9600 baud

Serial.println("starting arm....");

firstESC.writeMicroseconds(0);

delay(1000);

firstESC.writeMicroseconds(2000);

delay(1000);

firstESC.writeMicroseconds(700);

delay(1000);

Serial.println("fimarm...");

}

void loop() {

firstESC.writeMicroseconds(value);

if(Serial.available()){

value = Serial.parseInt(); // Parse an Integer from Serial

Serial.print("got >"+value);

}

}

nikodll (author)2016-12-25

@SaurabhK45 Try this link: https://hobbyking.com/media/file/962315753X35454X22.pdf

SaurabhK45 (author)2016-12-22

The link doesn't work. It just says error 404 when the page goes to hobbyking. Is there another link?

loptica62 (author)2016-11-28

Hi... great tutorial....!

I was just wondering, is it possible to download the english version of the instructions you posted? It seems that the link to the German version works fine but the link to the English version is broken :-( .......Thanks in advance

Source:
German: http://tom-620.bplaced.net/rc_modelle/zubehoer/re...
English: http://www.hobbyking.com/hobbyking/store/uploads/...

amiruls9 (author)2016-11-21

what if i want to use the battery to power up the arduino? is there a coding that i could use?

MasfukM (author)2016-11-15

excuse me, iam newbie. i need help how to calibrate ESC Seaking v3 120 Amp.

mmehta3 (author)2016-07-09

for me it worked, after 4 beeps type 700 then 750, 800, 900

yazinsai (author)2016-05-06

Thanks! Worked great ..

For my HobbyKing 20A ESC, I had to:

- Upload the code in Arduino
- Write 2000 in the Serial window
- Wait for 4 beeps, then write 700
- Wait for the beeps to finish, then write 750
- Now write whatever speed you like (Min = 755, Max = 2000) .. Be careful when writing 2000! It moves like a monster

CarlD6 (author)2015-10-07

I have posted the comment below in other spaces, but I feel it is most appropriate here for some of the questions I have seen. Note: us = microSeconds.

My biggest question is why use the Servo.h lib? To get a motor turning at its full speed or RPMs requires it be given the correct voltage from the ESC (a different topic and I use a benchtop PS not batteries for this) and the proper pulse rate. The ESCs or at least simonk ESCs send these pulses to the motor based on the rate of data given it and length of the pulse. The maximum length of the pulse to send for maximum spin is 2000 us. The Servo.h sends a 2000 us pulse every 20000 us, 50 Hz or 50 times a second. I found that 490 Hz sends the fastest pulse of 2000 us. If you want to look at it in duty cycle, this is a close to a 99.0% duty cycle for 490 Hz. It is only a 10% duty cycle for 50 Hz. To get your motor to spin at its fastest RPM both the 2000 us pulse plus sending it as fast as possible is needed. Obviously there is a limit and 490 Hz is the limit. Any faster and you can't send a 2000 us burst. I have never tested it, but I have always wondered, if you lower the burst length and raise the Hertz what will that do to the speed of the motor.

Here is the code I use. I also have a serial GUI sliding bar interface that sends the same serial data - 0 thru 2000 - to the Arduino so I can control speed easily. I use this only for testing my motors on a bench.

//This code is for controlling a SimonK ESC.
//Made by Carl Davis carldavis114@comcast.net

int PinToESC = 3;

// You can enter the data by hand in a terminal window or build a GUI slider to control it via a terminal connection.
int data = 700; //Usually has the motor running when started
//Connect the GND pins of the Arduino and the ESC (Black).

void setup(){
pinMode(PinToESC, OUTPUT); //connect this PWM pin with the data cable of the ESC
analogWrite(PinToESC, data);
Serial.begin(115200);
while (!Serial) {
;
}
}

void loop(){
if(Serial.available()){
data = Serial.parseInt(); // Parse an Integer from Serial
analogWrite(PinToESC, data);
}
//Serial.println(data);// Comment in if you want to see the data setting on the term window
}

DonaldN4 (author)CarlD62016-04-23

Hi! I am wondering two different things.

1. Where did you find out that the ESC's can receive a signal between 700 and 2000 us(microseconds)

2. Why do you have the data value from 700 to 2000? The arduino site for the analogWrite function(https://www.arduino.cc/en/Reference/AnalogWrite) indicates that it only takes values from 0 to 255. What would sending 700 do?

CarlD6 (author)DonaldN42016-04-24

Question 2 first. You are looking at analogWrite which is set at a specific PWM frequency - about 500 HZ. With analogWrite you use an 8 bit scale (0 - 255) as input.
The (700 - 2000) argument I was referring to in my post was talking about the Servo lib function writeMicroseconds.

It runs at about 50 Hz and takes a microsecond parameter.
Servo example
#include .
Servo ESC;
ESC.attach(Pin you are sending data thru);
ESC.writeMicroseconds(700);
ESC.writeMicroseconds(1000); //Increase speed

Servo is not usually used to run a BLDC so I see the confusion. It was a concoction I tried, using someones posting, as I was try to understand BLDC motors. In my post I was questioning why use the Servo lib, which is where the arguments of 700 to 2000 I talked about were used.

To answer question 1. that is the limitation of Servo.h lib not ESCs. Sorry if I implied that. I am working on another lib to try and find out the top and bottom end of a PWM signal to ESC and figure out what is the best frequency to use. This is taking me down the road of ESC and motor control design. I am no where near finished as I do this in spare time.

DonaldN4 (author)CarlD62016-04-24

Thanks for the help! That was very helpful!

GabrieleP10 (author)2016-04-15

If you are interested I have made this program to change and save the settings of ESC :
https://www.youtube.com/watch?v=hyIqT0kAdVo&feature=youtu.be

Wilderness-X (author)2016-04-06

Hi, just starting out with this and I would like to confirm that my motor is being under powered.... is so any ideas why...

so i have a Sunnysky x2212-13 9800ii motor and a WST blheli20A esc, the esc can handle 2-4s lipo. i am powering the esc with a power supply set to 14.8v.

so with your provided code the motor starts up correctly and runs within the mapped ranges of 0 and 179. but when the motor is running at its highest range right before the esc turns the motor off because it is out of range (***guess...) the motor is only pulling .6 amps. which falls quite short of the manufactures spec sheet of 14.9 amps @14.8v. is this normal operation or is it not reaching its full potential. i have put a prop on it and it does have some pull but i was kinda expecting more......

Thanks in advance for any help

sellithy (author)2015-11-24

I wanted to ask if an Arduino board can control ANY ESC?

nicktc10 (author)2015-07-03

Hi, I am new in this world of ESC's and I am just in the middle of doing my own electric longboard and I would like to know if an ESC is able to generate negative PWM so the motor can run in the opposite direction. I imagine this is the way to make a motor brake so it can generate negative torque and so on make me stop or even go backwards if I ever need to.

Thank you very much, any help will be really appreciated

ved.vit (author)2015-03-11

hey i have calibrated all(4) ESC ( EMAX SimonK series ESC, 20 A) through RF Avionic RCB6i (2.4Ghz 6ch transmitter with receiver) but when i pickup the throttle one motor is running slower than other. Should i have to try the above procedure??

http://abc-rc.pl/templates/images/files/995/141451...

plz reply ASAP

JessV1 (author)ved.vit2015-06-08

ESC's normally receive a continuous signal, they are running a different rates because each motor is slightly different, each resistance slightly different, and these small differences add up to a speed difference. If it's an input problem, make sure the ranges of input are all the same IE 700-2000, 1200-1800, etc.

canterslayer (author)2015-03-29

I have a issue

I calibrate my ESC's (4) but two of them have begin to work with the value 1200 to 2000 and the others with value between 700-2000

Why does not work with the same value when i calibrate the minimu 700 and the maximun 2000

carlos.alcazar.7921 (author)2015-02-06

Anybody know what the Signal is for the 120A version? (HK-1-8-120A). I've played around with this and can verify that it is accepting values well over 2k

I´ve tried every option available here, in other sources and my own combinations, and I´m still unable to make it fly. With degrees or microseconds, defining ratings from 40 to 150 or 700 to 2000. The motors start, accelerate with a variable in a ++ loop and suddenly always stop. Any advice?

AbdulR10 (author)2015-01-03

if anyone knows how to start esc of 18A for brushless dc motor without using header file "Servo.h". Then please help me??

amit.0991 (author)2014-11-27

I tried your code and ESC gave the calibration confirmation but motor didn't run.

My procedure is-

1- First send the maximum signal to arduino.

2- turn on the ESC

3- after right beep i sent the minimum signal to ESC and ESC made some beeps and gave a calibration confirmation tone. but now i am giving the singal between maximum and minimum, motors are not rotating.

alexander.mogren.7 (author)2014-10-07

Hey All. I run this Code:

#include <Servo.h>

#define MAX_SIGNAL 2000
#define MIN_SIGNAL 700
#define MOTOR_PIN 9

Servo motor;

void setup() {
Serial.begin(9600);
Serial.println("Program begin...");
Serial.println("This program will calibrate the ESC.");

motor.attach(MOTOR_PIN);

Serial.println("Now writing maximum output.");
Serial.println("Turn on power source, then wait 2 seconds and press any key.");
motor.writeMicroseconds(MAX_SIGNAL);

// Wait for input
while (!Serial.available());
Serial.read();

// Send min output
Serial.println("Sending minimum output");
motor.writeMicroseconds(MIN_SIGNAL);
Serial.println("Done");
}

void loop() {

}

andy.slock.31 (author)2014-09-30

Thank you for this example. I just cant find one thing, quote: "

The Hobbyking ESC's can receive a Signal between 700 and 2000 us(microseconds)."

I'm looking in the manual. But I can't find it. Can you help me? Thank you very much.

alexander.mogren.7 (author)2014-09-27

I have tested this with a Arduino Nano MCU and a Turnigy ESC and it works like a dream.

dbierdeman (author)2014-02-17

Could you please share the arming sequence for the Hobbyking ESC? Thanks!

maole_95 (author)dbierdeman2014-02-21

The Arming Sequence seems to be
individual, because you can make different settings on the ESC. My
arming sequence on standard settings is:

void setup()
{
Serial.begin(9600);
myservo.attach(10);
delay(1);
myservo2.attach(11);
delay(1);
myservo3.attach(12);

myservo.write(40);
myservo2.write(40);
myservo3.write(40);
delay(1000);
myservo.write(60);
myservo2.write(60);
myservo3.write(60);
delay(1000);
myservo.write(40);
myservo2.write(40);
myservo3.write(40);
delay(1000);
}

About This Instructable

321,056views

149favorites

License:

Add instructable to: