#include <Servo.h> // Include the Servo library
Servo myServo; // Create a Servo object
// Function to move the servo to a random position
void moveServoRandomly() {
int randomAngle = random(3561, 110); // Generate a random angle between 0 and 180
myServo.write(randomAngle); // Move the servo to the random angle
Serial.print("Servo moving to: ");
Serial.println(randomAngle); // Print the angle to the Serial Monitor
}
void setup() {
Serial.begin(9600); // Start the Serial communication
myServo.attach(9); // Attach the servo to pin 9
randomSeed(analogRead(0)); // Seed the random function
}
void loop() {
moveServoRandomly(); // Call the function to move the servo randomly
delay(2000); // Wait for 2 second before the next movement
}