Controlling a servo position using a slider (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

Demostrates how to control a servo's position using a slider potentiomenter (variable resistor) connected to an analog pin

Created 10 March 2004
Revised 30 August 2007
 

   
// Controlling a servo position using a slider (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
int sliderpin = 0;  // analog pin used to connect the slider 
int sliderValue;    // variable to read the value from the analog pin 
 
void setup() 
{ 
  myservo.attach(0);  // attaches the servo on pin 0 to the servo object 
} 
 
void loop() 
{ 
  sliderValue = analogRead(sliderpin);  // reads the value of the slider (value between 0 and 1024) 
  sliderValue = sliderValue/5.68;       // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(sliderValue);           // sets the servo position according to the scaled value 
  delay(15);                            // waits for the servo to get there 
} 
           
     
           
           
           
     
           
           
           
         
           
           
    Circuit schematics: the servo signal pin is connected to Wiring digital pin 0. The potentiometer is connected to Wiring analog input pin 0.