Source: https://mokxi.com/libraries/adafruit-pwmservodriver
Updated: 2026-11-02

Libraries / Motion
Arduino library · Motion

# Adafruit PWM Servo Driver: sixteen servos from one PCA9685

The PCA9685 is a 16-channel, 12-bit PWM chip on I2C, sold on the blue Adafruit breakout and countless copies. The Adafruit PWM Servo Driver library talks to it, so two Arduino pins (SDA and SCL) can hold sixteen servos or dim sixteen LEDs, and the board keeps every pulse going on its own while the sketch does something else.

Open the example in the editor See the calls

Built in on Mokxi: #include <Adafruit_PWMServoDriver.h> and it builds, with nothing to install. Free, and no account needed.

## What Adafruit PWM Servo Driver Library does

Each channel counts 0 to 4095 through one PWM period. For servos you set the frequency to 50 Hz, which makes a period 20 ms, so one count is about 4.9 microseconds and a 1.5 ms center pulse is about 307 counts. Tutorials call the end points SERVOMIN and SERVOMAX (often 150 and 600) and tune them for each servo.

The chip’s internal oscillator is nominally 25 MHz but real ones run a few percent off, which is why widths can come out slightly wrong. setOscillatorFrequency() lets you correct it once you have measured a board. Servo power goes into the board’s separate V+ terminal, never through the Arduino.

Library Manager name | Adafruit PWM Servo Driver Library

Author | Adafruit

Include | #include <Adafruit_PWMServoDriver.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Servo driver, PCA9685 16-channel

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <Adafruit_PWMServoDriver.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "Adafruit PWM Servo Driver Library" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit PWM Servo Driver Library to lib_deps in PlatformIO. Mokxi follows the calls of release 3.0.2, so a sketch written here builds there too.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

A board at the default address 0x40. Pass another address, such as Adafruit_PWMServoDriver(0x41), for a second board with A0 bridged.

### pwm.begin()

Starts I2C, wakes the chip from sleep and sets the default 1000 Hz frequency.

### pwm.setOscillatorFrequency(27000000)

Tells the library what the chip’s oscillator really runs at, so writeMicroseconds() and the frame period come out right on that board.

### pwm.setPWMFreq(50)

Sets the PWM frequency for all sixteen channels at once: 50 Hz for analog servos, up to about 1600 Hz for LEDs.

### pwm.setPWM(channel, 0, pulse)

Sets when channel 0 to 15 turns on and off within the 4096-count period. On at 0 and off at the pulse length is how servo sketches use it.

### pwm.writeMicroseconds(1, 1500)

Sets a channel by pulse width instead of counts, worked out from the frequency and oscillator setting.

### pwm.setPin(15, 2048)

A duty cycle from 0 to 4095 on one pin, the call for dimming an LED.

### pwm.sleep()

Stops the oscillator and every output; wakeup() starts them again.

## Example: Pick and place arm on a PCA9685

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

Open it in the editor, wired and ready to run · Pick and place arm on a PCA9685: the project page

## Common errors and how to fix them

### The servos do not move but the board’s LED is on

The servos need power on the V+ screw terminal (5 to 6 V from a supply that can deliver an amp or more). The VCC pin only powers the chip’s logic, not the servos.

### Servos buzz at the ends or travel less than 180 degrees

SERVOMIN and SERVOMAX do not match your servo. Change them a few counts at a time until each end is reached without straining, or use writeMicroseconds() with widths from the servo’s data sheet.

### Nothing responds, and an I2C scanner finds no 0x40

Check SDA and SCL go to the board’s I2C pins, that VCC has 3.3 or 5 V, and that the address jumpers are as you expect. A board with A0 bridged answers at 0x41.

## Projects that use Adafruit PWM Servo Driver Library

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Arduino quadruped robot Eight servos on a PCA9685 walk a four-legged robot through a creep gait: one foot lifts and swings forward at a time while the other three hold it up.

## Keep going

### Learn

- Arduino PCA9685 Servo Driver: Wiring and Code
- I2C Scanner for Arduino and ESP32, and Fixes

### Parts

- Servo driver, PCA9685 16-channel

### More motion libraries

- Servo
- Stepper
- AccelStepper
- L298N
- Adafruit Motor Shield V2 Library

Every built-in library · Open the editor

## Try Adafruit PWM Servo Driver Library without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
