Servo center Problems

Hey everyone, I am building a project names animatronic Robot head, and using mg90s servos for movements.
The problem is that when I Centered the servo by connecting it directly to the Arduino, it centered at a position.
But when I connect the servo to PCA9685 servo driver and then try to center it, then it centers at different position. Can anyone help me with that problem. Here are the both codes:

#include <Servo.h>

Servo myServo;  // Create a servo object

void setup() {
  myServo.attach(9);  // Attach the servo to pin 9 (use the pin connected to the servo signal wire)
  myServo.write(90);  // Set servo to center position (90 degrees)
}

void loop() {
  // Nothing to do in the loop for now
}
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// Initialize the PCA9685 using the default address (0x40)
Adafruit_PWMServoDriver pca9685 = Adafruit_PWMServoDriver();

// PWM settings
#define SERVOMIN  150   // Minimum pulse length out of 4096
#define SERVOMAX  600   // Maximum pulse length out of 4096
#define CENTER_PULSE 375 // Center pulse length out of 4096, roughly the middle between SERVOMIN and SERVOMAX

// Set the channel number for the servo you want to center
int servoChannel = 0; // Change this to the actual channel number connected to your servo

void setup() {
  Serial.begin(9600);
  Serial.println("Centering Servo...");

  // Initialize PCA9685
  pca9685.begin();
  pca9685.setPWMFreq(50); // Standard servo frequency

  // Center the servo
  pca9685.setPWM(servoChannel, 0, CENTER_PULSE);

  Serial.println("Servo should be centered.");
}

void loop() {
  // Nothing needed in loop for centering
}


We know.

1 Like

The value for this can range from 40 to 1600. Try 1000?

Adafruit recommend calibrating your servo to their library.

See https://learn.adafruit.com/16-channel-pwm-servo-driver/using-the-adafruit-library for details.

The first code that you posted produces a pulse width of 1.47ms, frequency 50Hz (tested on an Uno R3):

I cannot say what the second code produces, as I don't have the hardware to test.

What value of "SERVOMIN" makes your servo go to 0 degrees?
What value of "SERVOMAX" makes your servo go to 180 degrees?

How can I check?

I need some more guidance if someone want to clear my confusion. Which power source should I use to power servos, I am using 10 to 11 servos including 1 mg996R servo all connected to PCA servo driver. I have 4AA batteries can they run them? Or I also have a power supply of 5v 5a and another power supply of 5v 10a?.
Which power supply I can use

How much of a difference is there between the centered positions of the Uno and the PCA9685 driver?
If it's not much, you might just mechanically adjust the servo horn by seating it on a different position on the output shaft.
Sometimes, "over optimization is the root of all evil".