Using the Adafruit Library

Download the library from Github

Start by downloading the library from - you can just click the button below

Copy the zip file to the Libraries folder inside your Arduino Sketchbook folder and re-name it to Adafruit_PWMServoDriver. For more details on how to install Arduino libraries, check out our detailed tutorial!

Test with the Example Code:

First make sure all copies of the Arduino are closed.

Next open a new copy of the IDE and select "File->Examples->Adafruit_PWMServoDriver->Servo". This will open the example file in an IDE window.

Connect the driver board and servo as shown on the previous page and upload the example code.

You should see the servo sweep back and forth over approximately 180 degrees.

Calibrating your Servos

Servo pulse timing varies between different brands and models.  Since it is an analog control circuit, there is often some variation between samples of the same brand and model.  For precise position control, you will want to calibrate the minumum and maximum pulse-widths in your code to match known positions of the servo.

Find the MInimum:
Using the example code, edit SERVOMIN until the low-point of the sweep reaches the minimum range of travel.  It is best to approach this gradually and stop before the physical limit of travel is reached.

Find the Maximum:
Again using the example code, edit SERVOMAX until the high-point of the sweep reaches the maximum range of travel.  Again, is best to approach this gradually and stop before the physical limit of travel is reached.
Use caution when adjusting SERVOMIN and SERVOMAX. Hitting the physical limits of travel can strip the gears and permanently damage your servo.

Converting from Degrees to Pulse Length

The Arduino "map()" function is an easy way to convert between degrees of rotation and your calibrated SERVOMIN and SERVOMAX pulse lengths.  Assuming a typical servo with 180 degrees of rotation; once you have calibrated SERVOMIN to the 0-degree position and SERVOMAX to the 180 degree position, you can convert any angle between 0 and 180 degrees to the corresponding pulse length with the following line of code:
pulselength = map(degrees, 0, 180, SERVOMIN, SERVOMAX);
Last updated on 2015-05-04 at 04.27.27 PM Published on 2012-10-16 at 05.53.24 PM