#include <Servo.h>
Servo myServo; // Create a servo object to control the servo
void setup() {
myServo.attach(9); // Attach the servo signal pin to D9
Serial.begin(9600);
Serial.println("Servo Test Initialized");
}
void loop() {
// Sweep from 0° to 180°
for (int angle = 0; angle <= 180; angle += 1) {
myServo.write(angle); // Set servo position
delay(15); // Wait for the servo to reach the position
}
// Sweep from 180° back to 0°
for (int angle = 180; angle >= 0; angle -= 1) {
myServo.write(angle);
delay(15);
}
}