Programming two motors

Hi,

Im relatively new to Arduino so would greatly appreciate some code advice. I posted a similar message the other day but have now had to switch to the Arduino Motor Shield R3.

I need to run two DC Motors using the Arduino motor shield. I need to run one motor forward on Motor A for 2450, then run another motor on Motor B after Motor A for 2600, then stop both of them for 30000, then repeat again.

I have managed to work out some of the code but cant get them delay at the right times, motor B seems to come on for too long.

void setup() {
  
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin
  
}

void loop(){

  
  //Motor A forward @ full speed
  digitalWrite(12, LOW); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed

  delay(2450);

  digitalWrite(9, HIGH);  //Engage the Brake for Channel A

  
  //Motor B forward @ full speed
  digitalWrite(13, HIGH); //Establishes forward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 255);   //Spins the motor on Channel B at full speed
  
  delay(2600);
  

  digitalWrite(9, HIGH);  //Engage the Brake for Channel B
  
  
  delay(30000);
  
}

Many thanks!! :slight_smile:

You seem to be engaging the break while still powering the motor!