Attaching Servo causes PWM problem

I controlling a GWS Pico Naro Servo motor in a sweeping motion from 0 - 180 degrees and also using PWM on Pin 9 to control a DC motor. The problem I have is that when I call servo.attach(), it causes the PWM to not work. If I comment out the attach statement I a correct multimeter reading off the PWM pin but once I include the statement, there is no PWM and I get a reading of 0V.
Here’s my code:

#include <Servo.h>

Servo servo1;
int servoPosition = 0;
boolean scanIncrement = true; //increase position?
byte servoIncrementValue = 6;
byte servoDecrementValue = 6;

void setup()
pinMode(9, OUTPUT);

void loop()
analogWrite(9, 200);

void scan()
scanIncrement ? servoPosition += servoIncrementValue : servoPosition -= servoDecrementValue; //increment or decrement current position
if (servoPosition >= 180)
scanIncrement = false;
servoPosition = 180;
else if (servoPosition <= 1)
scanIncrement = true;
servoPosition = 1;


Can anyone please explain why this happens and how I can fix it? thanks

Read the second paragraph in the servo reference about pin conflicts between servo library and PWM pins. You need to utilize pins that won't conflict:


Thanks a lot Lefty!

Hi, I´m having a similar problem. However it woudn´t be possible for me to attach the motors to other pins rather than 9 and 10 because I'm using an arduino motor shield wich uses as default pins 9 and 10 for the PWM. Could you give me an idea of how to solve this?


Hi KevinCoder, welcome.

There's external boards available, controllable through I2C (pins A4 and A5 on an Uno). This (click !) is an example, from well appreciated company Adafruit. The appreciation is because they are very generous with all information you might need to get their stuff running.