/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-servo-motor-controlled-by-potentiometer
*/
#include <Servo.h>
int potpin = A0;
int servopin = 8;
Servo myServo;
void setup() {
Serial.begin(9600);
myServo.attach(servopin);
}
void loop() {
int analogValue = analogRead(potpin);
// scales it to use it with the servo (value between 0 and 180)
int angle = map(analogValue, 0, 1023, 0, 180);
myServo.write(angle);
Serial.print("Analog: ");
Serial.print(analogValue);
Serial.print(", Angle: ");
Serial.println(angle);
delay(100);
}