Unable to control two BLDC motors using Arduino.. Help me.

/*guys, we are trying to make a line follower hovercraft .
We want to run two brushless motors at two separate constant speeds.
We are unable to run the two motors simultaneously using the pwm signals.
Only one of the motors is reacting to the given code.
The other one is just being idle.
but while testing individually both are working perfectly.

I am posting my program below
please let me know if there has to be any modifications required
and please let me know any ideas to improve the code

My arduino code
*/

#include <Servo.h>

int pin[5]={0,1,2,3,4};
int pinvalue[5]={0,0,0,0,0};
int state=1;
int arming_time=0;
int mpin1=10;
int mpin2=6;
int pulse=1000;

Servo myservo; // create servo object to control a servo

void setup()
{
Serial.begin(9600);

myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(mpin1,OUTPUT);
pinMode(mpin2,OUTPUT);

// arming first motor

for(arming_time=0;arming_time<500;arming_time+=1)
{
digitalWrite(mpin1,HIGH);
delayMicroseconds(1150);
digitalWrite(mpin1,LOW);
delay(20-(pulse/1000));
}

// arming second motor

for(arming_time=0;arming_time<500;arming_time+=1)
{
digitalWrite(mpin2,HIGH);
delayMicroseconds(1150);
digitalWrite(mpin2,LOW);
delay(20-(pulse/1000));
}

}

void loop()
{
int i;

//code to run first motor
digitalWrite(mpin1, HIGH);
delayMicroseconds(1400);
digitalWrite(mpin1, LOW);
delay(20-(1250/1000));

// code to rotate second motor
digitalWrite(mpin2, HIGH);
delayMicroseconds(1400);
digitalWrite(mpin2, LOW);
delay(20-(1250/1000));

// takng values from sensor kit

for(i=0;i<5;i++)
{
pinvalue_=analogRead(pin*);_
_
}*_

* // controlling servo*

* if(pinvalue[2] <60)*
* {*
* myservo.write(90);*
* delay(10);*
* }*
* if( (pinvalue[0]<50))*
* {*
* myservo.write(10);*
* delay(10);*
* }*
* if(pinvalue[1]<50)*
* {*
* myservo.write(70);*
* delay(10);*
* }*
* if(pinvalue[3]<50)*
* {*
* myservo.write(110);*
* delay(10);*
* }*

* if((pinvalue[4]<50))*
* {*
* myservo.write(170);*
* delay(10);*
* }*

}

HI, to make your sketch clearer can you use the # code tags please.
Also before posting the sketch, select TOOL, AUTO FORMAT on your programming window.
Can you also post a pic of your project and a CAD or pic of a hand drawn circuit.
Thanks, we will try to help you get it running.
Have you written and tested with a sketch that just turns the two motor outputs HIGH to check your wiring to both motors?

Tom..... :slight_smile:

You need a separate Servo object for each ESC+motor you are driving. The standard
Servo library supports upto 12 pins on the Uno, 48 on the Mega. Don't try and use
explicit loops to generate servo signals, the timing is too sloppy.