Hi there, When I power my project by giving power to my ESC which it's line is connected to pin9 on the arduino board my brushless motor comes on after a few seconds. The only way to stop it is to kill power to the esc. I can control the speed of the motor with a app on my smartphone to a certain extent but i cant stop the motor. Here is my sketch. I hope someone can help.
#include <Servo.h>
#include <SoftwareSerial.h>
int incomingByte = 0; // for incoming serial data
int armingTime;
int pin = 9;
int counter = 0;
int pulseTime = 1100; //microseconds
boolean highSpeed = true;
Servo myservo;
void setup(){
Serial.begin(9600);
myservo.attach(9);
Serial.println("Enter 0-9 to adjust motor speed.");
Serial.println("Enter h or l to change the speed range.");
}
void loop(){
digitalWrite(pin, HIGH);
delayMicroseconds(pulseTime);
digitalWrite(pin, LOW);
delay(10-(pulseTime/1000));
if(Serial.available() > 0){
incomingByte = Serial.read();
}
//void incomingByte(){
//void readSerialVal(){
switch (incomingByte) {
case '0':
setTimingParams(1100);
incomingByte='*';
Serial.print("Throttle: ");
Serial.print((pulseTime-1100)/8);
Serial.println("%");
break;
case '2':
setTimingParams(1300);
incomingByte='*';
Serial.print("Throttle: ");
Serial.print((pulseTime-1100)/8);
Serial.println("%");
break;
case '3':
setTimingParams(1400);
incomingByte='*';
Serial.print("Throttle: ");
Serial.print((pulseTime-1100)/8);
Serial.println("%");
break;
case '4':
setTimingParams(1500);
incomingByte='*';
Serial.print("Throttle: ");
Serial.print((pulseTime-1100)/8);
Serial.println("%");
break;
case '5':
setTimingParams(1600);
incomingByte='*';
Serial.print("Throttle: ");
Serial.print((pulseTime-1100)/8);
Serial.println("%");
break;
case '6':
setTimingParams(1700);
incomingByte='*';
Serial.print("Throttle: ");
Serial.print((pulseTime-1100)/8);
Serial.println("%");
break;
case '7':
setTimingParams(1800);
incomingByte='*';
Serial.print("Throttle: ");
Serial.print((pulseTime-1100)/8);
Serial.println("%");
break;
case '9':
setTimingParams(1900);
incomingByte='*';
Serial.print("Throttle: ");
Serial.print((pulseTime-1100)/8);
Serial.println("%");
break;
}
}
void setTimingParams(int newPulseTimeVal){
if(highSpeed){
pulseTime = newPulseTimeVal;
} else {
pulseTime = 1025 + (newPulseTimeVal/10);
}
}