I can not make my servos work

Hello everybody,

I am using a Arduino UNO R3 and a 16 channel PWM shield. I try to make my MG996R (360 continuous) servo work (in any direction, just some movement) but it doesn’t move whatever I try. Arduino is hooked up to pc and shield has a 5v 3a power connection. Both lights are on for arduino and shield so that shouldnt be a problem. I tried so many different codes and example codes (from the Adafruit PWM drivers) and nothing works. Here is a picture of the board and wiring:

please post the code?

looks like you have a servo. you don't need anything more than a digital output from an UNO. don't power the servo thru the arduino. see Servo Motor Basics

1 Like

Arduino is not a power supply.

1 Like

#include <Adafruit_PWMServoDriver.h>                             //Include the PWM Driver library

Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);    //Create an object of board 1    //Create an object of board 2 (A0 Address Jumper)

int servoMin =  150;        // This is the servos minimum pulse length count (out of 4096)
int servoMax =  600;        // This is the servos maximum pulse length count (out of 4096)
int servoFrequency = 50;    // Servo update frequency, analog servos typically run at ~50 Hz

void setup()
{
  pwm1.begin();             //Start each board
  pwm1.setOscillatorFrequency(27000000);    //Set the PWM oscillator frequency, used for fine calibration
  pwm1.setPWMFreq(servoFrequency);          //Set the servo operating frequency
}

void loop()
{
  for (int i=0 ; i<=3 ; i++)   //Cycle through moving 4 servos on each board
  {
    for (int pulseLength = servoMin ; pulseLength <= servoMax ; pulseLength++)    //Move each servo from servoMin to servoMax
    {
      pwm1.setPWM(i, 0, pulseLength);           //Set the current PWM pulse length on board 1, servo i
      delay(1);
    }
    delay(100);
    for (int pulseLength = servoMax ; pulseLength >= servoMin ; pulseLength--)    ////Move each servo from servoMax to servoMin
    {
      pwm1.setPWM(i, 0, pulseLength);           //Set the current PWM pulse length on board 1, servo i
      delay(1);
    }
    delay(100);
  }
  delay(500);
}

I just have one servo for testing purposes but I plan to connect 10 servos once it works for a 3d printed robot. Any idea on why this doesn’t work for one servo? I’m pretty sure the 996R 360 degree servos are continuous so maybe i need to change the code?

Post a link to the shield, or post it's datasheet here. Hopefully we can get you up and running shortly.

if you looked at that link i posted, there are just 2 functions you need to call to drive a servo. servo.attach (Pinservo) to tell the servo library which pin is used for the servo and servo.write (angle) to move the servo to the specified angle.

a DC motor controller typically use PWM to control the speed.

This is the link to the shield! Thanks for all the quick replies guys.

After you try the link from post #2, try the example code from the library you are using...

1 Like

The 360 servos work diferently. The pulse length actually sets the speed.
1500u is zero speed, 1000u is reverse full and 2000usec is forward

Yes I understand. However, that would mean that with the over mentioned code, the servo would move full speed reverse. But this is not the case as I have not managed to make the servo move at all..

As a test, change the delay(1) to delay (50) in each of your loops, to see if you're simply sweeping the value too quickly.

Tried that and it sadly doesn’t work. What would be a simple code to test a continuous MG996R servo with this PWM board. I tried with this: pwm1.setPWM(0, 1, 2000)

Others will have to advise, I don't use continuous servos - it was just an observation of your code.

The MG996R is NOT continuous.
You need to get the frequency correct otherwise the 50Hz is wrong and the pulsewidths.
Set the frequency to 25000000
servoMin = 205
servoMax = 410

Hi, I changed the settings. Still Zero response from the servo... I can confirm again that I believe that everything is properly connected. It should be very straightforward yet it doesn’t work. I have tried all 4 servos I have so I don’t think that is the issue. Code is now as follows:

#include <Adafruit_PWMServoDriver.h>                             //Include the PWM Driver library

Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);    //Create an object of board 1    //Create an object of board 2 (A0 Address Jumper)

int servoMin =  205;        // This is the servos minimum pulse length count (out of 4096)
int servoMax =  410;        // This is the servos maximum pulse length count (out of 4096)
int servoFrequency = 50;    // Servo update frequency, analog servos typically run at ~50 Hz

void setup()
{
  pwm1.begin();             //Start each board
  pwm1.setOscillatorFrequency(25000000);    //Set the PWM oscillator frequency, used for fine calibration
  pwm1.setPWMFreq(servoFrequency);          //Set the servo operating frequency
}

void loop()
{
  for (int i=0 ; i<=3 ; i++)   //Cycle through moving 4 servos on each board
  {
    for (int pulseLength = servoMin ; pulseLength <= servoMax ; pulseLength++)    //Move each servo from servoMin to servoMax
    {
      pwm1.setPWM(i, 0, pulseLength);           //Set the current PWM pulse length on board 1, servo i
      delay(1);
    }
    delay(100);
    for (int pulseLength = servoMax ; pulseLength >= servoMin ; pulseLength--)    ////Move each servo from servoMax to servoMin
    {
      pwm1.setPWM(i, 0, pulseLength);           //Set the current PWM pulse length on board 1, servo i
      delay(1);
    }
    delay(100);
  }
  delay(500);
}

Also, I have noticed that the VCC light ( VCC - that is the 5V power from the Arduino) is off. If that normal when the servo shield is connected to V+ external power (that light is on)?

Except when it is. I found references to three versions, not sure how they differentiate themsleves but all are MG996R. One does 0 to 180 degrees, one does 0 to 160 degrees and one is continuous rotation.

I saw that it is made by Tower Hobby, which serves the r/c community and wondered if it just a regular servo. This

Working Frequence: 20ms period / 50hz (Digital Control)

makes me think it's just plain servo that can be driven by the servo library.

OK just found it referred to as the MG996R 360. That's a bit dumb for my taste.

a7

void setup()
{
  Serial.begin(9600);
  Serial.print("Setup Started.");  
  pwm1.begin();             //Start each board
  pwm1.setOscillatorFrequency(25000000);    //Set the PWM oscillator frequency, used for fine calibration
  pwm1.setPWMFreq(servoFrequency);          //Set the servo operating frequency
  Serial.print("Setup Finished.");
}

void loop()
{
  Serial.print("Loop active");

I added text prints to check if everything was running well but to my surprise the board prints Setup Started twice. No prints of Setup Finished or Loop Active....
....

Remove the solder blob on VCC!

1 Like

Does it do that if the servo is not connected to the shield?

Does it do that if the shield is not on the Arduino board?

Your sketch is resetting at least and apparently dying. This should not happen and is indicative of a power supply or wiring issue.

The shield should mean no wiring problems, and your first picture shows the shield being fed from an external power supply. What is the voltage and current capacity of that supply?


So you said

the 996R 360 degree servos are continuous

you may have a "MG996R 360" servo. But you right about what that should do. As in not nothing.

@missdrew has better eyes, I did not notice

the solder blob on VCC!

but that blob is actually a jumper select 5 volts for the board, which evidently will run at 3.3 when you need it to.

If you didn't first, please try the servo without the shield. Wire it like a normal servo and use the servo library. Use example code from the IDE. Be sure to supply power to the servo directly, not off the Arduino board. The servo ground should be connected to the Arduino ground.

a7