Is it possible to set a servo to start at 180 rather than 0?

I have a servo and whenever I start my code it jumps to 0 immediately. Is there any way to make it go to 180 instead? If there isn't I'll just live with it.
I've tried these things.

#include <Servo.h>

Servo servo;

void setup() {
  servo.attach(9);
  servo.write(180);
}

void loop() {
}
#include <Servo.h>

Servo servo;

void setup() {
  servo.write(180);
  servo.attach(9);
}

void loop() {
}

That should move the servo to 180 as soon as it is attached. A servo attached to my Uno does.
What is your servo doing?

Spinning to 0 immediately and then after a bit going to 180.
Must just be my servo

Try this code. I have tested it on my Uno with a little servo. It moves to 180 at boot and pauses there for 3 seconds before starting the sweep example on my set up. Mind the servo pin number.


#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.write(180);
  myservo.attach(4);  // attaches the servo on pin 9 to the servo object
  delay(3000);
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.