In this tutorial we will learn how to control a brushless motor using Arduino and ESC. In case you want more details how BLDC motors work, you can check the other article or watch the following video which contains explanation of the working principle of a brushless DC motor and how to control one using Arduino and ESC.
Overview
For this example, I have an outrunner BLDC motor with the following specifications: it has a KV rating of 1000, it can be powered using 2S, 3S or 4S LiPo battery and it requires 30A ESC. The KV rating on a brushless motor defines the RPM of the motor per volt with no load.
In this case, the 1000KV means that, for example, if we supply the motor with 2S LiPo battery which has a voltage of 7.4 volts, the motor can achieve maximum RPM of 7.4 times 1000, or that’s 7400 RPM.
Brushless motors are power hungry and the most common method for powering them is using LiPo batteries. The “S” number of a LiPo battery indicates how many cells the battery has, and each cell has a voltage of 3.7V.
For this example, I will use 3S LiPo battery which has 3 cells and that’s 11.1V. So, I can expect my motor to reach maximum RPM of 11100.
Lastly, here’s a 30A ESC that I will use for this example and match with the motor requirements. On one side the ESC has three wires that control the three phases of the motor and on the other side it has two wires, VCC and GND, for powering.
There is also another set of three wires coming out of the ESC and that’s the signal line, +5V and ground. This feature of the ESC is called Battery Eliminator Circuit and as the name suggests it eliminates the need of separate battery for a microcontroller. With this, the ESC provides regulated 5V which can be used to power our Arduino.
We can notice here that this connection is actually the same as the one we see on Servo motors.
So, controlling a brushless motor using ESC and Arduino is as simple as controlling servo using Arduino. ESCs use the same type of control signal as servo and that’s the standard 50Hz PWM signal.
This very convenient, because for example, when building an RC plane, we usually need both servos and brushless motors and, in this way, we can control them easily with the same type of controller.
So, using the Arduino we just have to generate the 50Hz PWM signal and depending on pulses width or the high state duration which should vary from 1 millisecond to 2 milliseconds, the ESC will drive the motor from minimum to maximum RPM.
Arduino Brushless Motor Control – Circuit Diagram
Here’s the circuit diagram for this example. In addition to the ESC we will just use a simple potentiometer for controlling the motor speed.
You can get the components needed for this Arduino Tutorial from the links below:
- Brushless Motor …………………………… Amazon / Banggood
- ESC 30A ……………………………………….. Amazon / Banggood
- Arduino Board …………………………….. Amazon / Banggood
- Potentiometer ……………………………… Amazon / Banggood
- Breadboard and Jump Wires ………… Amazon / Banggood
*Please note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
Arduino Code for BLDC Motor Control
The Arduino code is really simple with just few lines of code.
/* Arduino Brushless Motor Control by Dejan, https://howtomechatronics.com */ #include <Servo.h> Servo ESC; // create servo object to control the ESC int potValue; // value from the analog pin void setup() { // Attach the ESC on pin 9 ESC.attach(9,1000,2000); // (pin, min pulse width, max pulse width in milliseconds) } void loop() { potValue = analogRead(A0); // reads the value of the potentiometer (value between 0 and 1023) potValue = map(potValue, 0, 1023, 0, 180); // scale it to use it with the servo library (value between 0 and 180) ESC.write(potValue); // Send the signal to the ESC }
Description: So, we need to define the Servo library, because with the servo library we can easily generate the 50Hz PWM signal, otherwise the PWM signals that the Arduino generates are at different frequencies. Then we need to create a servo object for the ESC control and define a variable for storing the analog input from the potentiometer. In the setup section, using the attach() function, we define to which Arduino pin is the control signal of the ESC connected and also define the minimum and maximum pulses width of the PWM signal in microseconds.
In the loop section, first we read the potentiometer, map its value from 0 to 1023 into value from 0 to 180. Then using the write() function we send the signal to the ESC, or generate the 50Hz PWM signal. The values from 0 to 180 correspond to the values from 1000 to 2000 microseconds defined in the setup section.
So, if we upload this code to our Arduino, and then power up everything using the battery, then we can control the speed of the brushless motor of zero to maximum using the potentiometer.
However, there are few things that we should note here. When initially powering the motor, the signal value must be the same or lower than the minimum value of 1 millisecond. This is called arming of the ESC, and the motor makes a confirmation beeps so that we know that it’s properly armed. In case we have higher value when powering, which means we have a throttle up, the ESC won’t start the motor until we throttle down to the correct minimum value. This is very convenient in terms of safety, because the motor won’t start in case we have a throttle up when powering.
ESC Calibration
Lastly, let’s explain how ESC calibration works. Every ESC has its own high and low points, and they might slightly vary. For example, the low point might be 1.2 milliseconds and the high point might be 1.9 milliseconds. In such a case, our throttle won’t do anything in the first 20% until it reaches that low point value of 1.2 milliseconds.
To solve this issue, we can calibrate the ESC or set the high and low points as we want. For that purpose, before powering the ESC, first we need to throttle up our potentiometer to maximum or a value at least greater then the current middle point. Then we can power up the ESC, and we will hear few beeps from the motor which actually confirms that we have set the new high point.
Then after 2 seconds, we should move our potentiometer to the position where we what the new low point to be. We will again hear the confirmation beeps and with that we are done with the ESC calibration. Now our throttle will respond right away and we can control the motor within these new two points.
That’s pretty much everything for this tutorial. In case you want to learn how to wirelessly make this Arduino brushless motor control, you can check my previous video where I build and Arduino based RC transmitter and explained how to control BLDC motors using it.
I hope you enjoyed this tutorial and learned something new . Feel free to ask any question in the comments section below and don’t forget to check my collection of Arduino Projects.
The post Arduino Brushless Motor Control Tutorial | ESC | BLDC appeared first on HowToMechatronics.
from HowToMechatronics http://bit.ly/2Wxjtux
No comments:
Post a Comment