The servo motor don't work

Hi friends ,I have made a project consisting of a PCA9685 module and 5 servo motors, the board used a UNO board,but when i use 3 servo motors,it could activate well,but when i add to 5 servo motors,they don't work,the external power supply ,i use 7.4V and 1A power supply ,the servo motor is MG996R servo,here are the code and Wiring diagram

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

// 定义PCA9685的地址,默认为0x40
#define PCA9685_ADDRESS 0x40

// 定义伺服电机脉冲宽度范围
#define SERVOMIN  150 // 最小脉冲宽度计数(对应0度)
#define SERVOMAX  600 // 最大脉冲宽度计数(对应180度)
#define SERVO_CENTER ((SERVOMAX - SERVOMIN)/2 +SERVOMIN) // 中心位置脉冲宽度计数(对应90度)


// 定义伺服电机通道
#define SERVO_CHANNEL_1 0
#define SERVO_CHANNEL_2 1
#define SERVO_CHANNEL_3 2
#define SERVO_CHANNEL_4 3
#define SERVO_CHANNEL_5 4


int SERVO1;
int SERVO2;
int SERVO3;
int SERVO4;
int SERVO5;
int TURN=1;
int a=SERVO_CENTER;
int b=SERVO_CENTER;
int c=SERVO_CENTER;
int d=SERVO_CENTER;
int e=600;

// 初始化PCA9685对象
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

// Arduino pin numbers
const int SW_1 = 7; // digital pin connected to switch output
const int X_1 = A0; // analog pin connected to X output
const int Y_1 = A1; // analog pin connected to Y output
const int SW_2 = 6; // digital pin connected to switch output
const int X_2 = A2; // analog pin connected to X output
const int Y_2 = A3; // analog pin connected to Y output


int a_1=0;
int b_1=0;
int digitalSW1=0;
int a_2=0;
int b_2=0;
int digitalSW2=0;

void setup() {
  // 初始化PCA9685
  pwm.begin();
  Serial.begin(9600);

  pinMode(SW_1, INPUT);
  digitalWrite(SW_1, HIGH);
  pinMode(SW_2, INPUT);
  digitalWrite(SW_2, HIGH);

  pwm.setOscillatorFrequency(27000000);
  pwm.setPWMFreq(20); // 设置PWM频率为50Hz

  // 将所有伺服电机设置到90度位置
  pwm.setPWM(SERVO_CHANNEL_1, 0, SERVO_CENTER);
  pwm.setPWM(SERVO_CHANNEL_2, 0, SERVO_CENTER);
  pwm.setPWM(SERVO_CHANNEL_3, 0, SERVO_CENTER);
  pwm.setPWM(SERVO_CHANNEL_4, 0, SERVO_CENTER);
  pwm.setPWM(SERVO_CHANNEL_5, 0, SERVO_CENTER);

}

void loop() {
  a_1=analogRead(X_1);
  b_1=analogRead(Y_1);
  digitalSW1=!digitalRead(SW_1);
  a_2=analogRead(X_2);
  b_2=analogRead(Y_2);
  digitalSW2=digitalRead(SW_2);

  rebuild();
  motor();

  Serial.print("a");
  Serial.print(a);
  Serial.print(" ; ");
  Serial.print("b");
  Serial.print(b);
  Serial.print(" ; ");
  Serial.print("c");
  Serial.print(c);
  Serial.print(" ; ");
  Serial.print("d");
  Serial.print(d);
  Serial.print(" ; ");
  Serial.print("e");
  Serial.println(e);
 



 


  
}

void motor(){
  SERVO1=a;
  SERVO2=b;
  SERVO3=c;
  SERVO4=d;
  SERVO5=e;
    // 将所有伺服电机设置到90度位置
  pwm.setPWM(SERVO_CHANNEL_1, 0, SERVO1);
  pwm.setPWM(SERVO_CHANNEL_2, 0, SERVO2);
  pwm.setPWM(SERVO_CHANNEL_3, 0, SERVO3);
  pwm.setPWM(SERVO_CHANNEL_4, 0, SERVO4);
  pwm.setPWM(SERVO_CHANNEL_5, 0, SERVO5);
}

void rebuild(){
  //tern left
  if(a_1>1000&&b_1>400&&b_1<600){
    a=a+20;
    a=min(a,480);


  }
  //turn right
  if(a_1<100&&b_1>400&&b_1<600){
    a=a-20;
    a=max(260,a);

  }
  //1st big arm turn down
  if(b_1<100&&a_1>500&&a_1<600){
    c=c+20;
    c=min(475,c);


  }
  //1st big arm turn up
  if(b_1>1000&&a_1>500&&a_1<600){
    c=c-20;
    c=max(c,195);

  }
  //2nd forearm turn up
  if(b_2<100&&a_1>500&&a_1<600){
    b=b+20;
    b=min(480,b);


  }
  //2nd forearm turn down
  if(b_2>1000&&a_2>500&&a_2<600){
    b=b-20;
    b=max(b,170);

  }
  if(a_2>1000&&b_2>400&&b_2<600){
    d=d+20;
    d=min(d,480);


  }
  //turn right
  if(a_2<100&&b_2>400&&b_2<600){
    d=d-20;
    d=max(260,d);

  }


  e=600-375*digitalSW1;
  

}

and i also use two 2-Axis module to control the 5 motor

For 5xMG996R servos, a power supply delivering 4.8 to 6V at 12 Amperes minimum is required.

Each MG996R servo briefly draws 2.5 Amperes, every time it starts moving.

and there is another problem.when i try this project ,the motor always shake ,why did it happen,and when it rotate,it couldn't rotate smoothly ,it just like move bit by bit ,sometime it would also rotate significantly at the wrong angle ,but this is not under my control

Did you ignore post #2?
You do not have motors in your drawing. Servos?

Because your power supply is useless. Read post #2.

sorry i already change the external power supply to 6V lithium battery ,in this way i shouldn't worry about the problem of the electric current .but it also shake,and i believe the reason why it would rotate at a wrong angle is the programming problem

That is almost always due to a power supply problem.

Good luck with your project.

alright ,thank you ,

  • Disconnect all but 1 servo, how does that servo work ?

  • Try 2 then 3 then 4 . . .

  • When volunteers make recommendations, you should follow those recommendations.

No such a thing as a 6v lithium.
Not possible to run servos via the Arduino
5v regulator.
Best you supply an updated circuit diagram (no fritzing) mark all connections and power supplies.

SW_1 & SW_2 are inputs so you're supposed to read them, not to write them. If you want the pull-up resistors to be active, use

  pinMode(SW_1, INPUT_PULLUP);
  pinMode(SW_2, INPUT_PULLUP);

instead.

Next:

PWM Frequecy should be 50Hz, use

pwm.setPWMFreq(50); // 设置PWM频率为50Hz` <- 50 instead of 20 here !!!

and adjust SERVOMIN & SERVOMAX as well as any servo position if needed.

Next:

Use

int e = SERVOMAX;

to be consistent.

Next:

Copy-Paste typo here, should be

  //2nd forearm turn up
  if (b_2 < 100 && b_1 > 500 && b_1 < 600) { // <- b_1, not a_1 !!!
    b = b + 20;
    b = min(480,b);
  }

Next:

Some if test against 400, others against 500. You should test all against 400 (mid joystick value being 512)
Besides, you should use meaningful names instead of a_1, something like joystick_1_X or even joystick[0].x if you know arrays and structures.
You don't need a , b, c, d and e, use SERVO1... SERVO5 directly and rename them with lowercase letters servo_1_Pos or servoPosition[0] with arrays.

Next:

I'm not surprised, variable a, which controls servo_1, will vary from 260 to 480 with steps of 20.

That's only 11 steps or 12 possible positions. As there's no delay() in the loop(), the servo will move from end to end in a blink... Lower this value of 20 down to or close to 1.
Same with b, c, and d...