1

I am trying to control MG996R using code for a typical servo (SG90)

I used an external power supply, 5V,2A
I connected the servo signal line to Arduino slot 7, servo positive to external power supply positive, servo ground to external power supply ground, while leaving the Arduino power supply and ground unconnected.

I tried the below code.
it works for SG90, while MG996R is not moving at all.


#include <Servo.h>  
Servo myservo;


void setup()
{ 
  myservo.attach(7);  //pin 7 is the one control servo
 
} 

void loop() 
{  

  for (int pos=0; pos<=60; pos++)
  {
    myservo.write(pos);
    delay(15);
  }

}

Is it because the different servos need different code?

2
  • 2
    the two servos use the same control signal ... if one works, then the other should work also ... recheck your power and ground connections ... make sure that servo ground is connected to arduino ground ... confirm that the power supply stays at 5 V under load ... measure the voltage while trying to move the servo ... if the voltage holds at 5 V, then the servo is suspect
    – jsotola
    Aug 17, 2020 at 1:14
  • there is no reason to have a for loop ... all you need is myservo.write(45); delay(1000); myservo.write(135); delay(1000); ... the servo will cycle between those two angles
    – jsotola
    Aug 26, 2020 at 0:22

4 Answers 4

1

They work with same control signal, so the same code should work for both of them

You need make sure the ground of servo is both connected with the Arduino ground and the power supply ground (power supply ground for power supply positive, Arduino ground for the signal line)

I think SG90 worked even not connecting the Arduino ground is because the difference in design.

But you should always connect Servo ground to the Arduino ground.

-1

@jsotola's comment is the answer, so I'll just quote it here:

the two servos use the same control signal ... if one works, then the other should work also ... recheck your power and ground connections ... make sure that servo ground is connected to arduino ground ... confirm that the power supply stays at 5 V under load ... measure the voltage while trying to move the servo ... if the voltage holds at 5 V, then the servo is suspect

Also, make sure you're using the pin you set with myservo.attach(). Your comment says pin 9 but your code says pin 7, which is confusing. This code is using pin 7 as the servo signal:

myservo.attach(7);  //pin 9 is the one control servo
-1

I note on the manufacturers website for the MG996R that it has an operating voltage of 4.8V to 6.6V.

Your problem could be that your voltage (at the motor) is below the minimum voltage of 4.8V.

Try driving the motor with 6V.

Also make sure you are testing the motor with no load connected to the output.

-1

The operating current (running current for the MG996R (~650 mA) is higher than SG90 (~220 mA) but definitely well in the capacity of a 5 V, 2 A. Unless there is a mechanical load on the servo motor, the motor is not limited by the current supply.

enter image description here enter image description here

The MG996R is a power beast. it is good idea to consider rechecking the supply voltage as well as trying with the supply greater than ~5 V.

PS: The code is definitely fine. Here is the simulation for the code you have posted which works fine with an emulator

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.