#include <Servo.h>
Servo myServo; // Create a Servo object
void setup() {
myServo.attach(9); // Attach the servo control to digital pin 9
}
void loop() {
// Sweep from 0 to 180 degrees
for (int pos = 0; pos <= 180; pos += 1) { // from 0 to 180 degrees
myServo.write(pos); // Set the servo position
delay(15); // Wait for the servo to reach the position
}
// Sweep from 180 to 0 degrees
for (int pos = 180; pos >= 0; pos -= 1) { // from 180 to 0 degrees
myServo.write(pos); // Set the servo position
delay(15); // Wait for the servo to reach the position
}
}