#include <Servo.h>
// Create a servo object
Servo myServo;
void setup() {
// Attach the servo on pin 3 to the servo object
myServo.attach(3);
}
void loop() {
// Sweep from 0 to 180 degrees
for (int pos = 0; pos <= 180; pos += 1) {
myServo.write(pos); // Tell servo to go to position in variable 'pos'
delay(15); // Wait 15ms for the servo to reach the position
}
// Sweep back from 180 to 0 degrees
for (int pos = 180; pos >= 0; pos -= 1) {
myServo.write(pos); // Tell servo to go to position in variable 'pos'
delay(15); // Wait 15ms for the servo to reach the position
}
}