#include <Servo.h>
Servo s1; // Create a servo object to control a servo
void setup() {
s1.attach(9); // Attaches the servo on pin 9 to the servo object
}
void loop() {
// Sweep the servo from 0 degrees to 180 degrees
for (int i = 0; i <= 180; i++) {
s1.write(i); // Tell servo to go to position in variable 'i'
delay(15); // Waits 15ms for the servo to reach the position
}
// Sweep the servo from 180 degrees back to 0 degrees
for (int i = 180; i >= 0; i--) {
s1.write(i); // Tell servo to go to position in variable 'i'
delay(15); // Waits 15ms for the servo to reach the position
}
}