can't brake 1 of the 2 motors using motor shield

I am using Arduino UNO R3 with Arduino motor shield. By following the instructions as below:

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

void loop(){
  
  //Motor A forward @ half speed
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 123);   //Spins the motor on Channel A at half speed

  //Motor B forward @ half speed
  digitalWrite(13, HIGH); //Establishes forward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 123);   //Spins the motor on Channel B at half speed 
  
  delay(3000);
  
  digitalWrite(9, HIGH); //Engage the Brake for Channel A
  digitalWrite(8, HIGH); //Engage the brake for Channel B

  delay(2000);
  
  //Motor A backward @ half speed
  digitalWrite(12, LOW); //Establishes backward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 123);   //Spins the motor on Channel A at half speed
  //Motor B backward @ half speed
  digitalWrite(13, LOW); //Establishes forward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel b
  analogWrite(11, 123);   //Spins the motor on Channel B at half speed  
  
  delay(2000);
  digitalWrite(9, HIGH); //Engage the Brake for Channel A
  digitalWrite(8, HIGH);//Engage the brake for channel B
  
  delay(1000);
 
 while(1);
  
}

all goes o.k. the led on motor shield lit in the following sequence

port A(L) port A(R) port B (L) port B(R)
on dimm on dimm ← motor forward
on on on on ← motor brake // found channel B motor does not brake
dimm on dim on ← motor backward
off off off off ← only channel A motor brake // led not dim, but off

with reference to the code, channel B pin 8 was set to high to enable the brake, but it seems not working or not braking as channel A, can anyone help? thank you.

But at the end of loop(), in the part where you brake both motors, looks to me that one pin on each motor is still low so I’m surprised either motor is actually braking.

//

Motor A backward @ half speed
  digitalWrite(12, LOW); //Establishes backward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 123);   //Spins the motor on Channel A at half speed
  //Motor B backward @ half speed
  digitalWrite(13, LOW); //Establishes forward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel b
  analogWrite(11, 123);   //Spins the motor on Channel B at half speed  
  
  delay(2000);
  digitalWrite(9, HIGH); //Engage the Brake for Channel A <<<<<<<<<<<<<<<<< pin 12 is still low
  digitalWrite(8, HIGH);//Engage the brake for channel B <<<<<<<<<<<<<<<<<<<<< pin 13 is still low

Also, jbtw, you don’t seem to have set your PWM pins (3 and 11) as output.

thanks for your reply,

i think i miss sth.

  1. Both Channel A and B motor braked after forward, with Channel B a little delay. And
  2. Both channel A and B motor braked after backward; but

Channel B motors braked less than 1 seconds after Channel A motor(time lapse). As the programme is aimed to stop both motors at the same time, why there is a delay ? is it a hardware problem or software problem?

I have put back the pin 3 and 11 as input in the setup code, but they didn't solve the problem.

I don't know why one motor is braking late.

But as your code stands, I stick with what I said before, and that's in the backwards case, there is no braking because one pin on each channel is still low.

I have put back the pin 3 and 11 as input in the setup code, but they didn't solve the problem.

I hope you mean output not input. And I didn't mean it was anything to do with your problem, that's why I say "btw".