Moushira
Published © MIT

In Servo We Trust!

Let's control 135 servos with a single Arduino!

AdvancedFull instructions provided29,470

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Adafruit PCA9865 PWM Servo Driver
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

PWM driver to arduino wiring, image from Adafriut.com

Code

Arduino Code to control 8 Adafruit servo drivers to adjust them to 90 degrees

Arduino
#include "Arduino.h"
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

//numbering works in binary. Check here if you get confused http://www.allspectrum.com/store/all-spectrum-electronics-binary-decimal-hex-reference-card-free-p-8251.html

Adafruit_PWMServoDriver pwm0 = Adafruit_PWMServoDriver(0x40); //in this one you don't solder the board
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x41); //in this one you solder one register.  Check adafruit tutorial for details https://learn.adafruit.com/16-channel-pwm-servo-driver/chaining-drivers
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x42);
Adafruit_PWMServoDriver pwm7 = Adafruit_PWMServoDriver(0x43); 
Adafruit_PWMServoDriver pwm6 = Adafruit_PWMServoDriver(0x44);
Adafruit_PWMServoDriver pwm5 = Adafruit_PWMServoDriver(0x45);
Adafruit_PWMServoDriver pwm4 = Adafruit_PWMServoDriver(0x46);
Adafruit_PWMServoDriver pwm3 = Adafruit_PWMServoDriver(0x47);




int C = 500; //delay variable
int x = 250; //through testing we found pwm 250 to look visiually as 90 degrees



void setup() {



           pwm0.begin();
  pwm0.setPWMFreq(50);    //add frequency based on your motor datasheet, otherwise, do NOT complain of the jitter :)
             pwm1.begin();
  pwm1.setPWMFreq(50);
             pwm2.begin();
  pwm2.setPWMFreq(50);
             pwm3.begin();
  pwm3.setPWMFreq(50);


               pwm4.begin();
  pwm4.setPWMFreq(50);
               pwm5.begin();
  pwm5.setPWMFreq(50);
               pwm6.begin();
  pwm6.setPWMFreq(50);
               pwm7.begin();
  pwm7.setPWMFreq(50);
}

void loop () {
  
 for (int i = 0; i <= 15; i++) {  //according to the driver library i is the number of motors 
      pwm7.setPWM(i, 0, x);
      pwm6.setPWM(i, 0, x);
      pwm5.setPWM(i, 0, x);
      pwm4.setPWM(i, 0, x);
      pwm3.setPWM(i, 0, x);
      pwm2.setPWM(i, 0, x);
      pwm1.setPWM(i, 0, x);
      pwm0.setPWM(i, 0, x);
      delay(50);

  
}

delay (C);
}

Credits

Moushira

Moushira

0 projects • 28 followers

Comments