Set Speed Control of Brushless DC Motor using Servo Library

Hello,

I am relatively new in using Arduino. I am trying to run a Brushless DC Motor using the Servo library. I have the correct power supply, ESC, and correctly connected to the arduino pin 9. I got it to work using many different sketches I have found, however I am trying to set it to a certain speed and have it spin constantly at that speed while turned on. Eventually, I will incorporate some sort of feedback for the speed. I would like to avoid using a potentiometer and be able to set the desired speed directly within the code. Seems like it should be simple, but I am having trouble.

I am now using the following code:

#include <Servo.h> 

Servo myservo;

void setup() 
{ 
  myservo.attach(9);
  myservo.write(60);  //Sets speed of motor (60 (low) - 180 (high) i think)
} 

void loop() {}

Through trial and error, any lower than 60 the motor will stop running, however, it is still relatively fast. Is this a limitation from my ESC or from my motor? I would like to understand the process of what is going on better so I can have more precise control over the speed. Any input would be greatly appreciated!

Thanks
Nick

I am trying to run a Brushless DC Motor

...that you haven't specified...

the correct power supply

...that you haven't specified...

ESC

...that you haven't specified...

Seems like it should be simple, but I am having trouble.

Where are you arming and calibrating the ESC?

Is this a limitation from my ESC or from my motor?

Probably. Or the power supply. Or the code (specifically, what is not there). Or the load on the motor. Or the wiring.

Hi, would also like feedback on this.

As I understand it by just reading the sweep.ino code in the example libraries - one should be able to set pos = x (where x is your desired speed) instead of having it increment.

I.e. "for (pos =0; pos <180; pos+- 1)
{
myservo.write (pos);
delay (15);
}
could change to
int pos = 30; //for example
myservo.write (30);

This is probably like a really basic setup because I came across a program to sweep the motor using the command "map" which incorporated speed and angle.

'int angle = map (speed, 0, 100, 0, 180);
myservo.write (angle)' //sweeps motor from 0 to max

Could you change that 180 (degrees) by the way? I experimented with the speed "100" but it still runs quite high. Doesnt make sense to change the 180 though since that allows a full rotation??

I could also just be way off course, I'm just another new kid on the block :smiley:

hi . i am facing exact same problem as one described by rader945.
i am using a 20A emax esc and emax bldc 2213-935kv. its not slow enough even at 65 , the speed is glitchy and motor stops at 60 . what is the proper way to control its speed .
here is the code that im using

#include <Servo.h>

Servo myservo;

int pos = 0;
void setup()
{
myservo.attach(9);

}

void loop()
{
for(pos = 0; pos < 180; pos += 1)
{
myservo.write(pos);
delay(50);
}

while(1)
{
myservo.write(60);
}
}

please help me out . my final year project is stuck due to this

Through trial and error, any lower than 60 the motor will stop running, however, it is still relatively fast. Is this a limitation from my ESC or from my motor? I would like to understand the process of what is going on better so I can have more precise control over the speed. Any input would be greatly appreciated!

That is my experience with brushless DC motor/ESC used in R/C airplanes also. They don't control real well at slowest RPMs because the ESC is using electrical feedback pulses sensed on the three motor windings to determine speed and such pulses can be very small at slow speeds. Once above that 'threshold' the speed should be pretty linear Vs the servo.write command values you give it. So I would suggest not trying to attach any kind of external RPM feedback circuitry as the ESC is already a 'speed controller' you just have to characterize it's performance vs your servo write values.

Also using servo write microseconds rather then servo write degrees will improve the response curve of the motor/esc.

Lastly, know that brushless motor/ESC speed control relationship is dependent on the mechanical load on the motor. Some motor/ESCs work poorly or erratically with no load on the motor. Try to test out using real world motor loads.

Lefty

thankyou so much .the above reply was very helpful.
but there is one other issue that im facing .. the code is running fine and motor speed is also controllable through servo.write() between 180-63(min) but at round servo 70-75 the motor speed fluctuates. when i checked the input voltage at the esc it was varying between 8-10V thus the speed keeps going up and down . im powering the esc through a variable dc adapter. what could be the possible issue ? is it the adapter or some fault with the esc ???

retrolefty:

Through trial and error, any lower than 60 the motor will stop running, however, it is still relatively fast. Is this a limitation from my ESC or from my motor? I would like to understand the process of what is going on better so I can have more precise control over the speed. Any input would be greatly appreciated!

That is my experience with brushless DC motor/ESC used in R/C airplanes also. They don't control real well at slowest RPMs because the ESC is using electrical feedback pulses sensed on the three motor windings to determine speed and such pulses can be very small at slow speeds. Once above that 'threshold' the speed should be pretty linear Vs the servo.write command values you give it. So I would suggest not trying to attach any kind of external RPM feedback circuitry as the ESC is already a 'speed controller' you just have to characterize it's performance vs your servo write values.

Also using servo write microseconds rather then servo write degrees will improve the response curve of the motor/esc.

Lastly, know that brushless motor/ESC speed control relationship is dependent on the mechanical load on the motor. Some motor/ESCs work poorly or erratically with no load on the motor. Try to test out using real world motor loads.

Lefty

i have a stupid Question want to know.
can i use the signal from 3 wires of the ESC to feedback to the CPU to have a close-loop
i want to know the speed of motor and display in lcd

best regards

vubangbk_Cap:

retrolefty:

Through trial and error, any lower than 60 the motor will stop running, however, it is still relatively fast. Is this a limitation from my ESC or from my motor? I would like to understand the process of what is going on better so I can have more precise control over the speed. Any input would be greatly appreciated!

That is my experience with brushless DC motor/ESC used in R/C airplanes also. They don't control real well at slowest RPMs because the ESC is using electrical feedback pulses sensed on the three motor windings to determine speed and such pulses can be very small at slow speeds. Once above that 'threshold' the speed should be pretty linear Vs the servo.write command values you give it. So I would suggest not trying to attach any kind of external RPM feedback circuitry as the ESC is already a 'speed controller' you just have to characterize it's performance vs your servo write values.

Also using servo write microseconds rather then servo write degrees will improve the response curve of the motor/esc.

Lastly, know that brushless motor/ESC speed control relationship is dependent on the mechanical load on the motor. Some motor/ESCs work poorly or erratically with no load on the motor. Try to test out using real world motor loads.

Lefty

i have a stupid Question want to know.
can i use the signal from 3 wires of the ESC to feedback to the CPU to have a close-loop
i want to know the speed of motor and display in lcd

best regards

In theory one could but it would be somewhat software challenging analyzing/designing. Also if the motor runs at higher then 5vdc winding voltage then reading them back as analog signals would require external resistor divider networks.

rumshaa:
thankyou so much .the above reply was very helpful.
but there is one other issue that im facing .. the code is running fine and motor speed is also controllable through servo.write() between 180-63(min) but at round servo 70-75 the motor speed fluctuates. when i checked the input voltage at the esc it was varying between 8-10V thus the speed keeps going up and down . im powering the esc through a variable dc adapter. what could be the possible issue ? is it the adapter or some fault with the esc ???

The ESC will probably be pulling current spikes that are overloading the DC adapter.
The drop in voltage then causes the ESC to adjust its behaviour.

Remember these motors have only a few turns of chunky wire, they can easily pull dozens of
amps without flinching, if only for a few microseconds, can your supply cope? These
ESC/motor combinations are developed to work from high performance LiPo packs
which have little difficulty sourcing extremely high currents without much voltage
drop.

i am having a little trouble with the code i am using. my motor does not run continuously and when it runs, it does that at a very low speed kindly help me the code i am using is

int state=1;
int arming_time=0;
int pin=9;
int Pulse=1000;
void setup()
{
pinMode(pin,OUTPUT);
for(arming_time=0;arming_time<500;arming_time+=1)
{
digitalWrite(pin,HIGH);
delayMicroseconds(1100);
digitalWrite(pin,LOW);
delay(20-(Pulse/1000));

}
}
void loop()
{
for(Pulse=1150;Pulse<=1400;Pulse+=1)
{
digitalWrite(pin,HIGH);
delayMicroseconds(1100);
digitalWrite(pin,LOW);
delay(20-(Pulse/1000));

}
for(Pulse = 1400;Pulse >=1150;Pulse -=1)
{digitalWrite(pin,HIGH);
delayMicroseconds(Pulse);
digitalWrite(pin,LOW);
delay(20-(Pulse/1000));

}
}