What is it?
A servo motor is really a three-in-one deal. It is either an AC or DC motor, reduction gearing and miniaturised control electronics rolled into one solid, compact and versatile motor. Its main distinguishing feature is that it isn’t meant for continuous rotation. Instead, the motor receives a signal instructing which angle position it takes. It turns as instructed and holds its place, resisting any external forces that try to push it back so long as it is receiving the signal.
What should I use it for?
Servo motors are very useful when you need a motor to hold a position. You can map input from an analog sensor, such as a potentiometer or photocell. Because of its small size and simple wiring, it can be used in a variety of different situations and can be powered by the arduino or mbed on its own.
Ex: animatronics(blinking eyes), drawing machines, steering a small car
Here’s a really great example of a creative application of servos:
Servo motors are very easy to use with the Arduino because it has a built-in library. It can be included by going Sketch > Import Library > Servo. Here is a code example of a servo mapped to a potentiometer in Arduino:
//include the servo library for the servo motor
#include
//initialise your servo
Servo myServo;
//analog pin for the potentiometer
int potPin = A0;
//will be the angular value for the motor
int val;
void setup()
{
//begin Seial communication
Serial.begin(9600);
//set the pin for the motor communication
myServo.attach(3);
potPin.pinMode(INPUT);
}
void loop()
{
//get value from the potentiometer
val = analogRead(potPin);
//map it to the servo's range, typically 180 degrees, so a number between 0 and 179 to have 180 values.
val = map(val,0,1023,0, 179);
//send the value to the motor to give it instruction
myServo.write(val);
//uncomment this to see the value being sent to the motor
//Serial.println(val);
//small delay to make sure everything runs smoothly.
delay(15);
}