Zimbu:
Old thread, but just for the record...I was trying to accomplish the same thing and this simple code seems to work for me. I'm using the little SM-S2309S analog servo that comes standard in most arduino starter kits.
// Include the Servo library
#include <Servo.h>
// Declare the Servo pin
int servoPin = 3;
// Create a servo object
Servo Servo1;
void setup() {
// We need to attach the servo to the used pin number
Servo1.attach(servoPin);
}
void loop(){
// Make servo go to 0 degrees
Servo1.attach(servoPin);
Servo1.write(0);
delay(500); //Not sure why I had to add this short delay here, but without it, the servo doesn't move at all
Servo1.detach();
delay(3000);
// Make servo go to 180 degrees
Servo1.attach(servoPin);
Servo1.write(180);
delay(500); //Not sure why I had to add this short delay here, but without it, the servo doesn't move at all
Servo1.detach();
delay(3000);
}
I haven't tested whether the servo is still drawing power after the Servo1.detach() during the three second pause, but it appears to be totally silent, and I can not feel any vibration at all during that 3 second period. Good enough for me!
This is a method that I ended up using. The reason you need to the 500ms delay is because otherwise the PWM is turned off before the servo can adjust it's position.