Moving Servos with the PCA9685 Board

Good evening, I am trying to build a robotic arm controllable by keyboard with 6 servomotors, 3 SG90 and the other 3 are MG996R. They are connected to the PCA9685 board and powered by a 5V 1.2A power supply, but when I upload the code, the servos do not move. I thought the problem was that the power supply was insufficient for all 6 servos, but even when trying to power just one servo motor, it does not move. I don't understand if the problem is the power supply or the code. This code should move a servo using keyboard characters. Thank you very much to anyone who can help me.

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

Adafruit_PWMServoDriver servo = Adafruit_PWMServoDriver();

#define SERVOMIN 150
#define SERVOMAX 600

char tasto = '0';

int angBase = 150;  
int angSpalla = 90;
int angGomito = 90;
int angPolso = 90;
int angMano = 90;
int angDita = 90;

// POSIZIONE SERVO
int servoBase = 0;
int servoSpalla = 2;
int servoGomito = 3;
int servoPolso = 4;
int servoMano = 5;
int servoDita = 6;

int angolo;

void setup() {
  Serial.begin(9600);
  servo.begin();
  servo.setPWMFreq(60);
  delay(100);

}

void loop() {
  
  if(Serial.available() > 0) {
    tasto = Serial.read();
    Serial.print(tasto);

    switch(tasto) {
      case 'a':{
        angBase++;
        servo.setPWM(servoBase, 0, angBase);
        delay(10);
      }
      case 'A':{
        angBase--;
        servo.setPWM(servoBase, 0, angBase);
        delay(10);    
      }
 
    }
 }
}

Hi, @blundic
Welcome to the forum.

Thanks for using code tags on your sketch. :+1: :+1:

Your next step would be to add some Serial.print statements to see what you code is receiving on the serial port.

Have you run any of the example codes for the Adafruit library?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Yes, I tried using examples where the code was correct, but it still didn't work. I tried adding some Serial.print statements, for example inside the case blocks, and all of them were visible on the terminal, but the servos didn't move.

Hi, @blundic

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Can you post some images of your project?
So we can see your component layout.

Do you have a DMM? (Digital MultiMeter)

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Connect ONE servo like this:

arduino-with-servo-motors

Use this code to test one servo at a time:

#include <Servo.h> // servo library
int servoPin = 3; // Arduino data pin connected to the servo
Servo servo; // create a sevo object/instance

int deg = 5; // position of servo
int inc = 5; // increment step

void setup() {
  servo.attach(servoPin); // assign the servo object to the Arduino data pin
}

void loop() {
  degreesUsingDelay();
}

void degreesUsingDelay() {
  servo.write(deg);
  delay(20);
  deg = deg + inc ;
  if (deg < 0 || deg > 180)
    inc = -inc;
}

Report your results.

2 Likes

I tried with this code and the connections identical to the design, without going through the PCA9685 board, and it works.
Thank you very much for help me.

1 Like


These are all the connections I made, and they seem correct, but testing it with the code I posted earlier does not work.
Thank you very much.

Don't think so.
red + black from the supply should be connected to the screw terminal.
5volt and ground from the Uno connect to VCC and ground of the PCA9685.
Purple and green are correct.

The supply should be able to deliver 10A (~650mA per SG-90, 2.5A per MG996).
Leo..

Initially, I connected them with the screw, but then the power light on the board didn't turn on, so I thought it wasn't working and that it was broken. Then I connected them to the terminals. I think it's the same thing, but correct me if I'm wrong. I managed to find another power supply that is more powerful, 2A. The problem is that even when connecting just one SG90 servo, it doesn't move. Thank you very much.

I tried powering it through the screws, but the power light on the board doesn't turn on, and while uploading the sketch, I get an error saying stk500_recv() the board is missing or not connected.

I managed to fix it. I was connecting the external power but not powering the Arduino. The code is correct. Thank you very much to everyone who helped me.

1 Like

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