Problem using both a dc motor and servo

analogWrite() works by sending a PWM sequence to the selected pin.

In servo.h you can find the following:


A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. The servos are pulsed in the background using the value most recently written using the write() method.

Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached.


It looks like the selected pin for your servo affects the pins you are using for analogWrite. You should be able to fix the problem by choosing different pins.

1 Like