Servo jitter with arduino Mega only


I built a robot controlled by an Arduino mega, with 7 servos and 2 motors. The servos are used to move a robot arm, tilt and pan for a sensor head and pan a sharp ir rangefinder sensor below.

Everything works fine, but I have unacceptable jitter with all servos almost all the time. They stay in place just fine, but vibrate or shake a little every 2-3s. It doesn't seems to follow any pattern at all. Sometimes 2 or 3 do it together, but most of the time they do it one at a time.

They are cheap servos and I wouldn't expect them to work perfectly, but even the pan servos with no load at all have problems and that's strange.

So, I tried all obvious hardware solutions. Shortening the wires as much as possible, twisting the wires, spacing the wires, using a separate power supply, adding filter caps, adding a signal buffer/amplifier, etc. Nothing seems to fix or even reduce the problem a little.

I started suspecting the problem was software and not hardware related. I decided to experiment running them on the same fashion, with the same power supply and signal, but with an Arduino diecimila controlling. It works fine and they don't jitter at all.

Maybe it's the noise something else is generating, I don't know. Any ideas?

I decided to experiment running them on the same fashion, with the same power supply and signal, but with an Arduino diecimila controlling. It works fine and they don’t jitter at all.

How had you been powering them?

A 7.2V battery and a 5V regulator.

I found the cause. The robot has a NRF2401 transceiver for communication, and every time it's changed from tx to rx mode it has a 250uS delay, waiting for things to settle. This delay is affecting the servos and causing the jitter.

So, how to solve this? I thought the Arduino Mega would use different timers for each. My servos are connected to pins 8 to 13, and the library controlling the transceiver uses the _delay_us function when waiting.

I read somewhere that the delay isn't supposed to affect PWM and other hardware based timing, so I figure that wasn't the real cause. I changed the code and moved the delay to an asynchronous way and tested with different values and found it wasn't the real cause.

The real cause is a read I was doing inside an interrupt attached to the data received pin of the transceiver. Reading has a little 1uS delay and that seems to be the problem. I changed the interrupt to just switching a flag and the jitter is solved.

However, I had to enable back all the stuff I disabled to isolate the problem. When I enabled my LCD display back, guess what? Yes, I get some jitter back, following the LCD updates I have on the mainloop.

The interrupt issue made sense, but the LCD causing the same problem now doesn't. Any ideas?

The LCD is a serial device?

If so, the lcd.print function is probably blocking while it transfers data. Possibly long enough to interfere with the program's ability to provide the signal needed by the servo (every 20 milliseconds) to make it hold still.

Glad you solved the problem. I just experienced a similar problem and realized that the grounds between the two powers sources for each my arduino and the servos weren't connected. So anyone having similar problems might want to check that as well.


No, the LCD is parallel, not serial. I’m not sure what is blocking. From the code in the liquid crystal library, seems like there’s a very long (20ms) delay in the clear and cursor set calls, which I was using, but from my earlier conclusions, these aren’t supposed to affect the servos, are they?

these aren’t supposed to affect the servos, are they?

I’ve read that the servos need to be signaled every 20 milliseconds. I presume that longer durations between signals allow the servo to drift, if it’s under a load.

A 20 ms delay will interfere with the servo libraries interrupt to allow it to send a signal to the servos.

If what I’ve read is correct, then the jitter you see might be the result of the delay in the clear and set cursor functions.

I can understand, but not appreciate, the delay in the clear function. I’m don’t know what is happening in the set cursor function. All that I think should happen is a change to the index where the next character will be stored in the LCD’s buffer. But, I confess that the only thing I really know about LCDs is how to plug them in and use them.