#include <Servo.h>
Servo myServo; // Create a Servo object to control the servo motor
const int potPin = A0; // Define the potentiometer pin
const int servoPin = 3; // Define the servo motor pin
int potValue = 0; // Variable to store the potentiometer value
int angle = 0; // Variable to store the mapped servo angle
void setup() {
myServo.attach(servoPin); // Attach the servo motor to the defined pin
}
void loop() {
potValue = analogRead(potPin); // Read the potentiometer value (0 to 1023)
angle = map(potValue, 0, 1023, 0, 180); // Map the potentiometer value to an angle (0 to 180)
myServo.write(angle); // Set the servo position
delay(15); // Small delay to stabilize the servo
}