Summary
This is a tutorial of how to control an electronic speed control (ESC)and brushless motor using an Arduino.
Description
This tutorial is about controlling a brushless motor, the type commonly used in RC hobbies, and controlling the motor using an Arduino. The goal is to use the Arduino Servo library, give an input from 0 to 180, and see the motor move based on our input.
Before we begin
Hooking up the Arduino to an RC hobby ESC is always the same. The difference is that you will need to know how to arm your ESC. This means you'll need to look for the manual that tells you how to arm your ESC.
When reading your ESC manual, you'll most likely notice that the literature/manual was written for people who have other RC equipment. My manuals have always talked about the need to adjust the throttle in order to trigger an event like arming or programming modes. We will be substituting the throttle with the input we give the Arduino.
Safety (always)
"You'll shoot your eye out" - A Christmas Story
Experimenting with the combined equipment of an Arduino, ESC, motor, and computer can cause harm to you or your equipment under certain situations. Here's some items to consider for some of the components involved.
Motor
Make sure there is nothing attached to your motor (i.e. no props). Don't test with props attached. I jumped out of my chair, swearing, the first time the motor ran because I didn't expect it to work. In custom trial and error, you never know what's going to happen.
Secure the motor to something while experimenting. You don't want the motor jumping around when it unexpectedly comes to life. If you need an ideal example, please how Ray29erau has his motor secured in his youtube video.
Protect Your USB ports
While an Arduino may be relatively cheap, let me save you a USB port. No matter what you are thinking of doing, don't connect the positive line of your ESC to your Arduino pin labeled 5v. If you connect your battery to the ESC, connect your Arduino to your computer by USB, and connect the gnd, signal, AND 5V into the Arduino..... you will probably damage (lose, fry, kill, etc) whatever USB port your Arduino is plugged into on your computer. There's a good possibility you could lose the Arduino board too. For a full explaination, please see "10 ways to Destroy an Arduino".... more specifically it's "Method #5".
Battery
General battery safety is recommended. I'm using a lithium polymer (LiPo) battery. If you want to know more on LiPo's, check out this page. If you have a question or doubt about something you are doing with a LiPo battery, find someone who knows about the safe handling/charging of battery/LiPo's and ask. For example, I bought mine from an awesome local hobby shop. If I had questions about what I bought and the answers weren't included with the manual or couldn't be found online then I would ask the people that sold the gear to me.
D.) Other
This is the other category. This is all meant to be fun. When experimenting, there may be times you feel uncomfortable or unsafe about doing something in a project. At times like these, find a person, forum, or group (Arduino forums linked) to ask and make your situation safe at all times.
Steps
Control the ESC/Motor using an Arduino
- Connect the ESC to motor.
- Connect the ESC to Arduino - pay attention or you will kill a USB port/Arduino (Protect Your USB Ports).
- Connect the Arduino to you computer.
- Upload your sketch to the Arduino.
- Use the Serial Monitor to arm the ESC
- Done!!! Do other stuff....
Begin
1. Connect the ESC to motor.
Simply enough, connect the ESC to the motor (Figure 1.1). Notice that my yellow wire is in the middle. Both the black and the red wires are on the outside. If your ESC doesn't have colored wires (as seen on another ESC Figure 1.2), don't worry. Getting the outside wires mixed up would only make the motor spin in the wrong direction. There would be no harm in getting the outside wires wrong. If you find your motor is spinning really fast when you think it should be stopped... you only need to reverse the polarity between the ESC and motor.
Figure 1.1 - Motor connected to ESC |
Figure 1.2 - Two ESC's next to each other |
2. Connect the ESC to Arduino.
Connect the Arduino's pin labeled "GND" to the ESC (Figure 2.1). For this project, I am using pin 9 for the signal, yours may be different. Connect the Arduino's pin labeled "9" to the ESC's white signal line (Figure 2.2). That's it for step two.
As discussed in above in the safety section under "Protect Your USB Ports", DO NOT connect the Arduino pin labeled 5V to the ESC. (Figure 2.3)
Figure 2.1 - Arduino GND to ESC |
Figure 2.2 - Arduino pin #9 to ESC |
Figure 2.3 - DONT DO THIS
Figure 2.3 - DONT DO THIS |
3. Connect the Arduino to your computer.
Connect the Arduino to your computer (Figure 3.1). It's super-easy.
Figure 3.1 |
4. Upload your sketch the Arduino.
Open up your Arduino IDE. Click here to open up the reference page (it has the Arduino sketch). Copy the sketch on the reference page and paste it into your own sketch. Upload the sketch to your Arduino (Ctrl + U).
5. Use the Serial Monitor to arm the ESC.
In the Arduino IDE, select "Tools" then select "Serial Monitor". At this point, plug your battery into the ESC. Your ESC will probably be different that mine. This is where it's all about trial and error now.
Your ESC will be different but mine always gives a series of beeps. According to the manual, the series of beeps tells me that the the ESC is on. At this point, the manual (mine is found here) says the following:
"The H . K i n g ESC will not arm unless youGreat. I have no idea what this correlates to in the values from 0 to 180. That's okay. I did my trial and errors by typing numbers between 0 and 180 into the Arduino IDE Serial Monitor. I tried the lows (0, 5, 10, 15, 20), the middle (90), and the high (170, 175, 180). What I found was that sending "10" will arm the ESC and it will start spinning when I enter (send) "55" or higher from the Serial Monitor (Figure 5.1). Figure 5.1 shows what happens when I type "10" and then "55" into the Serial Monitor.
move your throttle stick to the lowest position. When
the H.King ESC receivesthe low throttle command, it
will arm and play a double tone through the motor,
indicating it is armed and now ready to run."
Be careful when doing trial and error with the motor. When figuring out the ranges, high and low could be backwards. For example, high might be "0" and low might be "180". The first time my motor spun was when I sent 180, coincidentally I also found out that this was the high end of the range.
Figure 5.1 |
If you have figured out how to make your motor spin. Congrats! It's a fun learning experience. Most likely, you are trying to get your motor spinning for some other project and this was one of the first steps. Good luck!