• Brandon

Controlling a Brushless Motor with Arduino


In this post, I'm going to demonstrate how to control a brushless motor with a potentiometer and an Arduino.

Parts Needed:

For this example you'll need:

  • an Arduino Uno and breadboard,

  • potentiometer,

  • jumper wires,

  • brushless motor,

  • electronic speed controller,

  • and battery.

What is a Brushless Motor?

Without going too deep into an explanation about electromagnetism, a brushless motor is a type of actuator that creates rotary motion by manipulating the timing of current that goes into each of its three leads. Unlike a brushed motor, you can't simply apply a voltage to the leads and expect the motor to move the way you want it to. There are two types of brushless motors, the in-runner, or the out-runner. The in-runner is completely enclosed, and only the shaft rotates. The out-runner has a shaft that is rigidly attached to the outer enclosure of the motor, and the entire enclosure of the motor rotates.

In general, the brushless motor requires something called an electronic speed controller, or ESC, to control the output of the motor. ESC's operate off of the same PWM (pulse width modulation) signal that a servo does. I explain how this works in a previous post. Out-runners usually are used with ESC's that only go in one direction, and in-runners are usually used with ESC's that can enable movement in both directions.

The difference is that, instead of the PWM signal being related to an output angle, it is directly related to the output speed. In addition, when selecting and ESC, it's important to make sure that it is rated to handle the amount of current that the motor is capable of drawing.

Building the Circuit

The circuit in this example will read analog values from a potentiometer and then manipulate those values to directly control the speed of the brushless motor. It is essentially the same circuit from my previous post on how to use a servo.

  • Connect a potentiometer to 5V and ground.

  • Wire the output of the potentiometer to A0.

  • Connect the signal wire of the ESC to pin 3.

  • Ground black wire of the ESC to ground. (The red wire could be used as a 5V output in most ESC's used for RC hobby applications).

  • Connect the battery after you have completed and uploaded your Arduino sketch.

Arduino Code

The goal of my Arduino sketch is to simply use the potentiometer to control the speed of the brushless motor. The sketch for this example can be found here.

  • First, include the servo library, and create a variable for the potentiometer pin and the pin that will send a PWM signal to the ESC.

#include <Servo.h>
#define SensorPin A0
#define MotorPin 3
  • Create a servo object for the motor and create variables for the speed of the motor and the value from the potentiometer.

Servo Motor1;
int Speed = 0;
int SensorVal = 0;
  • In the setup, attach the servo object to the PWM output pin, and set the baud rate.

void setup() {
  Motor1.attach(MotorPin); 
  Serial.begin(9600);
}
  • In the loop, read the analog values from the potentiometer and map these values to be between 0 and 180.

  • Then write the mapped values to the servo object.

  • Print the mapped variables.

void loop() {
  SensorVal = analogRead(SensorPin);
  Speed = map(SensorVal, 0, 1023, 0, 180);
  Motor1.write(Speed);

  Serial.println(Speed);
}

After you upload the code and plug in the battery, you may notice, that the motor is stationary and does not respond to moving the potentiometer. In most ESC's there is a safety feature that requires it to first receive a PWM signal that indicates a speed of zero. This is so that the motor doesn't start spinning as soon as you power it up. To find this point, open up the serial monitor, and adjust the potentiometer until it reaches 90. At this point, you should hear and audible beep that indicates that the motor is ready to move.

Thanks for following along. Check out early entries from this Introduction to Arduino Series. Subscribe below to stay up to date with future releases.


Also, if you're interested in the engineering design process and how to create a robotics prototype at home, check out my course.







The Bored Robot LLC is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com.

749 views0 comments

Recent Posts

See All