Servos are not running on this code

I have tried so many different ways to connect these three servos to the PCA9685 board... I just don't know what I am missing my servos just will not run. I get no error messages in my code.

Below is the code I've used:

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

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); // Initiates library.

#define SERVOMIN 250 // 1000 microsecond Minimum pulse length count out of 4096.
#define SERVOMAX 500 // 2000 microsecond Maximum pulse length count out of 4096.

int servoNo = 0; // Defines a counter for servos.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //Starts serial connection at 9600 baud rate.

  pwm.begin(); //Sends PWM signals.
  pwm.setPWMFreq(60); // Sends PWM signals.
  delay(20);

}

void loop() {
  // put your main code here, to run repeatedly:
for (int pulselen = SERVOMIN; pulselen <SERVOMAX; pulselen++) // Drives each servo one at a time first
  pwm.setPWM(servoNo, 0, pulselen); //to maximum pulse length then to minimum pulse length.
delay(300);

for (int pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--)
  pwm.setPWM(servoNo, 0, pulselen);
delay(300);

servoNo ++; //Proceeds to next servo.
if (servoNo > 3) servoNo = 0;


}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

What's the 5V source for the servos?

Welcome to the forum.

If you put your sketch between code-tags on this forum, then we can read it. You may also type three backslash single quotes.

```
Your sketch
```

In the Arduino IDE is a auto-format. It is in the menu or press Ctrl+T.
If you do that, and then make it look even better, then the code is easier to read. Put every indent, every comma, every new line at the right place.
You do that for yourself, it helps to spot bugs.

Have you tried a Servo motor without the Adafruit PWM module ?
The Servo library is in the Library Manager of the Arduino IDE

You're telling the PWM board to send the 4096 steps 60 times per second. That's 245760 steps per second or a little over 4 microseconds per step.

A typical servo pulse is 500 to 2500 microseconds long. That would be 125 to 625 steps per pulse. Your 100 to 2200 step limits are way beyond what servos can typically handle.

Try:

#define SERVOMIN 250 // 1000 microsecond Minimum pulse length count out of 4096.
#define SERVOMAX 500 // 2000 microsecond Maximum pulse length count out of 4096.
2 Likes

Good day I've tested the servos individually, and they work just fine.

even with the change in the code, they still do not run. I do not understand what I could be missing.

Thank you
Denise

For the 5V source, I've connected a 9V battery.

5V does not equal 9V

Using a


for 9V?

For servos you need a 4.8-6V power supply, capable of providing at least 1 Ampere per small servo, 2.5 A/servo for larger ones like the MG996R.

A 4xAA battery pack will work for 1 or 2 SG90 servos. Don't forget to connect all the grounds.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.