Powering your Arduino with batteries

The Premise

So, you've created an Arduino project and you want to power it with batteries to take it on the road. Your board's components are designed to run on 5 Volts and you know you can't feed 9V directly into the Vcc of a 5V board because it will damage it. Arduino has you covered - the pin marked "RAW" is for that purpose and according to the documentation, you can feed it between 6 and 12V and it will regulate that voltage down to the 5V needed by the board. Perfect, right? Well, not quite.

Voltage Regulation

There are 2 main ways to regulate (aka control) the voltage. A linear regulator allows you to supply a higher voltage than desired (in our case 9V) and get a stable, lower voltage as output. It essentially does this by generating heat from the excess energy. Let's say your board uses 100mA @5V while executing your code. If you're powering it from a 9V battery through a linear regulator, then you're creating 4V x 100mA = 400mW of waste heat (9V - 5V = 4V). If you measure the current coming out of your 9V battery, it will be very close to 100mA, so 9V @ 100mA is going into the regulator and 5V @ 100mA is coming out. The means that the linear regulator effectively has an energy efficiency of 56% in this case. For many many years, the 78xx series of linear regulators is what you would use for cases like this:

Aside from the simplicity, there isn't much to like about linear regulators. When running on battery power, you're throwing away a large percentage of your battery's energy when you regulate the output this way. In circuits that use a lot of current, heat becomes a major concern too.

The older Arduino boards have a linear regulator built in to make it easier to power them from various energy sources. The assumption is usually that you'll be running from a wall wart (A/C power brick) so wasted energy isn't much of a concern and that you'll be running a small current through your circuit, so waste heat isn't a concern either.

Some simple energy calculations
If you're using a 9V alkaline battery that has a typical energy capacity of 500mAh and you connect it to the Arduino's linear regulator...

9V x 500mAh = 4.5Wh (mAh = milliamp hours, Wh = Watt hours)
5V x 500mAh = 2.5Wh

In effect, instead of having a 4.5Wh battery, you have a 2.5Wh battery because the rest of the energy is given off as heat.

Buck (or step down) converters are another way to convert a high voltage source to a lower voltage. Buck converters are a more complex circuit that relies on an oscillator and inductor (coil) to change the voltage. The advantage of the buck converter is that it doesn't waste nearly as much energy as a linear regulator. Here are the efficiency curves for a typical buck converter:

With 5V output at low current, it approaches 97% efficiency. That means that your 9V battery could potentially provide closer to 4.5Wh of energy to your circuit instead of the 2.5Wh you get with the linear regulator. Electronut Labs sells a convenient buck converter specifically designed for easy use with 9V batteries:
What about going in the other direction? This is the option that's usually not mentioned in Arduino project articles. It's also possible to boost the voltage from a lower voltage to a higher voltage. DC-DC boost converters work similarly to buck converters and use a high frequency oscillator and a coil to generate a higher voltage. They also have typical efficiencies greater than 85%. This frees you to use other power sources such as a single AA battery. An Alkaline AA battery typically has a capacity of around 2500mAh. At 1.5V, this translates to about 3.75Wh of energy. Less total energy than a 9V battery, but used efficiently, it can save space and cost compared to a 9V. If we boost 1.5V to 5V and assume that the boost converter has an efficiency of 90%, we should be able to squeeze about 3.375Wh of energy out of it. Here's a typical DC-DC boost converter sold by various vendors in China for $0.45-$1.00 each:
I like to use these in my projects because they're tiny and inexpensive. They operate down to about 0.8V as input and the output is clean enough (low noise) to use in most microcontroller projects.

Power Down

The original set of Arduino boards were all based on AVR microcontrollers and all set to run at 5V. This made sense at the time because the AVR MCU can operate on any voltage between 1.8V and 5.5V, but at the higher voltages, the clock can run at up to 20Mhz (see chart below):

The reality is that your project probably doesn't need the MCU to run at 20Mhz. If you're reading a few sensors and updating a display, you could accomplish the same work at a lower clock rate. Another reason is that the amount of energy used by the MCU and peripherals does not perfectly follow a linear scale. Even so, you can potentially accomplish the same amount of work running at 8Mhz and 3.3V as you could at 16Mhz and 5V. Running the CPU slower or at a lower voltage uses less energy.

A lot of newer MCUs in the Arduino lineup operate at 3.3v (e.g. ARM Cortex-M MCUs) and so do many add-on boards, so it makes a lot of sense to run your project at 3.3v. Without having to know too much about AVR fuses and hardware, it's possible to run a board designed for 5V and 16Mhz at 3.3V and 8Mhz with a simple trick in software. The main CPU clock divider can be set in software. We can use this to cause a 16Mhz part to run at 8Mhz so that it can run reliably at 3.3V. The clock prescaler is normally set to 1 on Arduino boards. By setting it to 2, the CPU will run at a more stable 8Mhz:


#include <avr/power.h>
clock_prescale_set(clock_div_2);


Now with this new information, let's look at cost and battery life of our original 5V project running on a 9V battery versus our new idea of running it at 3.3V from a single AA battery. For the cost, I'm making the assumption of buying a 4-pack of each battery type (Duracell) from Amazon.com.

Worst case:
9V into 5V linear regulator, 100mA current drain 
$2.64 each
500mAh / 100mA = 5 hours of run time

Best case:
1.5V into 3.3V boost converter (90% efficient), 100mA current drain
$0.94 each
100mA output requires 244mA input --> ((3.3v / 1.5V) / 90%) * 100mA = 244mA
2500mAh / 244mA = 10.2 hours of run time

Leave it Running?

In the examples above, if you leave the power source connected and your Arduino project is mostly sleeping, you'll still be losing some energy through the power regulation circuit. When I use these types of power regulators with batteries, I put a power switch between the battery and the regulator to keep it from draining when not in use. If you want to leave your project running for months at a time on batteries then a better choice might be to use 2 or 3 AA batteries in series and run them into the Arduino unregulated.

What's Next?

In the near future I'll write about how to reduce power usage through careful part selection and changes to software so that those battery powered devices can keep running as long as possible.

Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Interesting article, just one thing is that for what I know the internal clock is less reliable so when you have time critical operations it may be better to use external oscillator, also instead of 7805 you may use Low Quiescent Current and LDO regulator like MCP1702.

    ReplyDelete

Post a Comment

Popular posts from this blog

Controlling lots of OLED displays with a few GPIO pins

My adventures in writing an OTA bootloader for the ATmega128RFA1

Fast SSD1306 OLED drawing with I2C bit banging