#include <Servo.h> // Include the servo library
Servo myServo; // create a servp object to control servo
int servoPin = 9; // servo motor is connected to pin 9
int potPin = A0; // potentiometer is connected to A0
int potentiometerValue; // variable to store potentiometer reading
int servoPosition; // This will store an angle for the servo arm
void setup() {
myServo.attach(servoPin); // Attach the servo motor to pin 9
Serial.begin(9600);
}
void loop() {
potentiometerValue = analogRead(potPin);
//read the value from the potetiometer (0-1023)
servoPosition = map(potentiometerValue, 0, 1023, 0, 100);
// This changes the 0-1023 reading to a 0-100 degree scale
myServo.write(servoPosition); // Move the servo arm to the calculated position
Serial.print(potentiometerValue);
Serial.print(" ");
Serial.print(servoPosition);
delay(100);
}