You are not logged in.

#1 2014-08-08 10:57:49

Registered: 2014-07-10
Posts: 8

Servo + knob tutorial

I had a servo sitting, doing nothing and wanted to do something with it!

I grabbed the servo, a 10k potentiometer, some wires and a breadboard.

Here I’m using an Arduino Uno R3 clone with a Motor Shield (same as Adafruit‘s Motor Shield).
The servo is a Parallax standard servo (any digital servo will do).


From 10k Pot to Arduino :
GND (black)    --> GND
Signal (yellow)--> A0
VCC (red)--> 5V

From Servo to Arduino:       
GND (black)--> GND
VCC (red)--> 5V
Signal (white)--> D10
or simply “Servo2” if using the motor shield (Servo2 signal pin = D10)


#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup()
  myservo.attach(10);  // attaches the servo on pin 10 to the servo object

void loop()
  val = analogRead(potpin);            // reads the value of the potentiometer
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo
  myservo.write(val);                  // sets position to the scaled value
  delay(15);                           // waits for the servo to get there

Turn the pot to see the servo moving !


Board footer