#include <Servo.h>
// Create Servo objects
Servo servo1;
Servo servo2;
Servo servo3;
// Define the pin numbers for the servos
const int servoPin1 = 9; // Connect the first servo to pin 9
const int servoPin2 = 10; // Connect the second servo to pin 10
const int servoPin3 = 11; // Connect the third servo to pin 11
void setup() {
// Attach the servos to their respective pins
servo1.attach(servoPin1);
servo2.attach(servoPin2);
servo3.attach(servoPin3);
}
void loop() {
// Sweep the servos from 0 to 180 degrees and back
for (int angle = 0; angle <= 180; angle++) {
servo1.write(angle);
servo2.write(angle);
servo3.write(angle);
delay(15); // Wait for the servo to reach the position
}
for (int angle = 180; angle >= 0; angle--) {
servo1.write(angle);
servo2.write(angle);
servo3.write(angle);
delay(15); // Wait for the servo to reach the position
}
}