ESC Programming on Arduino (Hobbyking ESC)

420,274

160

55

Introduction: ESC Programming on Arduino (Hobbyking ESC)

Hey there,


I'm going to show you how to program and use a 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 easy to understand.


Good to know:

* ESC stands for Electronic Speed control

* The ESC has a 5 V (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

Step 1: Receiving ESC Information

You should pay attention to the ampere value of your ESC. In this tutorial a 20 A ESC is used:

http://www.hobbyking.com/hobbyking/store/__15202__hobby_king_20a_esc_3a_ubec.html


I can't really promise that this is working with any other ESC but i think so, because in the english manual 20 and 30 A ESC's are described. In the German version you find a generalization from 10 to 120 A, that's why I think this could work for every other 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: Arduino Connection

I tried it with an arduino uno R3. I guess it should also be possible with other arduino models like Duemilanove or Mega.


First you have to connect the ESC to your battery. Next, connect the ESC like so:


* Black to GND

* White/Yellow to PIN 9



The ESC is now on, which is why 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: The Sketch

Just copy and paste this Code to your IDE:







/*

Coded by Marjan Olesch

Sketch from Insctructables.com

*/

#include <Servo.h>



int value = 0; // initialize the variables you need


Servo firstESC, secondESC; // you can control 2 or more servos simultaneously


void setup() {


 firstESC.attach(9);   // attached to pin 9

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


}


void loop() {


//First connect your ESC WITHOUT arming. Then open the serial and follow the instructions.


 firstESC.writeMicroseconds(value);


 if(Serial.available()) 

   value = Serial.parseInt();   // parse an integer from serial


}

Step 4: Understanding and Programming an ESC

ESCs are programmable. You just don't need a language to program them, but simple interactions via the serial. The ESC communicates with sound codes.


To open the menu (which runs infinitely) you just have to do following Steps:


* Connect your ESC

* Adapt the code for all ESCs you need to configure

* You should hear nothing at the beginning, because the Arduino sends a zero

* Open your serial monitor and send '2000'. it's the highest Signal the ESC can receive

* You will hear the sounds described on the picture ( Source: Manual: http://www.hobbyking.com/hobbyking/store/uploads/811103388X7478X20.pdf)



The Hobbyking ESCs can receive a signal between 700 and 2000 us. 700 means 'throttle at lowest position' and 2000 'throttle on the highest position'.


Example:

- Write 2000 us

- Wait for 'D-D-D-D' to chose lipo as battery type

- As soon as the third 'D' appears write a 700 in your serial (delay compensation)

- The ESC will make a sound to confirm that the option is picked




I hope i could help you with this tutorial.

1 Person Made This Project!

Recommendations

  • Fandom Contest

    Fandom Contest
  • Microcontroller Contest

    Microcontroller Contest
  • Halloween Contest

    Halloween Contest

55 Comments

0
AaronY
AaronY

Question 3 years ago

Thanks for the great page! Do you know if this works with TURNIGY MULTISTAR 40A BLHELI-S REV 16 ESC 2~4S V3 (OPTO)?

0
Papasot
Papasot

Question 3 years ago on Step 4

Hello,

Thank you for this tutorial, it is extremely helpful!

I was trying to create a similar circuit myself whereby I attach a 40A ESC UBEC 4A, to a 300W brushless motor, being powered by a 6s Lipo battery, controller by my Arduino Mega.

I cannot seem to find the specifications defining the signal range for my esc. When I try callibrating it with a throttle I am able to go through the initialization of sequential beeps (AAAA BBBB etc), however when I try it through sending values via the serial monitor, I only get one or two beeps for each value I send, and it does not seem to initialize. Any ideas how I can fix this issue?

0
khbilen
khbilen

5 years ago

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()
{
}

0
ChrisD513
ChrisD513

Reply 3 years ago

I am very interested in running 1 motor through an ESC via an Arduino Uno. And I just need to run it through the usb port. I don't know what to do about the code though. Even if I write it out in the editor, what should I expect -how do I just turn it on/off

fullsizeoutput_7ef.jpegfullsizeoutput_7f2.jpegfullsizeoutput_7f5.jpegfullsizeoutput_7f8.jpegfullsizeoutput_7fb.jpeg
0
ChrisD513
ChrisD513

Question 3 years ago on Step 2

I'm hoping I can get this answer as simple as possible - I'm sure what Im asking has been done a million times over so I'd just love to be able to copy and paste the code - HOWEVER I really don't know what to do next anyways.
Attached images; The set up as a whole:
  • 6s LiPo battery - 6,000mAh
  • 80A ESC - "Mystery" brand
  • Drone motor - U7 T-Motor brand, 420KV, 3-8s LiPo battery
FIRST: I have it set up in 'a' way that will allow this to function/interact correctly. I do not need an accelerometer and I am wanting to turn it on/off-start/stop and adjust speeds (for all intense and purposes) through my desktop via the USB port. So I want to be able to do all of this through the Arduino create agent editor thing on my desktop.

NEXT: So even if/when someone is so nice enough to show me the code in such a way I can just copy and paste into the editor - I really don't know what to do next. How do I get it to go? I'll have to adjust numbers in certain sections of the code in editor. I'll need some help with this, e.g. this number means this - that means that and adjusts the speed accordingly, etc.

But basically; How do I turn this set up on and off in the editor controlled from my desktop.
Thanks AND please let me know what I can clarify
IMG_3898.jpegIMG_3899.jpegIMG_3900.jpegIMG_3901.jpegIMG_3902.jpeg
0
Calond
Calond

Reply 4 years ago

I was using the github code and it was working fine, but only for pin 9 and 10 on the arduino NANO the other pins that do have pwm do not work. Someone said it might be that pin 9 and 10 run on 980 hertz and the other pins only at 490 hertz. Is that the case and is it fixable?

1
FarhanT1
FarhanT1

Question 4 years ago

Oh thanks for explained.

In my case, my pwm output from pid calculation is responsive but when it write to esc ,the bldc response is slow(its like have some delay on it) so my quad can't stable in any pid constants that i tune..

Please help how to make my esc reponse fast according to yaw and pitch angle with no delay ?( thanks.

0
PeterG98
PeterG98

5 years ago

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?

0
OlivierL23
OlivierL23

Reply 5 years ago

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?

0
PeterG98
PeterG98

Reply 4 years ago

Sorry I honestly didnt see this reply.

It was just the power supplies I was using couldnt give amps fast enough. I eventually just bought a large capacity lipo and charger off ebay.

Thanks for the reply.

0
OlivierL23
OlivierL23

Reply 4 years ago

No worries, thanks for getting back to me :-)
LiPo will also be the long term solution, but for now, using a power supply for the algorythm tests with my students..
Thanks again for the the ESC instructions, they were very useful!

0
PeterG98
PeterG98

Reply 5 years ago

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.

0
TanmayB11
TanmayB11

Reply 4 years ago

Hey! What sort of Power Supply?

0
PeterG98
PeterG98

Reply 4 years ago

hmm this was a while ago now.

I was using a pc power supply, but I couldnt get the motors to run at full speed for long before they eventually cause the power supply to fail.

I eventually just bought a proper lipo and charger off ebay, I think I got change out of $50 for both. I havent done much on this for a year or so because I've moved and no longer have the space, but I need to get bigger motors. The ones I have ALMOST lift it off the ground but the airframe is just under 1.4kg. I am also trying to lighten the load.

0
CheL7
CheL7

Question 4 years ago

Hello, is that all kind of ESC have the same signal value between 700 and 2000?

0
SaurabhK45
SaurabhK45

5 years ago

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

0
Dave Mc
Dave Mc

Reply 4 years ago

I know this is very late but for any new people coming here, I found the link here

https://hobbyking.com/media/file/712477887X38755X54.pdf

0
ethanmm120
ethanmm120

6 years ago

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() {

}

0
AlphonsusA
AlphonsusA

Reply 5 years ago

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!