This tutorial is part of: Servo Motors
All videos related to servo motors that are related, listed here.
Arduino Code and Video for PCA9685 16-Channel 12-Bit Servo Controller V1
In this tutorial, we will explore how to use the PCA9685 16-channel 12-bit servo controller from NXP Semiconductor. This module allows you to control up to 16 servos or dim a bank of LEDs with precision using pulse width modulation (PWM). By the end of this tutorial, you will have a working setup that can control multiple servos individually or simultaneously.

To clarify the tutorial content further, I encourage you to watch the accompanying video (in video at 00:00) for a visual demonstration of the setup and coding process.
Hardware Explained
The PCA9685 module is a compact board that can control multiple servos via I2C communication. It features 16 channels, allowing you to connect up to 16 servos, each with its own control signal. The module operates at a 5V power supply and is designed to handle PWM signals, which are essential for controlling the position of servos accurately.
The board includes dedicated pins for power (VCC), ground (GND), and communication (SDA and SCL). The SDA pin is used for data transmission, while the SCL pin is the clock signal, both of which connect to the Arduino's analog pins A4 and A5, respectively. This setup ensures reliable communication between the Arduino and the PCA9685 module.
Datasheet Details
| Manufacturer | NXP Semiconductor |
|---|---|
| Part number | PCA9685 |
| Logic/IO voltage | 3.3 V to 5.5 V |
| Supply voltage | 2.3 V to 5.5 V |
| Output current (per channel) | 25 mA max |
| Peak current (per channel) | 100 mA max |
| PWM frequency guidance | 24 Hz to 1.6 kHz |
| Input logic thresholds | 0.3 V (low) / 0.7 V (high) |
| Voltage drop / RDS(on) / saturation | 0.5 V max |
| Thermal limits | -40 °C to 125 °C |
| Package | HTSSOP-28 |
| Notes / variants | 16-channel PWM controller |
- Ensure a 5V power supply with sufficient current (1A recommended).
- Do not power the servos directly from the Arduino to avoid damage.
- Use the correct I2C pins: SDA to A4 and SCL to A5.
- Adjust pulse width values according to your specific servos.
- Check wiring for correct polarity: GND, VCC, and signal.
- Consider heat-sinking for high-current applications.
Wiring Instructions

To wire the PCA9685 to your Arduino, start by connecting the power and ground. Connect the VCC pin on the PCA9685 to the 5V output on the Arduino. Then connect the GND pin on the PCA9685 to the GND on the Arduino. Next, connect the SDA pin on the PCA9685 to pin A4 on the Arduino, and the SCL pin to pin A5.
For the servos, connect the signal wire to the corresponding channel on the PCA9685 (e.g., CH0 for the first servo), the power wire to a separate power supply (as the servos may require more current than the Arduino can provide), and the ground wire to the common ground shared with the PCA9685. Make sure that the signal, power, and ground wires are correctly aligned to avoid damaging your components.
Code Examples & Walkthrough
In the setup section of the code, we initialize the PCA9685 module with pwm.begin() and set the PWM frequency with pwm.setPWMFreq(60);. This sets the communication frequency for the servos.
void setup() {
Serial.begin(9600);
Serial.println("16 channel Servo test!");
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
}
Within the loop, we control the servos by setting the PWM values corresponding to the desired angles. The function angleToPulse(int ang) maps the angle to the appropriate pulse width, which is essential for accurate servo positioning.
void loop() {
for( int angle =0; angle<181; angle +=20){
delay(500);
pwm.setPWM(0, 0, angleToPulse(angle) );
}
}
Finally, the function angleToPulse(int ang) converts the angle to pulse width using the defined minimum and maximum pulse lengths. This allows you to easily control the servo's position based on the angle you want to achieve.
int angleToPulse(int ang){
int pulse = map(ang,0, 180, SERVOMIN,SERVOMAX);
Serial.print("Angle: ");Serial.print(ang);
Serial.print(" pulse: ");Serial.println(pulse);
return pulse;
}
Demonstration / What to Expect
Once everything is wired correctly and the code is uploaded, you should see the servo moving through the specified angles in increments of 20 degrees. If the servo does not behave as expected, check the wiring for correct connections and ensure that the power supply is adequate (in video at 12:30).
Video Timestamps
- 00:00 - Introduction to PCA9685
- 02:30 - Wiring instructions
- 05:00 - Code walkthrough
- 10:15 - Demonstration of servo control
- 12:30 - Troubleshooting common issues
This tutorial is part of: Servo Motors
- Controlling a Servo with Push Buttons Using Arduino
- Control a Servo Motor with a Push Button: Move Servo and Return SPB-1
- Control a Servo Motor with a Push Button: Move Servo in One Direction SPB-2
- Controlling a Servo Motor with a Push Button: Move Servo While Button Is Pressed (SPB-3)
- Controlling a Servo with a Potentiometer Using Arduino
- Controlling a Servo with Potentiometer and LCD1602 using Arduino
- Controlling Servo Motors Using an Infrared Remote with Arduino
- Arduino Servo Motor Control Using a Potentiometer
- Controlling Servo Position with Hand Gestures for Arduino
- Controlling Two or More Servos with Potentiometers Using an Arduino
- How to Control a 360° Servo with Three Push-Button Switches
- How to Use Continuous 360° Servo with Arduino
- Build an Arduino Servo Toggle Switch with a Push Button
Resources & references
No resources yet.
Files📁
No files available.