Why do servos move when attached?

I am working on a project that mechanically only allows for the servos to turn about 60 degrees or they will break. When I create a servo and attach it to pin A0, it will move 90 degrees to the right and then to the left and then back to center (like sweeping). I am sure that my code is not doing this, is this part of the Servo library? How can I prevent this?

All that should happen on attach() is that the servo moves to 90 degrees (by default) (note; not moves by 90 degrees, but to 90) and stays there until you command it. The position to which it moves on attach() can be controlled by you, by doing the first write() before the attach().

But why it's doing a sweep-like action is anyone's guess in the absence of you posting the code, and even perhaps a connection diagram.

The Servo library is NOT causing that sweeping. The most it will do is get the servo to move to a position if it is not already at that position. You can do a myServo.write(angle); before you do myServo.attach(servoPin); to pre-set the start position.

Try connecting a 4700 ohm resistor between the servo signal line and GND.

Which reminds me, I presume you have your servo GND connected to your Arduino GND.

...R