I'm working on a project ( a quadcopter). the brushless DC motors are driven by an Electronic Speed controller which drives the motors at varying speeds depending upon the PWM values inputted to the ESC. I'm varying the pwm by means of a visual studio application that i designed.
So, basically, PC-->arduino dumilanalov-->RF transmitter --- RF receiver-->arduino dumilanalov-->ESC-->brushless DC motor
The motor starts when i gradually increase the pwm. When i tried using pwm pins 3 and 11, the motor worked perfectly, but pins 5 and 6 didn't seem to work. So i tried connecting an LED to it. But the LED responded correctly. VirtualWire(the library i used for the wireless communication) takes over Arduino Timer1, and this will affect the PWM capabilities of the digital pins 9 and 10.
In the arduino reference page, it is given
Notes and Known Issues
The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.
Here is code on the receiver arduino,
#include <VirtualWire.h>
const int pin=5;
void setup() //reception-12, motor-3
{
Serial.begin(9600);//debugging purposes
pinMode(13,OUTPUT);
pinMode(pin,OUTPUT);
pinMode(2,OUTPUT);
vw_set_rx_pin(12);
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_rx_start(); //start the PLL running
}
void loop()
{
transmission();
}
void transmission()
{
uint8_t buf[VW_MAX_MESSAGE_LEN],pwm;
uint8_t buflen = VW_MAX_MESSAGE_LEN;
char msg[10],start[2]="s";
int i=0;
//
if (vw_get_message(buf, &buflen))
{
digitalWrite(13,HIGH);
//pwm=atoi(buf);
for(i=0;i<buflen;i++)
msg[i]=buf[i];
msg[i]='\0';
if(strcmp(msg,start)==0) // checking for an input from PC for automatic start
starter();
pwm=atoi(msg);
Serial.println(pwm);
analogWrite(pin,pwm);
digitalWrite(13,LOW);
}
}
void starter()
{
digitalWrite(2,HIGH);
analogWrite(pin,0);
delay(200);
analogWrite(pin,50);
delay(1000);
analogWrite(pin,80);
delay(1000);
analogWrite(pin,100);
delay(2000);
analogWrite(pin,150);
delay(1000);
digitalWrite(2,LOW);
}