Power/Noise Issues while Controlling 2 MG995 Servos with Arduino Mega2560

Hey guys,

Got a bit of a problem. I am trying to control two servos with a simple joystick and I am running into issues. I am trying to control 2 MG995 Servos using my Arduino Mega 2560. The joystick is a simple thumbstick with 5 pins (+5V, GND,X,Y,SWTCH).

When I wired the servos and joystick up, I didn’t see much of anything,just buzzing. Then when I added a 100µF capacitor across a switch for one of the servos, it partially worked and then other servo worked completely. I know my code works great because if i hook up 2 HS-50 servos, I don’t run into issues, I have complete control. Check out the pic of my fritz schematic to see how I have it wired.

Ultimately, I’m thinking it is a combination of issues, both power & noise. I am running everything from the board’s power supply (which I know is a no-no) but I couldn’t get a response when I used a 9v battery with a voltage divider as an external 4.5V power supply. For my voltage divider, i tried with 10k ohms for both my resistors and got no response.

I also tried adding in a low pass filter, R=220 ohms w/ C=100µF for an fc of about 7ish Hz, no success. In reference to the schematic, I also tried increasing the capacitance to 200µF and 50µF, but neither were successful, only 100µF really showed promise. I really think manipulating the capacitance might be key though.

I did hook up the circuit that is shown to a scope and i recorded the output. This image is also attached. Any help or guidance would be really appreciated!!

If I can give you more information in order to properly respond to this post, please let me know!!

Thanks yall!

  • Drew

abb825: I am running everything from the board's power supply (which I know is a no-no)

Correct. Do not do that. You get exactly the results you are describing. Use a proper power supply.

but I couldn't get a response when I used a 9v battery with a voltage divider as an external 4.5V power supply.

A 9v smoke detector battery? Also not a proper power supply.

Try 4x AA batteries to power the servos. Use common ground.

vinceherman: A 9v smoke detector battery? Also not a proper power supply.

Try 4x AA batteries to power the servos. Use common ground.

That's why I tried creating a voltage divider: Vout = [R2/(R1+R2)]*Vin

With, my Vin as 9v and R1=R2=10kOhms, it should be 4.5 V, or roughly 3x AA batteries

It's just your garden variety 9V battery. Im sure you could use it in most smoke detectors.

abb825: That's why I tried creating a voltage divider: Vout = [R2/(R1+R2)]*Vin

With, my Vin as 9v and R1=R2=10kOhms, it should be 4.5 V, or roughly 3x AA batteries

It's just your garden variety 9V battery. Im sure you could use it in most smoke detectors.

Yes, you can use it in a smoke detector or a transistor radio. Those applications pull a VERY small amount of current. Your physical motors do not pull such a small current. They pull a much larger amount of current and the 9v battery cannot provide that voltage at that current. The voltage drops way down and your devices brown out and fail.

vinceherman: Yes, you can use it in a smoke detector or a transistor radio. Those applications pull a VERY small amount of current. Your physical motors do not pull such a small current. They pull a much larger amount of current and the 9v battery cannot provide that voltage at that current. The voltage drops way down and your devices brown out and fail.

Hi vince Herman,

thanks again for your response. maybe I should clarify. A 4.5V external power supply was created using a voltage divider from a 9v battery. this Vout of 4.5V ultimately provided no response so it was not used. again, the boards power supply is what the schematic indicates as well as what the scope output.

If you don't use a separate power supply with a reasonably high current capability with powerful servos it's simple. They do not work.

The 5V out from the board won't work. 9V PP3-type batteries won't work. And a resistor voltage divider will NEVER work...as soon as the load draws any current the voltage drops close to zero.

4 x NiMH rechargeable AAs are good. They will usually provide more current than primary AAs.

Steve

abb825: . A 4.5V external power supply was created using a voltage divider from a 9v battery. this Vout of 4.5V ultimately provided no response so it was not used. again, the boards power supply is what the schematic indicates as well as what the scope output.

As indicated earlier, a resistor potential divider will not work here because you are drawing current from the mid junction. Potential dividers work if very little current is drawn from the series arrangement. Not for directly making a lower voltage power supply.

Tom.. :)

Steve and Tom,

Thank you for your response. I went ahead and invested in 4x AA NiMH batteries and connector. I now have a 5V cell with a capacity of 2400 mAh as my external power supply.

I still have no movement from one of the servos. From what I read, the MG 995 has a running capacity of about 350 mA so I'm still a little baffled on why I don't have movement from the second servo -- the first one works great. I'm thinking this is where the noise issue is comin into play.

I then thought, 'Oh, must be noise'. So I created a low-pass filter with an Fc of about 6.3 kHz and still goose egg. Doing so was almost worse: I got no movement in either servo.

.....thoughts?.....

abb825: .....thoughts?.....

Yes. Test each servo individually. Unplug the servo that works. Move the servo that was not working to that pin the first servo was on. Run your sketch. Does the servo respond?

How exactly do you have the servos connected? Connecting high powered equipment via a breadboard is a bad idea. The battery +ve should connect directly to the servos +ve and then to the Arduino. Same with the battery -ve. A proper circuit diagram, even hand-drawn or a picture of the actual layout of your project would help.

But first...are you sure the second servo actually works? If you change the two servos over does the problem move to the other servo or is it always the same servo that doesn't move?

Steve

Guys,

Awesome responses so far. So I’m pretty dang postive the second servo works. When I have it hooked up to the boards power supply, and with a capacitor on the signal line, I get some response. This is the same arrangement from my fritz file in my first post. This is the same arrangement as the sketch attached to this post. I guess it could be a bunk piece of equipment but I don’t think so.

When I tested the problematic servo on the first servo pin, I just hear a high frequency noise and low buzzing. No movement. Furthermore, the external power supply really does no good: I get no movement whatsoever when I have that hooked up. Again, this

As far as using a breadboard for high-powered equipment, why won’t it work? It should theoretically, should it not? Maybe it’s not preferred but it’s what I’ve got right now.

Hi,
Ops pic.
IMG_3664.JPG
Why is the 100uF cap across sig to gnd?
It should be 5V to gnd.

Tom… :slight_smile:

Hi Tom,

I read that elsewhere to but when I tried it, I got no response from either servo. With my configuration, I at least got full control of 1 servo and partial control of that servo

According to that diagram there’s no battery or power going into the system from anywhere. So I’d say it’s not exactly a complete diagram. And running servos via the Arduino 5V pin is always a bad idea.

BTW breadboards often don’t make very solid connections and breadboard tracks are only intended to carry low currents, typically < 100mA. People have burned out tracks by running servos and motors through them. Other than that they’re just dandy.

But hey, we’re just offering advice. You don’t have to take it.

Steve

Thanks Steve. Trust me, I really appreciate y'alls advice! On my diagram, you're exactly right, I didn't draw my USB cable providing power to the Arduino Mega.

I see other people accomplish this task with simple breadboards which is why I hesitate to spend more money on equipment:

https://www.youtube.com/watch?v=WnKNEcDZwfM

https://www.youtube.com/watch?v=raTeZGsYZf0

Regards, Andrew

Hi, Can we have a picture of your setup please? Can you please post a copy of your code, please use code tags.

You should not have the 100uF from sig to gnd.

Do you know what the format of the signal is to control a servo? It is a PWM system, the duty cycle of the signal controls the servo position. Putting a capacitor in the signal line like you have causes distortion of the signal, plus possibly higher than specified current being drawn from the Arduino output pin.

https://www.servocity.com/how-does-a-servo-work

Put the 100uF across the +5V and gnd that goes to the servos.

Tom.... :)

abb825:
Guys,

Awesome responses so far. So I’m pretty dang postive the second servo works. When I have it hooked up to the boards power supply, and with a capacitor on the signal line, I get some response. This is the same arrangement from my fritz file in my first post. This is the same arrangement as the sketch attached to this post. I guess it could be a bunk piece of equipment but I don’t think so.

When I tested the problematic servo on the first servo pin, I just hear a high frequency noise and low buzzing. No movement. Furthermore, the external power supply really does no good: I get no movement whatsoever when I have that hooked up. Again, this

As far as using a breadboard for high-powered equipment, why won’t it work? It should theoretically, should it not? Maybe it’s not preferred but it’s what I’ve got right now.

I think you have to back way up and do some simple testing.
Load up the servo sweep sketch and confirm each servo works properly.

Implemented ‘Sweep’ (https://www.arduino.cc/en/Tutorial/Sweep) for each servo:

  • Sweep worked fine for first servo
  • Sweep for second servo using Arduino power supply produces a ticking rotation in increments of 10 degrees, one-way
  • Sweep for second servo using ext power supply caused very erratic behavior, increased speed, went back and forth in unpredictable manner, terminated with high frequency buzzing noise

For my setup:

  • Photo attached is same as fritz sketch and hand drawn circuit (whereby I forgot to include USB power). Though now, I am powering from external power source, not the Arduino
  • I have the 100uF cap there because I at least have control of that servo in one direction. without it , I have no control of either servos whatsoever
  • I tried connecting the 100uF cap across +5V and GND, got nothing. Even tried it with sweep and got the crazy erratic behavior again.

My joystick code works beautifully with 2 HS-50 servos:

//add the servo library
#include <Servo.h>

//define our servos
Servo servo1;  
Servo servo2;  

//define joystick pins (Analog)
int joyX = 0;   
int joyY = 1;

//variable to read the values from the analog pins
int joyVal; 


void setup() {
  servo1.attach(9);  // attaches the servo on pins 9, 10 to the servo object
  servo2.attach(10);
}

void loop() {
  //read the value of joystick (between 0-1023)
  joyVal = analogRead(joyX);
  joyVal = map(joyVal, 0, 1023, 0, 180);
  servo1.write(joyVal);

  joyVal = analogRead(joyY);
  joyVal = map(joyVal, 0, 1023, 0, 180);
  servo2.write(joyVal);
  delay(15);
  }

I think you have identified the problem as a bad MG995.

vinceherman: I think you have identified the problem as a bad MG995.

Haha, you are probably right. I have noticed that when I run Sweep with the ext. power supply and an electrolytic 100uF cap placed physically right next to the power supply (not electrically as what I had thought prior), I get good behavior for a few seconds and then it freaks it.

Power supply de-coupling ring a bell anyone?

De-coupling