Pages

Sunday, April 1, 2012

Servo Problems With Arduino - Part 1

Servo problems are one of the most frequently posted topics within the Arduino community. While problems may arise from programming, circuit design and faulty hardware, the vast majority or problems are a result of insufficient power or incorrectly connected power.

Control is nothing without power !

The Arduino itself is very good at controlling servos, the Servo library will allow a single Arduino to control upto 12 servos with no additional hardware.

What the Arduino cannot do is deliver power to 12 Servos, its questionable whether an Arduino can reliably deliver power to even a single servo.

Power - Not All Servos Are Created Equal

While building the circuit for the pictures in this post, I decided to
measure the current drawn by each of the test servos with no load applied.
Each of the servos is the standard size used in radio controlled cars,
they are all low end servos available for between 10 and 15 dollars.

No Load Current Of Test Servos In mA

The Bluebird draws five times more current at no load than the Futaba, its also less smooth and the least expensive of the servos tested.

The current at no load is only relevant in a small number of applications, all of the servos drew more than the the maximum 250mA I was able to measure when subjected to a light load in the form of finger pressure.

I will be interested to follow up this test in a future post using a variety of repeatable loads to compare servo performance and current draw. The fact that the lowest cost servo draws five times more current than the Futaba servo suggest that this will be an important concern for larger autonomous projects which will need to operate both under their own power and under load.

Note that while controlling all four servos the Arduino drew only 10mA from its separate power source.

So How Can Successfully Drive Lots of Servos With An Arduino ?

The power problem is easily solved through the addition of a 'power circuit'. This is can be as simple as four disposable AA Batteries such as you might use in a camera or toy car.

4 Domestic AA Batteries in a holder

Rechargable AAs are an even better option, they store as much charge, deliver as much current and can be used again and again.

For large projects which need to operate under their own power the basic concept is the same however the choice of battery technology will be different. See the 'Performance Power' section in Part 2.

So why do we need two power circuits ?

The Arduino has a narrow operating voltage around 5 Volts (3.3 Volts in some) and is sensitive to variation in this voltage. The Arduino design is based on the assumption that a stable 5 Volt power source will be feeding the chip at the heart of the Arduino. In the case of the popular UNO, this regulated 5 Volt power is supplied by the USB Connection or through a regulator built into the board.

The onboard regulator is designed to provide power to the Arduino and supporting circuitry. It is not designed to power external devices and trying to do so is the single most common reason for failure with servo projects. This 'Not designed to power external devices' also applies to USB Connected projects.

The remainder of this post provides a walk through of setting up an Arduino servo example which will drive four servos from the Arduino using a separate power pack to meet the power requirements of the servos.

Arduino Servo Walkthrough -

1) Power The Arduino

For the walkthrough I am using an Arduino UNO powered by a PP3 9 Volt Battery.

The Arduino has been loaded with my Multi Sweep example sketch, a link is provided at the end.

While running the servos, the Arduino was drawing only 10mA. A good PP3 could power the Arduino for days, after all, they power smoke alarms for months.

See the note below for more on the PP3 and why its not a good battery for use elsewhere in your projects.

Note - The PP3 is a poor battery choice for most applications, it has a small charge capacity (run time) and cannot deliver the higher currents required to drive servos or motors, however the 9 volts it provides is great for powering an Arduino through the onboard regulator. As the Arduino makes so little demand on a battery the PP3 is a common and practical choice to power the Arduino - just not any shields, motors, servos, transmitters etc.

The PP3's small charge capacity and limited ability to deliver current make it an unsuitable choice for providing the power circuit in our projects, the common AA battery is a far better alternative. In the case of servos the 9 Volts supplied by an unregulated PP3 is over the 4.8 to 6 volt recommended operating range and will result in immediate damage to the servo. Again AA Batteries are a better choice as four will provide a usable 6 Volts for our servo power circuit and a better run time.

This wont work for me, I need USB for Serial Output -

This is no problem at all, you can simply connect the USB Cable to the Arduino as you normally would. This will provide power to the Arduino so you do not need to use the 9V PP3 Battery.

You should still use the separate servo power and this will work provided that the ground from the battery pack is connected to the Arduino.

2) Power For The Servos

For servo power I am using four disposable AA Batteries. These are high capacity versions sold for cameras which will give us enough current and charge (run time) for our servos.

Each AA Battery provides 1.5 volts for a total of 6 volts (4*1.5).

Most servos are designed to operate with 4.8 to 6 volts. Powering them with more voltage can result in instant damage. The four AA Batteries give us a usable 6 volts.

I have connected the AA Batteries to the power (red) and ground (black) rails on my bread board.

Notice the black jumper running from the bread board to the Arduino ?

This is the next most common mistake in servo projects, when people introduce the servo power pack, they forget to connect a common ground.

You must connect the ground wire between the power circuit and the Arduino (control circuit) without this connection your circuit will not work. This applies whether you are powering your Arduino from a wall socket, USB port or a battery.

In the picture you can see where I have simply connected the two circuits through the black jumper wire running from the black ground rail of the bread board to the ground (GND) pin on the Arduino next to pin 13.

All of the ground pins on the Arduino are connected so use which GND pin is most convenient. These two circuits now share a common ground allowing us to add some servos.

2) Connecting Individual Servo Power

I have added a 3-Pin section of PCB Header to make it easier to connect the female servo plug to female breadboard.

Next to this you can see that I have added a green jumper from the battery pack ground rail to pin1 of the header, this is the shared ground between the Arduino, battery pack and servo.

Next I have added a yellow jumper from the power rail - 6 Volts from the AA Battery pack - to the center pin of the header. This will provide power to our servo directly from the AA Battery pack, not from the Arduino or its 9 Volt PP3 Battery.

The final pin is the signal pin, this is the pin which the Arduino will use to tell the servo which position to hold.

Remember - Without the common ground between the Arduino and the Servo AA battery pack, your project will not work. In the picture, this common ground is provided by the black wire linking the ground rail of the breadboard with the GND pin next to pin 13 of the Arduino.

3) Adding a servo

All we need to do now is connect our first servo -

You can see here that I have connected the first servo taking care to make sure that the black ground wire of the servo connector is connected to pin 1 of my header. This is then connected to the shared ground of the Arduino (and Battery pack ) through the green jumper wire.

You can also see that I have added headers for three more servos following the same convention of yellow for 6Volt power from the AA Battery pack and green for the shared Arduino/AA Battery pack ground.

The servo is receiving its position signals from the Arduino through the white jumper wire connected to pin 13. Remember - Without the common ground (black wire) connecting the Arduino GND Pin to the ground (-) fo the battery pack through the black ground rail of the breadboard, this will not work !

If you have uploaded the multi sweep example sketch linked at the end of this post, you should see your servo sweeping back and forth.

4) Adding more servos

Once you have one servo up and running, you can add more by following the same convention - connect the servo plug to the header so that the end with the black wire attaches to the header pin with the green wire. You can then add a connection from the signal pin to any of the Arduino digital pins 2-13 and you should see your additional servos follow the same sweeping pattern as the first servo -

"Recondition Your Old Batteries back to 100% of their working condition" . https://zbatteryreconditioning.weebly.com/- Car batteries- Computer and phone batteries- Rechargeable batteries- Long life batteries- Batteries used in alternative energy systems- Deep cycle marine batteries- Golf cart batteries- Forklift batteries- And many other kinds of common batteries!

Hey, how do i rotate the servo in the opposite direction. currently i am rotating it from 0 to 45 and back to 0 but from this position i want to rotate it to -45 ie 45 in the other direction..how do i do that?

I'm trying to run a s3003 off an arduino pro mini 5v. The system works fine when connected through a usb cable. But when I power it from a dc brick the servo acts nuts, I think the unit is continually resetting.

I've tried two dc adapters, one at 12v and one at 9v both supplying more than 1 amp. according the label on the dc adapters.

Can you tell me how I can test/troubleshoot? Can you confirm the wiring? I soldered the dc adapter to Vin and GND. I connect the servo's power line to the vcc pin on the side closest to d9.

Seems like there's not enough amperage to power it but 12v 1amp should be more than the 5v usb cable was providing, which I assume is .5 amp.

the 12v power source might not have any voltage smoothing (caps) built in so the down slope of the PWM especially under load can cause 0V to be recieved and the system reboots, splicing a 16V or higher cap into your 12V line should smooth out the down slope, and another cap on the supply side from board to servo should take care of the downslope from the arduinos PWM system.

Am I correct in assuming that this will work for bigger Servos as well without damaging my Arduino? I'm new to Arduino and I thought a Servo checker would be a fun project as it would be handy at work, we have servos ranging from 12 to 48 volts DC. As long as I make sure the voltage to the Arduino board is kept at the proper voltage, I can use whatever power supply I need for the servo, correct?

9V is too high for servos, they typically operate on 4.8 to 6 volts. A quick and easy way to get this voltage is to use 4 AA Batteries instead of one 9v battery. The 4AA Batteries will also support higher currents than a single 9V battery so your servos will support higher loads. Any model shop or electronics store will stock 4*AA Battery holders that you can use in your project.

Your arduino has a built in voltage regulator which can produce the steady 5V that your Arduino needs from a 9V battery.

In my standalone projects I often use a 9v to power the Arduino and 4*AA to power a servo or motors.

Thank you for this amazing post, but what if i use Arduino UNO, 4 servos and i add an HC-05 Wireless Bluetooth RF Transceiver Module serial RS232 TTL and Ultrasonic Sensor Module HC-SR04, these both should connect to the Arduino power outputs? Or how should i power them?

If you want to be able to send inputs/outputs between any two components or your project, they must have their grounds connected. So in your case I assume the ESP8266 is providing and input to the Arduino which is providing an output to the servos, in which case all three need to have a common ground.

1) The step down from 11.1 to 5v is a lot for the regulator to handle, it might be better to consider a 2s Lipo which will output around 8 volts giving the regulator less work to do.

2) Each individual servo could draw 1 amp of current if it is heavily loaded, this will overload the regulator causing the output voltage to drop and effect all other components (AVR) that share the same regulator

3) Because of 2) above I would consider a separate regulator for the servos, in fact as the servos might each draw over an amp if they are heavily loaded you might want to consider a dedicated high output regulator for the servos or individual low cost regulators for each servo.

From memory the high output regulators are expensive and so you might prefer individual regulators, or if you project is just a short term desktop project chance a single regulator and accept that its not a production quality solution, but suitable for your own desktop entertainment if thats the goal.

wont this method damage arduino?i mean extra current from external battery , which will be connected to ground of arduino should damage arduino.and if it doesn't get damaged then what it the reason for it!please answer!

Recondition Your Old Batteries back to 100% of their working conditionhttps://zbatteryreconditioning.weebly.com/- Car batteries- Computer and phone batteries- Rechargeable batteries- Long life batteries- Batteries used in alternative energy systems- Deep cycle marine batteries- Golf cart batteries- Forklift batteries- And many other kinds of common batteries!

Are you looking for a cash for cars ipswich? Then, you've came to the right place. All Cars Buyer provides excellent expertise in the areas of junk car removal, car disposal and cash for cars in all area of Caboolture . With more than 10years in automotive industry, we are largest buyers of the wreck automobiles ...Phone: 0403331443