## Tuesday, April 3, 2012

### Servo Problems - Part 2 - A Demonstration

If you have read the post Servo Problems With Arduino you will recognise the following as an apparently working circuit for driving one or more servos -

Lets have another look at this circuit -

In the following video I have replaced the 4 AA batteries that are powering the servos with a single 9 volt PP3 Battery. This battery is providing power to the servos and two LEDs through a 7805 regulator. This is a common regulator used in many Arduino's such as the Boarduino and standalone Arduinos. It is a reasonable replica of the 9V PP3 battery and on board regulator powering my Arduino UNO in the first video.

PP3 9 Volt Battery and The 7805 Regulator (red highlight) That Power A Boarduino

I have made one change to the circuit and introduced two series LEDs (and a current limiting resistor). Like all LEDs these two require a minimum voltage to light, in this case, combined they require around 4.5 volts. Thats about the minimum operating voltage of an Arduino so lets imagine that the LEDs are infact an Arduino sharing the same power circuit as the Servos.

Now lets see what happens under load -

Servo Under Static Load

When the LEDs go out, it is because the are no longer getting their minimum 4.5 volts.

When we apply a load to the servo, it draws more current, in this case it draws more current than the battery is able to deliver, when this happens, the battery voltage drops.

If this really was your Arduino it would have 'browned out' or at the very least your project would begin to behave oddly.

In the following video the servo is being instructed to sweep, even less effort is required to get the servo to take our imaginary Arduino out of service -

Something else interesting is also happening, its easier to see in the following videos, but even without a load applied the servo is able to take down the LED Arduino -

In this circuit I have added another LED in the top left corner for comparison, this LED is driven by the Arduino power circuit (+5v -> 680 Omh resistor -> GND). The other two LEDs remain on the servo power circuit, note how the Arduino LED remains at a constant brightness whereas the imaginary Arduino LEDs flash noticeably -

The camera is not fast enough to capture the full extent of the flashing in the LEDs, but if we can see it at all , you can be sure the Arduino is feeling it.

So what is this noise, where is it coming from and what can we do about it ?

Its not really noise, its our battery telling us that it just can't deliver the current we are asking for. The video is produced with no load, applying even a light load takes the LEDs out completely - thats not noise, thats your circuit telling you something.

The flashing is in sync with the servos changing direction at the end of their sweep. I don't have the means to investigate this further but suspect its down to the following effects -

1) The servos internal motor driver will be switching one set of transistors off and another on in order to reverse the motor
2) Momentum, the servo has to stop its internal motor and gears and get them moving in the opposite direction, this will require a burst of power.

Ok, but how do we get rid of the noise ?

As its not really noise, just our circuits way of telling us it doesn't have enough power, the solution is to add power.

Repeating the tests with the original four AA Battery pack provided improved results however it was not until I powered the circuit with a high power LIPO battery that the LEDs would remain lit at a constant brightness.

More on LIPOs and other batteries in a future post and some suggestions on using a similar LED set up to 'let the hardware do the work' in monitoring the power situation.

Duane B

1. Hi, great post! I have a doubt: if I use only one battery for both circuits (arduino and servo), it's ok or I could have some problem?

2. Hi, If you look at the last video where the bottom two LEDs are sharing power with the servo, you can see that they flash, particularly when the servo changes direction. This is due to the power the servo is drawing which is causing the voltage available to the LEDs to drop. If you Arduino was sharing this same power you could expect problems. A basic solution is to power your Arduino from a 9volt pp3 battery and your servos from four AA batteries. Thats what is used in the video and it is why the LED at the top left does not flash, it is sharing power with the Arduino, not the servos.
Duane B

3. Hi, Really a great post... Thanks for the video tutorials. That help me to understand it well..

4. A simple solution to use a single power supply is to feed the Arduino through a series diode on the positive rail followed by a generous (220uF +) capacitor to ground. The diode will prevent the motors from "drawing voltage" from the Arduino during the current peaks, while the capacitor holds up the voltage on the Arduino side. This works very well.

1. Very interesting solution. I hadn't thought of this before. Why did you choose 220uF?

5. awesome man, thanks for posting this. Now i can find why my project doesnt work!

6. Hi there,

I am trying to drive 12 rc servo motor for my quadruped project. I used 4 standard AA batteries and nothing happened. But when i fixed the batteries to only 3 servos it operated well. That would mean i need 16 AA batteries to drive 12 servo motor. Is this normal?

I am using an SG90s servo.

Jeremy

7. Hi,
Hobby servos can require around 1 Amp each if they are working against a load. For 12 Servos you could look at using LIPO Batteries, they are smaller, lighter and deliver more power - they do require a LIPO Specific charger though.

Duane B

8. Great article.. (more troubleshooting tips would be awesome!)

* how to solve jitter/twitching? I see it sometimes twitch when its in its end position?

* (more important) how do you compensate for the initial position the servos move to when powered? (before you can send any type of servo.write() command?)

ie: if you have two servos two to lift/move a platform together.. when you power they both individually move to their random/default positions before the code is attached/write a position to them?

* (maybe specific to library or other user fault/error) ServoTimer2 uses pulse instead of angle...

Im using this instead to help understand/use the library itself:

#define degreesToUS( _degrees) (_degrees * 6 + 900) // macro to convert degrees to microseconds

as in:

myservo.attach(9); // attaches the servo on pin 9 to the servo object myservo1.attach(3); // attaches the servo on pin 3 to the servo object

myservo.write(degreesToUS(pos1));
myservo1.write(degreesToUS(pos - 10));

it also seems I need to 'off-set' one of these servo's to the get both servos to the same angle/position..

ie: if I write

myservo.write(degreesToUS(45));
myservo1.write(degreesToUS(45));

to both servo & servo1.. they do NOT match/end at the same place. (maybe just mis-aligned arm placement?)

thanks!