Driving brushless DC motors with Arduino on the cheap using ESCs for RC vehicles.


Brushless DC (BLDC) motors really are at least one step above the conventional brushed ones: they offer higher torque and RPM then the same-sized brushed motors. However, they require more complex control circuitry and the chances are that you rarely hear about them being used anywhere except RC vehicles like copters.

How to bring the BLDC motors into the ordinary hobbyist's parts menu? The answer to this question lies exactly where I mentioned above: hobby RC industry. Due to high popularity of BLDC motors in RC copters and hovercraft making, there are really cheap BLDC drivers, or electronic speed controllers (ESC) as they are more commonly named.

The catch is, they are made to be compatible with RC controllers with loads of safety features built in, so don't expect to just connect the ESC to your favorite dev. board and have a straightforward analogWrite() controlling the motor.

I'll show you 2 ways of controlling the inexpensive ESC with Arduino, describing the pitfalls and attaching some useful documents, essentially sharing my experience of driving those beasts.

Setup

To drive BLDC motors with Arduino, you'll need:

1) Evidently, at least one BLDC motor. The one I'll be using has a 3D printed propeller and a tube, but that's irrelevant to our task.


 You can get yourself an ordinary barebones BLDC motor (here's mine).


 2) ESC -  the cheapest one I found was marked Hoenvesta 30A, rated for 30A as you can see from the name, and is meant to be used for "450 class Helicopter" - whatever that means. At the time of writing this post this piece of hardware retails for as low as 3.5USD (link). Never heard of this brand, but it works and that's all I need from it.


3) One potentiometer of any value to control speed.

4) Arduino - any will do. (By the way, did you know that you can buy a genuine Arduino from China? Looks like these guys are either just reselling Arduino after buying from Italy in bulk, or getting better at making clones 😀)


5) Something to connect BLDC motor to the driver. De-facto standard for this kind of connection is 2mm banana (or bullet, whatever you like) connectors like these.

Why make this connection impermanent, you ask? Of course you can solder the wires and forget about it. But swapping any 2 wires will result in reversing the direction of rotation, so connectors instead of soldering will result in added flexibility.

The funny thing is, I had only female connectors at the time I was experimenting with brushless motors, so I had to improvise:
I had a whole bag of those 3.5mm audio receptables, and it turns out the hole is exactly 2mm.!
Insulation is essential - you don't want to SC this big boy.

Let's do something already!


Connect your peripherals just as shown on the schematic above.
Things to keep in mind:
  • Red wire on 3-pin connector of ESC is the output of an on-board voltage regulator - DO NOT connect Arduino's 5v pin to it!
  • If your motor doesn't spin in the direction you intended, try switching any 2 of the three motor's wires. That's it! If you want programmable direction reversal, you'll have to roll your own ESC...
After the circuit is ready, it's time for quick theory and coding. To learn how RC ESCs work, you can read this PDF document. In short, there's an elaborate calibration procedure to get your motor spinning, and after that there's still some safety routines in play (e.g. stopping PWM signal will switch off the motor).


Now, to conform to these calibration procedures you can:

1) Write your own code
Back in the day when this was novel I used to write my code with analogWrite() and delay(), something like this always worked:



The value for delays and analogWrites will have to be determined by trial and error. With new ESCs I usually tried to increase the value of last analogWrite call - surprisingly, some controllers can push past the max. limit!

Recently, I've found a more convenient and transparent way to control a BLDC, described below:

2) Use this library - my preferred approach.

Just download the library and use the modified ESC_Knob example code:



Here's the video of me trying out the library with this code, complete with a little accident:


No propellers were harmed during the filming of this video:


Some thoughts after this little test:
  • Where does the sound come from? That's right, the motor's windings are being used as speakers. That's one clever trick from ESC firmware developers.
  • You don't have to power up BLDC then reset Arduino all the time, it's totally fine if you just power them up simultaneously.
  • ESC can be recovered from error in most situations, but sometimes you'll have to disconnect the power from ESC and connect it back again. Maybe use a relay?
  • Only swapping motor's terminals will reverse motor's direction when using RC ESCs. As a dirty hack, why not add a DPDT relay for that?

One of the ways to making this ESC more usable.

Comments