Servos keep failing after some time

so, I keep having trouble with figuring out my servos. I'm trying to do a project with 8 Servos pressing buttons in a certain sequence in a loop. Servos are small metal gear ones off of amazon around 15€, (https://www.amazon.de/dp/B0BHY4H1KN?psc=1&ref=ppx_yo2ov_dt_b_product_details) so not the cheapest ones either. I'm powering them separately through USB, measured it at 5.1 V. Arduino is an Arduino Micro.

the code is simply whenever a certain button/servo is called, in a subroutine it writes the position at which it presses the button, retracts after about half a second, subroutine ends and it goes to the next button in the sequence.

movement delta is 20°, always centered close to 90°, so none reach anywhere near the 0-180° limits. there is never any struggling sound once they reach their position.

It runs fairly well until always at some point after some time one or more servos stop turning and don't start up again even when the code loops or worse go into continuous turning (which isn't called a single time in the code). it's not the same servo every time plus in the cases of continuous movement, sometimes it's clockwise, sometimes counterclockwise. also it happens always at different points in the loop. when I then power everything down and then initialize again from the top most of the time it starts up again, and the same problem occurs again after some runtime. but it has also happened that a servo died completely and had to be replaced.

movement is executed almost always one after the other, never more than 2 at the same time. I have also tried the code with and without detaching in between use which didn't make a difference.

here's the code, shortened by a lot to just one of the button pressing routines, every subroutine does exactly the same, just abbreviated it to one of them as an example, because the whole thing would be way too long for this.

#include <Servo.h>

Servo a;

int pin = 9;
int idleposition = 103;
int pressingposition = 123;

void setup() {
  a.attach(pin);
  a.write(idleposition);
  delay(2000);
}

void loop() {
  pressbutton(x);
  pressanotherbutton(x);
  .
  .
  .  //as mentioned it does a long sequence of button presses
  .  //one after the other, and then loops the same sequence
}

void pressbutton(int r) {
  for(r; r>0; r--){
    a.write(pressingposition);
    delay(400);
    a.write(idleposition);
    delay(350);
  }
}

void pressanotherbutton(int r) {
  //looks exactly the same as the one above
  //just with the respective servo object
  //and the respective positions initialized
  //at the top like the mentioned ones
}

again, abbreviated for ease of reading. but functionally this is literally all any of the servos are doing.

this is the first time I've ever worked with servos so it's highly likely there's something I don't know, but it just seems weird to me how they keep failing seemingly arbitrarily. I can't find a pattern so I'd appreciate some suggestion on what to look out for, thanks.

any other information which might be of interest for figuring this out, please just ask, obviously!

Do you have the 0v DC grounds tied together?

1 Like

Hi, @chrushl
Welcome to the forum.

How are you powering your servos?
There doesn't appear t be any specs on the units.

Have you measured the current one servo uses?
Usually an Amp or more.

Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

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

Hi,

GND is connected between the servos/power supply and the arduino, yes.

for power I simply took an USB cable, cut it in half, and used the red and black wire, the other side is plugged into the wall with a 48W adapter.
I have measured here at the wires 5.1V, haven't measured the current yet.

unfortunately I won't be able to do so until tomorrow,
just like the circuit, but will provide that info as soon as possible!
thanks for now!

I believe if you only do that, it will limit its power output to 500mA. It needs to see a compatible device and cable. You may need to add some pull up resistors to your cable.

As there is only one 5V connection on the Micro, the servo drive current will not be drawn through it, which is a good thing.
The best way to connect is "star" configuration, with each peripheral and controller connected directly to the power supply or lead at one point each for positive and gnd.

Also the USB cable wire is going to drop some volts when the servo(s) are used, this would cause the Micro to power reset.
Have you measured the 5V when your servos are faulting.

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

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

The servo in the link has the same dimensions as a common/cheap SG-90.
The SG-90 has a stall current of 650mA@5volt.
The supply has to be capable of delivering 8x650mA = 5.2Amp peak.
You could have serious volt drop through a USB lead with those peak currents.
Leo..

ok, that is actually new to me, never thought of that.
in case that was the source of the whole problem, something like this should solve the problem though, right?
5v power supply
if so, I might be able to pick something like that up on my way home today and test with this.

connecting the 5v power supply pin to the 5v pin of the arduino too?
does that work, when the arduino itself is power via it's USB-micro port connected to a laptop?
sorry if I forgot to mention that.

why that much?
there are never more than 2 Servos running at the same time, so it should never have to supply max current to all of them at the same time, right?


I was able to whip something of a drawing up at work just now, hope this helps.
I can measure the mentioned things after work today.

Only connect the arduino gnd to the power supply gnd then, your circuit needs to have a gnd reference. No need for external 5V if USB powered.

Tom.. :grinning: :+1: :coffee: :australia:

always had that connection between the GNDs luckily.
but I'm wondering now, what would happen if you powered the Arduino over USB and at the same time applied an external 5v to the 5v pin?
would that simply be overkill or could that damage something?
never did that, just wondering, in case you know.

Post complete code.

You would need to consult the schematic for your specific controller.
Some rely on diode switching, others on MOSFETs to prevent 5V supplies from causing weird back currents on their boards and back to the sources.

Tom.. :grinning: :+1: :coffee: :australia:

Disclaimer, the internet isn't always true and I've never tried this.

Google quick charge USB cable DIY. I've never done it for lack of need, but the idea is that you short the green and white data lines and it tells the charger to put it in high output mode. I don't guarantee this will work and can't give any recommendations though. Might deliver higher voltages too? IDK.

What if the other six, not "running", are stalled against one end of travel, resulting in each drawing their rated "stall current"?
I don't see any way to remove the power from your servos, but are you actually removing the PWM signal from any servo not presently moving? Otherwise, they're still being commanded, and will draw excess current if they're unable to maintain position.

ok, so first I measured the voltage again at the cut open USB cable, stil 5.1V

now for current, I have two versions of the code, the one sampled above which attaches in void setup and never detaches.
and a second one, where everything is the same except for all the subroutines it attaches the corresponding servo object at the beginning and detaches at the end. subroutine looks like the following.

void pressbutton(int r) {
  a.attach(pin);
  delay(200);
  for(r; r>0; r--){
    a.write(pressingposition);
    delay(400);
    a.write(idleposition);
    delay(350);
  }
  a.detach();
}

as another example here is the detaching version of one of the subroutines that moves 2 servos at the same time.

void md(long d){
  x.attach(xpin);
  y.attach(ypin);
  delay(200);
    x.write(xactiveposition);
    y.write(yactiveposition);
    delay(d);
    x.write(xidleposition);
    y.write(yidleposition);
    delay(200);
  x.detach();
  y.detach();
}

I worked with the detaching version for quite some attempts now, so just before I decided to turn to this forum for help I tried the none-detaching version, but the thing is, that it came to the same result of one or more servos failing after some runtime, different servos at different positions in the sequence.

measuring current now, in the none-detaching version (mentioned in the original post) it draws somewhere between 30-60mA when idle and when one of the servos is expectedly moving, I've seen it jump most of the time to somewhere around 200-250mA, but I've seen a few jumps to 400mA, 457mA being the highest I saw.

the detaching version (mentioned in this comment) at idle draws a constant 19mA.
when moving it also jumps to somwhere between 200 and 250mA most of the time, highest I've seen being 442mA.

for measurements when a fail occurs, I'll have to wait for it to to so again.
it's a bit difficult since it could be hours before it does so, but I'll try to catch it.
but also on that note, a power reset of the Micro has never occured (yet)!

the complete code is over 1800 lines long, because the sequence is very long and all the subroutines.
but the subroutines are all just copy-pastes with the respective servo objects and active/idle positions being initialized exactly as the ones shown above. and the sequence is simply calling subroutine after subroutine.
I'm positive abbreviating it as shown is way easier for understanding what is going on.

do you maybe have a link?
what I find is one doing way more complicated things with the plugs themselves, one that explains to short it on the phones side "so the phones knows to draw more power" and another which doesn't short the green and white one, but the green with black and white with red.

I get what you mean, it could be bad luck to hit a moment where all of them are readjusting at the same time,
but (also to answer your second question), as expained here, I've tried both versions of either keeping the PWM on at all times or removing it whenever not supposed to be moving.
but both sooner or later arrived at the same problem.

in fact worst case scenario running the detaching version I've seen yet was that one failing occurence it sent one of the servos into continuous movement, but this time one of the servos that wasn't even attached at that time!

I think this should be all for now.

You of course have used an oscilloscope for that, not a slow digital multimeter.

Servos briefly draw the stall current every time they start moving.
Modern switching power supplies could briefly turn off during overload.
Leo..

Nope. Sorry. I've never done this so I won't make any recommendations.

of course I used one of my many backpocket oscilloscope, lucky I had that on handy.

I didn't know that, could you give me an example for an alternative that doesn't turn off?
or something to look for in an alternative, please?

Any 5volt supply that can handle the peak current of YOUR setup will do.
Not saying that the problems you have is from the supply,
but most servo problems we see here are related to that.
Leo..

Really you just need a sturdy power supply and storage capacitance.