// Libraries
#include <Servo.h>
// Global Variables
Servo servo;
int rotatePin = A0;
void setup() {
// Attach the potentiometer
pinMode(rotatePin, INPUT);
// Attach the servo
servo.attach(9);
// Start the Serial Monitor
Serial.begin(9600);
}
void loop() {
// Read the rotation of the potentiometer
int rotation = analogRead(rotatePin);
// Convert the value from analog reading to rotation
rotation = map(rotation, 0, 1023, 0, 180);
Serial.println(rotation);
// Rotate the servo
servo.write(rotation);
// Wait a short time, to save power
delay(0.05);
}