Introduction: Interfacing Servo to Arduino Uno

About: My team has developed a new product. PLEASE CHECK IT OUT ON INDIEGOGO AND SHOW YOUR SUPPORT. CAMPAIGN LINK: I'm a tech and food enthusiast and also a Soccer Player. I love…

A Servo Motor is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position feedback. In simple terms it's more like a Stepper Motor which can rotate at angles specified by the user.

Servo Motors come in a variety of sizes, depending on the load they can carry. In this Instructable, I will be going through the basics of connecting a Micro Servo (9g capacity) to an Arduino Uno.

Step 1: Stuff You Need

To get started, you will need:

  • Micro Servo (9g).
  • Arduino Uno.
  • Jumper Wires.

Step 2: A Little About Micro Servo

The Micro Servo is a tiny servo which is about 9g in weight and can carry a load of upto 200g easily. It can found useful in a large number of small projects like Obstacle Follower robot, Automatic Fish food feeder etc. The technical specs of the servo (from adafruit) are as follows :

  • Size : 23x11x29 mm
  • Voltage : 3V to 6V DC
  • Weight: 9g / 0.32oz
  • Speed : 0.12 sec/60 (at 4.8V)
  • Torque : 1.6 kg-cm

If you have a heavier load to carry you can use larger ones.You can use any servo code, hardware or library to control these servos.These MicroServos are good for beginners who want to make stuff move without building a motor controller with feedback & gear box, especially since it will fit in small places.

Step 3: The Connections

Connecting a Servo is quite simple.

  • The Red wire is the Vcc.
  • The Black or Brown is the Ground.
  • The Orange or Yellow one is the Digital Signal Pin.

This can be connected to Arduino without any motor drivers. So directly supply 5V from Arduino to the servo. The Digital signal pin is used to send values of angles to which the servo head has to be rotated.

Step 4: Code

The Arduino IDE has built in examples for testing Servos in two different functions. They are the Knob and Sweep. For this example I'm using testing the servo with the sweep function.

You can also make changes to the code and control the servo with the inputs you give in the Serial Monitor. For this you will need to create a variable that will hold the value of the angle which you enter.

The Sweep code is as follows:


Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

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

void loop() { for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }

Step 5: Uploading and Testing

Once you have the circuit ready, upload the program to the Arduino. If you have any doubts regarding that, do refer my previous Instructable.


  • If you have used the Sweep code, You will see something like in the image above, where the servo head will be rotating in a sweeping fashion.
  • If you want to control the servo manually (Provided you have written the code for it), go ahead and open the serial monitor and enter a value between 0 and 360. You should see the servo head rotate to that angle from reference point.

That's All Folks!!! Stay Tuned for More!!

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017