Arduino Powered Servo Control - I Made It at TechShop

Servos are incredibly useful in making "things" move. But in order to make that thing move you need to control it somehow. Luckily, arduino makes this incredibly easy to do and can be done with something as a potentiometer. The potentiometer turns and the servo can follow this rotation to it maximim bounds. I made this at TechShop and you can too.

Step 1: Materials

Arduino Uno

Servo (5volt, really any small size will work)

10k ohm potentiometer



usb cable

Step 2: Circuit

This circuit is just about as easy as easy gets with an arduino powering it.

The servo has three wires, Vcc, ground, and data. Connect Vcc to power, ground to ground, and data to pin 3. The data pin is important because it needs to be a pin with PWM or pulse with modulation control. Not all arduino pins have this capability. On the uno they are marked by a " ~ ".

Connect the potentiometer to power and ground. Connect the third leg to analog pin 5. This creates a variable voltage divider for the arduino to read.

Circuit complete.

Step 3: Code

This is the code for the servo to follow the potentiometer

#include <Servo.h>
#define POT_PIN 5
#define SERVO_PIN 3

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

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

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

Run that and Viola! You can now control a servo with a potentiometer. 



    • Organization Contest

      Organization Contest
    • Weaving Challenge

      Weaving Challenge
    • Pie Contest

      Pie Contest

    4 Discussions


    3 years ago

    I tried the same but my services doesn't move properly and its also shaking .what to do?


    4 years ago on Introduction

    that I can do to convert 2 PWM inputs (rc servo) to 5Vdc analog?