Arduino code and Video for PCA9685 16 channel 12 bits servo controller V1

Project Video
Project Details

This video shows you how to use PCA6985 servo controller module for arduino.

this is the code is V1 to controll one or more servos using PCA6895. Modify it so it is used for your purpose.
This code have a mappting methode so you enter your desired angle and it will convert it to appropriate pulse width. you will use pwm.setPWM(servo_number, 0, angleToPulse(angle) );

replace servo_number with the connector number like 0 ,2, up to 15 and the pulse is the value between 150 to 600 in this example. The angle is the a value between 0 to 180 degrees.

Other Videos on PCA9685

-V1 Video and code on PCA9685 (introduction and calibration)
-V2-1 Video and code on PCA9685 Servo Control ONE-By-ONE
-V2-2 Video and code on PCA9685
-V2-3 Video and code on PCA9685
-V3 Contro 32 Servo Motor with PCA9685 and Arduino
-V4 Video and code on PCA9685 32 Servo with ESP32

Project Code

 * Original sourse:
 * This is the Arduino code PAC6985 16 channel servo controller
 * watch the video for details and demo
 *  * 
 * Watch video for this code: 
 * Related Videos
V5 video of PCA9685 32 Servo with ESP32 with WiFi
V4 video of PCA9685 32 Servo with ESP32 (no WiFi):
V3 video of PCA9685 how to control 32 Servo motors
V2 Video of PCA9685 3 different ways to control Servo motors:
V1 Video introduction to PCA9685 to control 16 Servo

 * Written by Ahmad Shamshiri for Robojax Video channel
 * Date: Dec 16, 2017, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * this code has been downloaded from
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 16 servos, one after the other

  Pick one up today in the adafruit shop!

  These displays use I2C to communicate, 2 pins are required to  
  interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution


// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you 
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  125 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  575 // this is the 'maximum' pulse length count (out of 4096)

// our servo # counter
uint8_t servonum = 0;

void setup() {
  Serial.println("16 channel Servo test!");

  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates


// the code inside loop() has been updated by Robojax
void loop() {

  for( int angle =0; angle<181; angle +=20){
    pwm.setPWM(0, 0, angleToPulse(angle) );


 * angleToPulse(int ang)
 * gets angle in degree and returns the pulse width
 * also prints the value on seial monitor
 * written by Ahmad Nejrabi for Robojax,
int angleToPulse(int ang){
   int pulse = map(ang,0, 180, SERVOMIN,SERVOMAX);// map angle of 0 to 180 to Servo min and Servo max 
   Serial.print("Angle: ");Serial.print(ang);
   Serial.print(" pulse: ");Serial.println(pulse);
   return pulse;