Controlling Brushless DC Motors (BLDC) with Arduino

Creating small objects and making them work the way you want has always been a fascinating endeavor. While reaching a consensus, building flying machines can make hobbyists feel a bit less confident. Here, I am referring to gliders, helicopters, airplanes, and multi-functional transport aircraft. Today, thanks to the support of online communities, it is easy to create a similar product by yourself. In these flying machines, they all use BLDC motors, so what is a BLDC motor? Why do we need it for flying? What makes it special? How do you buy the right motor and connect it to a controller? What is an ESC, and why do we need to use it? If you have these questions, then this article can resolve all your doubts.

Therefore, in this article, we will control the speed of the A2212 / 1T sensorless BLDC outrunner motor (commonly used in drone making) using an Arduino board and a 20A electronic speed controller (ESC).

Required Materials

● A2212 / 13T BLDC motor

● ESC controller (20A)

● Power supply (12V 20A)

● Arduino board

● Potentiometer

Understanding BLDC Motors

BLDC motor stands for Brushless Direct Current Motor, commonly used in ceiling fans and electric vehicles due to its smooth operation. Unlike other motors, a BLDC motor has three wires, each forming its own phase, making it a three-phase motor.

Yes, although BLDC motors are considered DC motors, they operate in pulse wave mode. The electronic speed controller (ESC) converts the DC voltage from the battery into pulses and delivers them to the three wires of the motor. At any given time, only two phases of the motor will be powered, so the current flows into one phase and out through another. During this process, the coils inside the motor are energized, aligning the magnets on the rotor with the energized coils. The next two wires are powered by the ESC, continuing the process to make the motor rotate. The speed of the motor depends on how fast the coils are energized, and the direction of the motor depends on the sequence in which the coils are energized. We will discuss the ESC in detail later in this article.

There are many types of BLDC motors available; let’s look at the most common classifications.

● Inner rotor and outer rotor BLDC motors: The inner rotor BLDC motor operates similarly to other motors, meaning the shaft inside the motor rotates while the casing remains fixed. The outer rotor BLDC motor is the opposite, where the casing rotates with the shaft while the coils inside remain fixed. Outer rotor motors are very advantageous in electric bicycles because the casing (the rotating casing) is made into the rim of the tire, avoiding the need for connecting mechanisms. Additionally, outer rotor motors tend to provide greater torque than inner rotor motors, making them ideal for EVs and drones. The motor we are using here is also an outer rotor motor.

Note: There is another type of motor called coreless BLDC motors, which are also used in pocket drones, but their operating principles differ, and this article will not cover them.

● Sensor and sensorless BLDC motors: For a BLDC motor that needs to rotate without any acceleration, a feedback signal is required. This means that the ESC must know the position and poles of the magnets in the rotor to energize the stator accordingly. This information can be obtained in two ways: one is to place Hall sensors inside the motor. The Hall sensors detect the magnets and send the information to the ESC; this type of motor is called a Sensored BLDC motor, used in electric vehicles. The second method is to use the back EMF generated when the magnets cross the coils, which does not require additional hardware or wires, where the line itself serves as feedback to check the back EMF. Our motor uses this method, commonly used in drones and other flying projects.

Why do drones and other multifunctional helicopters use BLDC motors?

From quadcopters to helicopters and gliders, there are many types of drones, all of which share one common hardware: the BLDC motor. But why? Why do they use BLDC motors, which are slightly more expensive than DC motors?

Controlling Brushless DC Motors (BLDC) with Arduino

There are many valid reasons, one major reason is the high torque these motors provide, which is crucial for quickly gaining/lossing thrust to take off or land a drone. These motors can also be used as outer rings, further increasing the thrust of the motor. Another reason for choosing a BLDC motor is its smooth operation with less vibration, which is ideal for our drones to remain stable in mid-air.

The power-to-weight ratio of BLDC motors is very high. This is important because the motors used in drones should have high power (high speed and high torque) but should also be lightweight. A DC motor that can provide the same torque and speed as a BLDC motor would be twice the weight of the BLDC motor.

Why do we need an ESC, and what is its function?

We know that each BLDC motor requires some controller to convert the DC voltage from the battery into pulses to power the motor phases. This controller is called ESC, which stands for Electronic Speed Controller. The main responsibility of the controller is to energize the BLDC motor phases in sequence so that the motor rotates. This is done by detecting the back EMF of each wire and accurately energizing the coils as the magnets pass through the coils. Therefore, the ESC has many hardware highlights that we do not intend to detail here. However, it is worth mentioning that it has a speed controller and battery eliminator circuit.

Controlling Brushless DC Motors (BLDC) with Arduino

● PWM-based speed control: The ESC can control the speed of the BLDC motor by reading the PWM signal provided on the orange line. Its operation is very similar to that of a servo motor; the provided PWM signal should have a 20ms period, and the duty cycle can be changed to alter the speed of the BLDC motor. Since the same logic applies to servo motors for position control, we can use the same servo library in the Arduino program.

● Battery Eliminator Circuit (BEC): Almost all ESCs come with a battery eliminator circuit. As the name suggests, this circuit does not require a separate battery for the microcontroller, meaning we do not need a separate power source to power the Arduino; the ESC itself will provide a +5V regulated power supply that can be used to power our Arduino. There are many types of circuits that can regulate this voltage, usually linear regulation for cheap ESCs, but you can also find circuits with switching regulation.

● Firmware: Each ESC has a firmware program written by the manufacturer. This firmware greatly determines how your ESC responds; some popular firmware includes Traditional, Simon-K, and BL-Heli. The firmware is also user-programmable, but we will not cover most of that in this tutorial.

Connection Schematic of Arduino Board Controlling BLDC Motor

Controlling Brushless DC Motors (BLDC) with Arduino

Connecting the BLDC motor to the Arduino board is very simple. The ESC requires a minimum of 12V/5A power supply. In this article, I used an RPS as the power supply, but you can also use a Li-Po battery to power the ESC. The three-phase wires of the ESC should be connected to the three-phase wires of the motor; the connection of these wires does not have an order, and you can connect them in any order.

Note: Some ESC controllers do not have connection terminals; in this case, ensure the connection is secure and use insulating tape to protect exposed wires. Since large currents will flow through the phases, any short circuit could cause permanent damage to the ESC and motor.

The BEC (Battery Eliminator Circuit) in the ESC will regulate an output of +5V, which can be used to power the Arduino board. Finally, to set the speed of the BLDC motor, we will also use a potentiometer connected to the A0 pin of the Arduino.

Controlling Brushless DC Motors (BLDC) with Arduino

Arduino Program for BLDC Motor

We need to create a PWM signal that varies the duty cycle from 0% to 100% at a frequency of 50Hz. The potentiometer controls the duty cycle to control the motor’s speed. The code for this operation is similar to controlling a servo motor, as they also require a PWM signal with a frequency of 50Hz; thus, we use the same servo library from Arduino. The complete code can be found at the end of this page.

The PWM signal can only be generated on pins that support PWM, which are usually marked with a ~ symbol. On the Arduino UNO board, pin 9 can generate a PWM signal, so we connect the ESC signal pin (orange wire) to pin 9; we use the following code to represent this connection:

  1. ESC.attach(9);

Copy code

We need to generate different PWM signals with duty cycles from 0% to 100%. For 0% duty cycle, the POT will output 0V (0), and for 100% duty cycle, the POT will output 5V (1023). Here, the potentiometer is connected to pin A0, so we must use the analogRead function to read the analog voltage from POT, as shown below:

  1. int throttle = analogRead(A0);

Copy code

Then we must convert the value from 0 to 1023 to 0 to 180 because a value of 0 will generate 0% PWM, and a value of 180 will generate a 100% duty cycle. Any value above 180 is meaningless. Therefore, we use the map function to map the value to 0-180, as shown below.

  1. throttle = map(throttle, 0, 1023, 0, 180);

Copy code

Finally, we need to send this value to the servo function so it can generate a PWM signal on that pin. Since we named the servo object ESC, the code is as follows, where the variable throttle contains a value from 0-180 to control the duty cycle of the PWM signal:

  1. ESC.write(throttle);

Copy code

Controlling BLDC Motor with Arduino

Follow the circuit diagram to connect and upload the code to the Arduino board, then power on the ESC. Make sure to mount the BLDC motor on something, as the motor will jump around when it rotates. Once powered on, the ESC will emit a welcome sound and continue to beep until the throttle signal is within the threshold limit; simply gradually increase the POT from 0V, and the beeping will stop, indicating that the PWM signal we are providing is above the lower threshold. As you increase further, the motor will start to rotate slowly. The higher the voltage you provide, the faster the motor will spin, and eventually, when the voltage exceeds the upper threshold, the motor will stop accelerating. You can repeat this process.

If you encounter any issues while using this work, please reply below for more technical assistance.

WelcomeAppreciation+Like+Comment+Share!

Leave a Comment

Your email address will not be published. Required fields are marked *