Well, this is interesting, because I'm a newby too, and I've just bought the Arduino experimenters kit, and using the servo supplied with the kit I've wired up the power from the Arduino board and I'm getting very odd behaviour.
Sometimes it works, other times it doesn't and sometimes the servo seems to spin internally, without the arm actually moving.
The code is simple (I hope), it's just intended to rotate the servo 5 degrees every 5 seconds. Have I done anything wrong or is it all down to the power supply ?
//////////////////////////////////////////////////////////////////////
// Turns a servo motor dependant on an analog value
// A value of 0-255 gets written to the output pin
// This represents a duty cycle of 0%-100%
// This is translated as a rotation of 0-180 degress of the servo
//////////////////////////////////////////////////////////////////////
int outputPin = 11;
float fanalogValue ;
int analogValue ;
int degreeRotation=0 ; // the nomber of degrees we want the servo to rotate
void setup()
{
pinMode(outputPin,OUTPUT);
Serial.begin(38400);
}
void loop()
{
if (degreeRotation <= 180 && degreeRotation >= 0) // can't rotate more than 180 or less than 0
{
fanalogValue = degreeRotation/180.0*255.0 ;
analogValue = fanalogValue;
Serial.print("Analog Value:");
Serial.println(analogValue,DEC);
analogWrite(outputPin,analogValue);
degreeRotation += 5;
delay(5000);
}
else {degreeRotation = 0;}
}