Brushless motor very weird thing!

Hello,

I’ve been controlling a brushless motor through its speed control using the Serial terminal between it and the computer using this code

#include <Servo.h>
Servo myservo;
int pos=50;

void setSpeed(int speed){
  // speed is from 0 to 100 where 0 is off and 100 is maximum speed
  //the following maps speed values of 0-100 to angles from 0-180,
  // some speed controllers may need different values, see the ESC instructions
  int angle = map(speed, 50, 110
    , 50
    , 180);
  myservo.write(angle);    
}

void setup()
{
  Serial.begin(9600);
  myservo.attach(6);
  setSpeed(pos);
  delay(1000);
}
void loop() 
{ 
  char recvChar;
  if(Serial.available()){
    recvChar=Serial.read();
    if(recvChar == 'h'){
      if(pos<74){
        pos=pos+1;
      }
      else{
        pos=74;
      }
      Serial.println(pos);
      setSpeed(pos);
      delay(1000);
    }
      if(recvChar == 'b'){
        if(pos>55){
          pos=pos-1;
          Serial.println(pos);
          setSpeed(pos);
          delay(1000);
        }
      }
  }
}

And it’s working very good!, now I have bluetoothShield " http://www.seeedstudio.com/depot/bluetooth-shield-p-866.html " and i want to control the motor through the bluetooth terminal.So i wrote this code

#include <Servo.h>
#include <SoftwareSerial.h>
#define RxD 6
#define TxD 7
#define DEBUG_ENABLED  1
SoftwareSerial blueToothSerial(RxD,TxD);
Servo myservo;
int pos=50;

void setSpeed(int speed){
  // speed is from 0 to 100 where 0 is off and 100 is maximum speed
  //the following maps speed values of 0-100 to angles from 0-180,
  // some speed controllers may need different values, see the ESC instructions
  int angle = map(speed, 50, 110
    , 50
    , 180);
  myservo.write(angle);    
}

void setup()
{
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  myservo.attach(6);
  setSpeed(pos);
  delay(1000);
  setupBlueToothConnection();
}
void loop() 
{
  while(1){ 
    char recvChar;
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      if(recvChar == 'h'){
        if(pos<74){
          pos=pos+1;
        }
        else{
          pos=74;
        }
        setSpeed(pos);
        delay(1000);
      }
        if(recvChar == 'b'){
          if(pos>55){
            pos=pos-1;

            setSpeed(pos);
            delay(1000);
          }
        }
    }
  }
}

void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  //Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

BUT IT’S NOT WORKING!, IT doesn’t do anything to the motor although the same code will work if i used it with a Servo motor!

Please any help because I can’t proceed in my project and i feel very LOST! :frowning:

Thanks in advance!

Which pin is your ESC connected to? Which pins are you using for Software Serial?

Well I have to admit it!, I AM either very STUPID or distracted by not been asleep for a long time! hahah I didn't recognize that I am overriding the same pin :D:D:D. Thanks a lot MAN!!!