#include <Servo.h> // Include the Servo library
const int servoPin = 10; // Pin where the servo signal is connected
Servo myServo; // Create a Servo object
void setup() {
myServo.attach(servoPin); // Attach the servo to the pin
}
void loop() {
// Sweep the servo from 0 to 180 degrees
for (int angle = 0; angle <= 180; angle++) {
myServo.write(angle); // Set the servo position
delay(15); // Wait for the servo to reach the position
}
// Sweep the servo from 180 to 0 degrees
for (int angle = 180; angle >= 0; angle--) {
myServo.write(angle); // Set the servo position
delay(15); // Wait for the servo to reach the position
}
}