#include <Servo.h>
const 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 in 45-degree increments
for (int pos = 0; pos <= 180; pos += 45) {
myServo.write(pos); // Set the servo position
delay(1000); // Wait for 1 second to hold the position
}
// Sweep back from 90 to 0 degrees in 45-degree increments
for (int pos = 180; pos >= 0; pos -= 45) {
myServo.write(pos); // Set the servo position
delay(1000); // Wait for 1 second to hold the position
}
}