Arduino Motors not turning at the same time

I have been trying to make two motors to turn at the same time to no success. If i disconnect one motor, its fine but I can't get it work when both are connected. Why is this?


//define the two direction logic pins and the speed / PWM pin
const int BDIR_A = 5;
const int BDIR_B = 6;
const int PWMB = 7;
const int PWMA = 4;
const int ADIR_A = 3;
const int ADIR_B = 2;

void setup()
//set all pins as output
pinMode(BDIR_A, OUTPUT);
pinMode(BDIR_B, OUTPUT);
pinMode(PWMB, OUTPUT);

pinMode(ADIR_A, OUTPUT);
pinMode(ADIR_B, OUTPUT);
pinMode(PWMA, OUTPUT);

void loop()
//drive forward at full speed by pulling DIR_A High
//and DIR_B low, while writing a full 255 to PWM to
//control speed
digitalWrite(BDIR_A, LOW);
digitalWrite(BDIR_B, HIGH);
analogWrite(PWMB, 100);
digitalWrite(ADIR_A, LOW);
digitalWrite(ADIR_B, HIGH);
analogWrite(PWMA, 100);

//wait 1 second

//Brake the motor by pulling both direction pins to
//the same state (in this case LOW). PWM doesn't matter
//in a brake situation, but set as 0.
digitalWrite(BDIR_A, LOW);
digitalWrite(BDIR_B, LOW);
analogWrite(PWMB, 0);

digitalWrite(ADIR_A, LOW);
digitalWrite(ADIR_B, LOW);
analogWrite(PWMA, 0);

//wait 1 second


What motor driver are you using? And how are you powering the motors? If it's through the Arduino then that is almost certainly your problem. Motors, like servos, should be powered separately.