Trying to get my servo to go in a repetitive movement!

I can’t figure out the code to make my servo start at 0 degrees wait 3 seconds, go to 75 degrees wait 3 seconds, then go to 115 degrees for 2 seconds. I need it to do these actions in that order on a loop. Any suggestions??

The Servo library has example code associated with it - try working through a few examples.

Do you know how to move a servo? Do you know how to delay for a fixed time?

I know how to move a servo from one point to the next, but once I try to add a third point, everything gets a little wonky. I have gotten it to delay, but only with the two points. I know how to do a sweep. Trying to figure out the code by the end of the week. I have already used two classes trying to figure it out. Any suggestions would be super helpful and appreciated.

We can't help with code we can't see.

"Wonky" isn't a useful description of a problem

//  servo
#include <Servo.h>
Servo MyServo;
const byte ServoPin = 4;

void setup()
{
  // start at 0 degrees
  MyServo.write(0);
  MyServo.attach(ServoPin);
}

void loop()
{
  // start at 0 degrees
  MyServo.write(0);

  // wait 3 seconds,
  delay(3000);

  // go to 75 degrees
  MyServo.write(75);

  // wait 3 seconds,
  delay(3000);

  // then go to 115 degrees
  MyServo.write(115);

  // for 2 seconds.
  delay(2000);
}

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