#include <Servo.h>
Servo myservo;
int potpin = A0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
myservo.attach(9); // attaches servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop() {
val = analogRead(potpin); // read value of the potentiometer (0 to 1023)
val = map(val, 0, 1023, 0, 180); // mapping it together with servo motor
myservo.write(val); // sets servo position according to scaled value
Serial.print("Angle: "); // printing angle
Serial.println(val);
delay(500);
}