Servo Motor

Library

Import Library:

http://mbed.org/projects/cookbook/svn/Servo/trunk

Import Example program:

http://mbed.org/projects/cookbook/svn/Servo/examples/Servo

Hardware

source:/Servo/doc/ServoInterface.png source:/Servo/doc/ServoProduct.jpg

Hello World!

source:/Servo/doc/ServoSchematic.png source:/Servo/doc/ServoPhoto.jpg
Schematic Photo

#include "mbed.h"
#include "Servo.h"

Servo myServo (p21);
int main() {
  int i;
  while (1) {
    for (i=0 ; i<100 ; i++){
      myServo = i/100.0;
      wait (0.01);
    }
    for (i=100 ; i>0 ; i--){
      myServo = i/100.0;
      wait (0.01);
    }
  }
}
Source Code

API

ServoAbstraction on top of PwmOut to control the position of a servo motor
Functions
ServoCreate a servo object connected to the specified PwmOut pin
writeSet the servo position, normalised to it’s full range
readRead the servo motors current position
operator=Shorthand for the write and read functions
class Servo : public Base
Abstraction on top of PwmOut to control the position of a servo motor
Servo(PinName pin,  
const char* =  NULL)
Create a servo object connected to the specified PwmOut pin
void write(float percent)
Set the servo position, normalised to it’s full range
float read()
Read the servo motors current position
Servo& operator= (float percent)
Shorthand for the write and read functions

Theory

A standard R/C servo uses a PWM signal with a 20ms period, and modulates the pulsewidth from 0.5ms to 2.5ms to give the full range of the servo, usually 180 degrees.

The servo requires a higher current than the USB port can safely provide, and so it is essential that you power the servo using an external supply, such as a 4xAA (6v) battery pack.

Resources

Datasheets

PCB Library and Footprint

The Eagle PCB repository can be found at the Eagle page.

The Library for the Servo is