Arduino Motor Shield R3 - Motors don't fully break

Hi!
I am trying to build a little RC car and so I bought the Arduino Motor Shield R3 to have a better control over my motors.
I tried to use them with a "test" program, but I got a little issue.

I connected a button that should allow the motors to run only when the button is pressed.

// CHANNEL A
  //Dir = 12
  //Speed = 3
  //Brake = 9
  //Current Sensing = A0

// CHANNEL B
  //Dir = 13
  //Speed = 11
  //Brake = 8
  //Current Sensing = A1

// Every pin is composed by the channel (a/b) and the function of that pin 

#define adir 12
#define bdir 13
#define aspeed 3
#define bspeed 11
#define abrake 9
#define bbrake 8
#define acs A0
#define bcs A1
#define f HIGH // Forwards
#define b LOW // Backwards

#define button 7

void setup() {
  Serial.begin(9600);
  pinMode(adir, OUTPUT);
  pinMode(bdir, OUTPUT);
  pinMode(abrake, OUTPUT);
  pinMode(bbrake, OUTPUT);
  pinMode(aspeed, OUTPUT);
  pinMode(bspeed, OUTPUT);
  pinMode(button, INPUT);
}

void loop() {
  int x = digitalRead(button);
  if (x == HIGH) { // Button pressed

// CHANNEL A
    digitalWrite(adir, b); // Direction: backwards
    digitalWrite(abrake, LOW); // No brakes
    analogWrite(aspeed, 255); // MAX speed

// CHANNEL B
    digitalWrite(bdir, b); // Direction: backwards
    digitalWrite(bbrake, LOW); // No brakes
    analogWrite(bspeed, 255); // MAX speed

  } else { // Button not pressed

   digitalWrite(abrake, HIGH); // Full brakes channel A
   digitalWrite(bbrake, HIGH); // Full brakes channel B

  }
}

The problem is that when I press the button the motors only slow down, but don't FULLY stop.

FYI: I connected 5v and GND to the Motor Shield Vin and GND.
Thank you

"I am trying to build a little RC car and so I bought the Arduino Motor Shield R3 to have a better control over my motors.
I tried to use them with a "test" program, but I got a little issue."

Suppose you let us in on the issue secret. Do the motors work properly with the sample program? Then did you make changes to the sample program, or use a different one?

Paul

Did you mean "brake"?

Brake, like the ones that bikes and cars have to stop

Paul_KD7HB:
Suppose you let us in on the issue secret. Do the motors work properly with the sample program? Then did you make changes to the sample program, or use a different one?

Paul

void loop() {
  digitalWrite(bdir, f);
  digitalWrite(bbrake, HIGH);
  analogWrite(bspeed, 255);
}

This works. The engine isn't moving (If I put bbrake LOW it does)

void loop() {
  int x = digitalRead(button);
  delay(2);
  if(x==HIGH) {
    digitalWrite(bbrake, LOW);
    digitalWrite(bdir, f);
    analogWrite(bspeed, 255);
  } else {
    analogWrite(bspeed, 1);
    digitalWrite(bbrake, HIGH);
  }
}

But this doesn't

analogWrite(bspeed, 1);Why 1?

Just to try to put a very low number

I don't know why but...

void loop() {
  int x = digitalRead(button);
  if (x==1) {
    digitalWrite(adir, f);
    digitalWrite(abrake, HIGH);
    analogWrite(aspeed, 255);
  } else {
    digitalWrite(adir, f);
    digitalWrite(abrake, LOW);
    analogWrite(aspeed, 255);
    digitalWrite(bdir, f);
    analogWrite(bspeed, 255);
    digitalWrite(bbrake, LOW);
    delay(100);
  }
}

This is working.

I mean, why???
The motor B brakes also if in the code I never told him to do so...

And this

void loop() {
  int x = digitalRead(button);
  if (x==0) {
    digitalWrite(adir, f);
    digitalWrite(abrake, HIGH);
    analogWrite(aspeed, 255);
  } else {
    digitalWrite(adir, f);
    digitalWrite(abrake, LOW);
    analogWrite(aspeed, 255);
    digitalWrite(bdir, f);
    analogWrite(bspeed, 255);
    digitalWrite(bbrake, LOW);
    delay(100);
  }
}

Doesn’t!!! I only changed from 1 to 0 the condition in the if!!!

It seems like I'm doing something wrong on the breadboard...

I connected the + directly into the button, then a resistance, then the cable to pin 7, then ground. Is this wrong?

nicolopadovandev:

void loop() {

digitalWrite(bdir, f);
 digitalWrite(bbrake, HIGH);
 analogWrite(bspeed, 255);
}




This works. The engine isn't moving (If I put bbrake LOW it does)

That is just as expected!

"The motor driver on the Arduino Motor Shield has the ability to apply an engine brake. The brake works by shorting both terminals of the motor together. The brake is controlled by Pin 8 (Channel A) and Pin 9 (Channel B). "

The braking is dynamic to rapidly SLOW the motor. It is not the same as brakes in your car.

Paul

So how do I stop the motor?
Also.. when I touch my computer while the motor are running they suddenly stop

nicolopadovandev:
So how do I stop the motor?
Also.. when I touch my computer while the motor are running they suddenly stop

You can't stop them with what you have. You need a real brake mechanism of some sort.

Paul

Can I just put speed at 0?

SOLUTION

I finally managed to do what I need:

// CHANNEL A
  //Dir = 12
  //Speed = 3
  //Brake = 9
  //Current Sensing = A0

// CHANNEL B
  //Dir = 13
  //Speed = 11
  //Brake = 8 
  //Current Sensing = A1

#define adir 12
#define bdir 13
#define aspeed 3
#define bspeed 11
#define abrake 9
#define bbrake 8
#define acs A0
#define bcs A1
#define f HIGH // Forwards
#define b LOW // Backwards

#define button 7

void setup() {
  Serial.begin(9600);
  pinMode(adir, OUTPUT);
  pinMode(bdir, OUTPUT);
  pinMode(abrake, OUTPUT);
  pinMode(bbrake, OUTPUT);
  pinMode(aspeed, OUTPUT);
  pinMode(bspeed, OUTPUT);
  pinMode(button, INPUT);
}

void loop() {
  int x = digitalRead(button);
  Serial.println(x);
  if (x==HIGH) {
    
    Serial.println("TRUE");
    digitalWrite(bdir, f);
    digitalWrite(bbrake, LOW);
    analogWrite(bspeed, 255);

    digitalWrite(adir, f);
    digitalWrite(abrake, LOW);
    analogWrite(aspeed, 255);
    
  } else {
    
    Serial.println("FALSE");
    digitalWrite(bbrake, HIGH);
    digitalWrite(abrake, HIGH);
  }
}

This code is the right one!

Can you turn the motor shaft after your program stops it?

Paul

Setting speed to zero is not the same as brake.
Brake involves putting a short-circuit (or as close as you can get) across the motor.

Yeah but I only need to stop the engine