Braking a 5A DC motor with VNH5019 shield

Is there a way to set forward braking different than reverse braking?

I am just learning to use my new Dual VNH5019 motor driver shield. So far, it seems to work great for driving a 2.5" 12VDC motor that powered a car window, in both directions.
However, in one direction, there appears to be hard braking, while in the other, it coasts to a stop. Judging from the LEDs on the controller, this is something going on with the controller, not a quirk of the motor (which is driving nothing a the moment). Forward LED fades out when I send a setM1Speed = 0 command after it was going at +400, and snuffs out quickly when I send the same command after it was going at -400.

I see there is a setM1Brake command, but I don’t see any way to set forward braking different than reverse braking. And when I used this command to specify “full braking” (400), I still got coasting when stopping from the forward direction, and hard brake when stopping from reverse. I am probably doing something wrong, or forgetting to do something, so feel free to educate me! The User’s Guide and the Library Reference don’t have much to say about braking.


Hello, Steve.

If you are getting behavior from the VNH5019 where the motor brakes hard if it’s moving in one direction but coasts to a stop if it’s moving in the other direction, it means that one of the high-side MOSFETs for the H-bridge is on but the other three MOSFETs are off. This can happen if the PWM line is low and exactly one of INA/INB is high while the other is low.

I looked at the current version of our Dual-VNH5019-Motor-Shield library and unfortunately we are setting PWM=low, INA=high, INB=low when you call setM1Speed(0), so you would get that asymmetric braking behavior. I intend to fix that soon.

However, the setM1Brake() function behaves symmetrically and I would expect setM1Brake(400) to result in hard braking no matter which direction the motor is currently moving.

What behavior are you trying to get?


Hi David,
Thanks for the info.
I think I would like it to coast in both directions, but I am not sure until I build the mechanical part (a window opener).

Tell me about how to use the setM1Brake() function (I am a newbie): Is it used only in
void setup() or do you call it in the main loop of the program? I could not figure out if it is a setting that alters the controller’s wiring semi-permanently until called again, or if its effect evaporates as soon as the sketch ends.

Or if you could paste in a sketch that uses it, that would be great.

Merry Christmas,

Hi, Steve.

I think the best way to explain it would be to make it clear how the motor driver works. Let’s just consider the two outputs of one of the motor channels. When the motor is driving forward, the driver is putting the battery voltage (positive battery terminal) on one of the channel outputs and ground (negative battery terminal) on the other. When the motor is driving in reverse, the driver has flipped these voltages so that the first channel output is ground and the second is the battery voltage. When the motor is braking, the driver is shorting the two motor leads together through ground. When the motor is coasting, the driver is effectively disconnecting the motor leads from the circuit by turning off the outputs. (You can test the brake/coast behavior yourself with just a motor: first take a disconnected motor and try to spin the output shaft by hand; next, pinch the two motor leads so they are connected together and try the spin test again.)

The setM1Speed() and setM1Brake() functions just instantaneously affect what the motor driver outputs are doing, so you call them whenever you need to change the behavior of the driver outputs. Instead of using setM1Speed(0), just call setM1Brake(0).

- Ben

Hey Ben:

Did you guys ever update the code to fix the asymmetric behavior ? Also, how do you unset the brake ? Does setBrakes(0,0) do the trick or will just a setSpeeds(400,400) automatically unset the brakes ? Thanks.

I have confirmed that there is no braking in the forward direction (+400). There is always braking in the backward direction (-400). The setBrakes command certainly has no effect in the forward direction. I am not sure about the backward direction. As far as I can tell the braking action going backwards is the same for setBrakes(400,400) or setBrakes(0,0) ! The same result if you use the individual setBrakeM1 and set BrakeM2 commands.

This is kind of a bummer, but since I only need brakes going forward I am going to reverse the build so that -400 is forward and so at least I get some braking action. But this really needs to be fixed to make the brakes adjustable and useful.


Yes, we have fixed the problem with the VNH5019 library that was discussed in this thread five months ago. That bug didn’t have anything to do with the setBrakes function though, so the issue you are experiencing is probably different.

There is no function to explicitly unset the braking. You should just call the function that corresponds to what you want the motors to do. If you want them to both move at speed 400, then setSpeeds(400, 400) would be appropriate.

I just double-checked the code for the setBrakes/setM1Brake/setM2Brake and do not immediately see a reason that you should get asymmetric behavior from them. I am not sure exactly what problem you are having. Could you please post a complete, minimal Arduino sketch that exhibits the problem, along with a description of how you would expect the system to behave and how it actually behaves? A wiring diagram, some pictures of your setup, and a video of the motor’s behavior would really help.


Thanks. I will download the library and try it. The one on github seems to be old. Is there a version number I need to get and where do I find it ?

- vsingh

Got the library and it works fine, including brakes - Thanks. Pololu is great !

Github stores all past and present versions of the Arduino library. You can see the version number and release date by looking at the README.textile file in the zip file you download. I think I know what might have happened to you. If you clicked the first link I posted in this thread, it would have brought you to this page: … 551727b9de

Note the large hexadecimal number at the end of the URL. That refers to specific, old version of the library. On that page, it says:

If you click the ZIP download button on that page, you will get an old version of the library.

To get the latest version of any of our Arduino libraries, you should remove that stuff from the end of the URL so you can get to a page like this:

Since there is no version number specified in that URL, you will get the latest version. (Actually, the ZIP download button will give you the latest version with a git tag, but that is usually the same thing.) On that page, you can (at the time of this writing) see that the version number is 1.2.1. Another way to get to that page is to just click the name of the repository at the top of the page.