#include <Servo.h>
int servoPin = 5; // Pin for the servo motor
Servo myServo; // Create a Servo object
void setup() {
myServo.attach(servoPin); // Attach the servo to the specified pin
}
void loop() {
// Sweep from 0 to 90 degrees
for (int pos = 0; pos <= 90; pos++) {
myServo.write(pos); // Set the servo position
delay(15); // Wait for the servo to reach the position
}
// Sweep from 90 to 0 degrees
for (int pos = 90; pos >= 0; pos--) {
myServo.write(pos); // Set the servo position
delay(15); // Wait for the servo to reach the position
}
}