Dual VNH5019 Motor Driver Shield interfering with servos?

I am really enjoying the Dual VNH5019 Motor Driver Shield and appreciate its useful user’s guide. I have noticed that when I use the shield (with an Arduino Uno) and it’s library, that I’m not able to use servos (using the Arduino servo library) once the motor shield init() is done. My servos are using digital pwm pins not used by the motor shield, such as 11 and 3.

I’m wondering if this happens because the Motor Shield library does things to affect the timer so that it can be ultra sonic. Is anyone else having these issues? Are there certain pins I should be using that wouldn’t be affected? Or is there a way to disable the timer modifications or in some other way use the servo library together with the motor shield library?


The servo library on a mega328 based Arduino uses timer1. The VNH5019 MDShield uses analogWrite on pins 9 and 10, which relies on timer1.

Whichever constructor is called last will probably function properly. So if you initiate the motor driver shield before the servos, the servos will work, and vis-versa.

If you use a different two PWM pins for the motor driver shield you should be fine. All of the other PWM pins use different timers. On the other hand, if you were able to make the servo library use a different timer, you would also be fine. The first option is much easier in my opinion. The shield has points to cut the two traces, and you can wire them up to pins 11 and 3.

The standard servo library does not need the servos to be attached to PWM pins. It does it’s magic in software.

Thank you for the excellent advice. Based on your answer, I started searching for alternate servo libraries that use a different timer. I found one called ServoTimer2, which as you might expect, uses timer two.

Information on this library is available here:
arduino.cc/cgi-bin/yabb2/YaB … 1230479947

Using this instead of the native servo library, I was able to attach servos to pins 3 and 11, leave the motor shield in “stock” condition, and both are getting along fabulously now.

Thanks much!

If you want to use the Dual VNH5019 Motor Driver Shield with the standard analogWrite on ATmega328-based Arduinos, losing ultrasonic PWM but gaining normal functioning of Timer 1, you can delete the branches in DualVNH5019MotorShield.cpp that begin with

#if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__)

- Ryan

I’m pretty sure that will not solve the problem Ryan, because the servo library overwrites normal operation of Timer1.

Glad you got it working msmith!

Hi Mike,
I was trying to following your method and used the servo timer 2 library but it wouldn’t compile on my Arduino Uno board and showed messages such as xxx.h not found in directory. I was wondering what board do you use and If you have modified/updated the servo timer 2 library. It seems to me that the servo timer 2 library was created years ago and some of the functions and libraries may have slightly different names now. Thank you so much!!!