Try the two examples in File/Examples/Servo/Knob and Sweep.
If your servo is drawing too much power it might make your Arduino board unstable and the servo may behave erratically. In those cases, you should use an external power source as well, and also try to put a capacitor as explained in this page.