Digital pin output problems

Hello, I have a very weird problem which, after a lot of cutting bits of code out of a larger program, I have simplified down to the following code:

#include <Servo.h>

byte servoPin = 6;

Servo s;

void setup() {

void loop() {
analogWrite(motorPin, 255);

Now, the “motorPin” (named so because originally going to control a solid state relay for controlling a DC motor) is attached to an LED to check if it comes on or not.

Now, guess what, with the code as shown above, the LED turns on, no surprises there. With the:


line uncommented however, the LED stays off :o

What is going on here? I have tried changing the pin numbers (moved motorPin from 9 to 10) but doesn’t solve the problem. The offending line is the servo attachment to its pin.

Maybe try adding pinMode(motorPin, OUTPUT); in your setup?

If the LED stays off, it may mean the code isn't getting to your loop. Is it possible to move the motor pin to a digital pin?

A comment in Servo.cpp:

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

So, this is expected behavior. Perhaps not desired, but expected.

Right, bummer but I get it now. Thanks.

P.S. solved by moving motorPin to pin 11 (leaving servo on pin 5) on Duemilanove board.