Hi!

This is the long overdue second part of the Motor Series. In this post we will discuss Servo motors, which are great motors you want positional accuracy without sacrificing on the high current requirements of a stepper motor.

Introduction

A Servo motor, while very much like a stepper motor(which we will discuss in the next post) are best suited to High speed, high torque applications that involve dynamic load changes.

I will not go into the actual mechanics of how a Servo works as there are people who know a lot more about this subject who have explained it all over the internet.

For the interest of a hobbyist like me, a Servo motor is simply a PWM controlled motor with good positional accuracy and very useful for projects. The one thing to note is that a Servo cannot only rotate 180 degrees which means they cannot be used to drive wheels or other such applications that require full range of motion.

Things Needed

  • A Servo Motor
  • An Arduino
  • The Servo Arduino Library

Wiring it Up

As servos can be directly controlled by most microcontrollers, this setup is going to be very easy. All we need to connect is the VCC and GND pins to 5V and Ground on the Arduino and the SIG pin to any pin on the Arduino.

The Schematic looks like this:

Code

Luckily for most of us, their is great library already available that makes controlling servos a breeze. We use the standard Arduino Servo Library which can control as many as 12 Servos on an Uno board.

For this example, I will just do some basic control.

#include <Servo.h>

Servo myservo;

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

void loop()
{
  moveServoToPostion(10);
  moveServoToPostion(30);
  moveServoToPostion(50);
  moveServoToPostion(70);
  moveServoToPostion(90);
  moveServoToPostion(110);
  moveServoToPostion(90);
  moveServoToPostion(70);
  moveServoToPostion(50);
  moveServoToPostion(30);
  moveServoToPostion(10);
}

void moveServoToPostion(int pos) {
  myservo.write(pos);              // tell servo to go to position in variable 'pos'
  delay(100);   
}

This is very simple code and the most important part of it is the moveServoToPostion function, which takes a positional value in degrees and moves the Servo to that postion.

Usage

Just run the program and you will see the motor sweep from 10 - 110 degrees and back to 10 degrees.

Conclusion

Servos are useful in moving alot of parts on a fixed range of motion. I have used them in the past in Robotic hands, to control steering, and to rotate sensors in the past and they have always performed very well.