/* Use a potentiometer(ajustable resistor) to control servo position * Copyright John Yu * detail project see http://osoyoo.com/?p=172 */ #include Servo servo_obj; // create servo object to control a servo int control_put = 0; // define A0 port to receive control signal from potentiometer int position; // variable to read the value from the analog pin void setup() { servo_obj.attach(7); // attaches the servo on pin 7 to the servo object } void loop() { position = map(analogRead(control_put), 0, 1023, 0, 179); //get input signal from A0,convert it into angle value servo_obj.write(position); // sets the servo position according to the scaled value delay(25); }