// The Servo library ships with the IDE #include // Middle leg of the potentiometer: A0 const int POT_PIN = A0; // The servo's orange (signal) wire const int SERVO_PIN = 9; Servo servo; int lastAngle = -1; void setup() { servo.attach(SERVO_PIN); Serial.begin(9600); } void loop() { // From 0 (one end) to 1023 (the other) int potValue = analogRead(POT_PIN); // Turn 0–1023 into 0–180 degrees int angle = map(potValue, 0, 1023, 0, 180); servo.write(angle); // Write the angle when it changes if (angle != lastAngle) { Serial.print("Angle: "); Serial.println(angle); lastAngle = angle; } // Give the servo time to get there delay(15); }