Programming help, controlling d/c motors with Arduino Uno

I am trying to control 4 dc motors using two dual h-bridges and an Arduino Uno.With my code I have got all the motors to work one at a time but when I trying running them together I get problems. Motor A and B will propel my rov up and down. Motor C and D will go forward and reverse, and turn left or right by varying the speed of each motor. I want to have a standby pin for each H-Bridge so I can turn the motors off and on in pairs. The way I have my code setup both standby pins are enabled when I write void stop();. How do I define my standby pins differently so I have control of each direction individually. I am fairly new to this. Below is the code I have been trying to use.

//The below code defines the output pins on the Arduino will hookup to specified pins on the HBridge
int STBY = 1; //this will be the standby pin
//Motor A
int PWMA = 6; //Speed control
int AIN1 = 2; //Direction
int AIN2 = 3; //Direction
//Motor B
int PWMB = 5; //Speed control
int BIN1 = 4; //Direction
int BIN2 = 7; //Direction

int STBY1 = 0;
//Motor C
int PWMC = 11; //Speed control
int CIN3 = 10; //Direction
int CIN4 = 8; //Direction
//Motor D
int PWMD = 9; //Speed control
int DIN3 = 12; //Direction
int DIN4 = 13; //Direction

void setup(){
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
pinMode(STBY1, OUTPUT);
pinMode(PWMC, OUTPUT);
pinMode(CIN3, OUTPUT);
pinMode(CIN4, OUTPUT);
pinMode(PWMD, OUTPUT);
pinMode(DIN3, OUTPUT);
pinMode(DIN4, OUTPUT);
void loop(){
move(0,250, 0); //motor 1, full speed, right
move(1,250, 0); //motor 2, full speed, right
void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 1 for B 0 for A
//motor: 2 for C 3 for D
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise

digitalWrite(STBY, HIGH);
//disable standby to H-Bridge 1
digitalWrite(STBY1, HIGH); //disable standby to H-Bridge 2

boolean inPin1 = LOW;
boolean inPin2 = HIGH;
boolean inPin3 = LOW;
boolean inPin4 = HIGH;

if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
inPin3 = HIGH;
inPin4 = LOW;
if(motor == 0){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
} if(motor == 1){
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}if(motor == 2){
digitalWrite(CIN3, inPin3);
digitalWrite(CIN4, inPin4);
analogWrite(PWMC, speed);
}if(motor == 3){
digitalWrite(DIN3, inPin3);
digitalWrite(DIN4, inPin4);
analogWrite(PWMD, speed);

}void stop(){
//enable standby
digitalWrite(STBY, LOW);
digitalWrite(STBY1, LOW);


How do I define my standby pins differently so I have control of each direction individually.

I don't understand the question, unfortunately.

You need to post a schematic of your setup. What h-bridges are you using?- presumably an off-the-shelf chip?

PS, please also put your code in code tags: the # button above the :wink: smiley.

Then your code will look like this....

Hi, i’m currently doing a project on controlling dc motor direction using L298 & arduino uno. Below is the code that i wrote. May i know does it work if i execute on my robot?

const int INPin1 =7;
const int INPin2 =6;
const int INPin3 =5;
const int INPin4 =4;

void setup()

pinMode (INPin1, OUTPUT);
pinMode (INPin2, OUTPUT); // Initiallize Port
pinMode (INPin3, OUTPUT);
pinMode (INPin4, OUTPUT);


void loop()

digitalWrite(INPin1, LOW);
digitalWrite(INPin2, LOW); // STOP
digitalWrite(INPin3, LOW);
digitalWrite(INPin4, LOW);


digitalWrite(INPin2, HIGH);
// Forward
digitalWrite(INPin4, HIGH);


digitalWrite(INPin2, HIGH);

delay(5000); // Turn Right

digitalWrite(INPin1, HIGH);
// Reverse
digitalWrite(INPin3, HIGH);


digitalWrite(INPin4, HIGH);

delay(5000); // Turn Left


May i know does it work if i execute on my robot?

Yes, you may, and that’s how you’ll know.