#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
int potValue = 0; // potentiometer value
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop() {
potValue = analogRead(A0); // get the potentiometer value
pos = map(potValue, 0, 1023, 0, 180); // map the pot value to the 180 degrees for the servo
Serial.println(pos);
myservo.write(pos);
}