Shares
How to Run an Arduino for Years on a Battery

How to Run an Arduino for Years on a Battery

Last Update: / by Marco Schwartz

If you found this article after doing a search on Google, welcome! On this website you will find plenty of content around DIY home automation using open-source hardware. Enjoy the article!

For most of the Arduino tutorials you will find on this website, power is usually not an issue as the Arduino is powered by the USB cable coming from the computer. However, sometimes you want to build systems that are going to be autonomous and powered by a battery.

For example, you want to power the wireless motion detector just by using a set of batteries. The first idea would be to connect directly an Arduino board like the Arduino Uno R3 to a battery. Easy, right ? Well, it would work, but your battery would be depleted in a matter of days because some components like voltage regulators are always sucking power. So we need something better.

The first thing we need is to build our own Arduino system with just the minimal set of components. This will be similar to a previous article, but with even less components. The second part is to optimize the software so that the system only consumes power when it is actually doing something. And that’s exactly what we will see in this article.

Hardware & Software Requirements

You need several components to build you own Arduino system. The main piece of this project is of course the microcontroller that will run your Arduino sketches, like the Atmel ATmega328. You will need a chip with the Arduino bootloader. Buy your chip with it, it will make your life easier.

How to Run an Arduino for Years on a Battery

In a previous project I used a FTDI breakout board to program the Arduino chip directly on the breadboard. But for this project I won’t have any external power running on the breadboard so I will just use an Arduino Uno board to program the microcontroller.

To power the Arduino, you will need a battery. The best is to power the Arduino directly from the battery, so you don’t have to use any voltage regulators that will suck some power. I used a set of two AA batteries (1.5V each) with a battery holder thus powering the microcontroller with around 3V, which is fine according to the ATmega328 documentation.

You will also need several components around the chip. You will need one 10uF capacitortwo 22pF capacitorsone 10K Ohm resistorone 220 Ohm resistorone green LED, and one 16MHz crystal clock.

Finally, you will need a breadboard and some jumper wires.

This is the list of the components that were used in this article:

On the software side, you just need the usual Arduino IDE. Note that in this tutorial, we will only cover a tiny part of the possibilities offered by the Arduino platform. [Arduino course]

Hardware Configuration

This project is a bit complex to build, so be sure to follow the instructions. This is how it should look like at the end:

How to Run an Arduino for Years on a Battery

First, put the microcontroller in the center of the breadboard. You can then take care about the power: connect power lines on each side, connect the negative power rail to the two GND pins of the microcontroller, and the positive power rail to VCC, AVCC, and AREF. Also, add the 10uF capacitor between two power rails. Finally, add the battery to the system.

You also have to add the crystal between the X1 and X2 pins, with 22pF capacitors going from each pin to the ground. Also, you need to connect the RST pin to the positive power rail using a 10K Ohm resistor. To see if the system is working, connect the green LED in series with a 220 Ohm resistor to the digital pin 13 of the Arduino board, the other side going to the ground.

This is the complete schematics of the project:

How to Run an Arduino for Years on a Battery

Testing your Arduino system

It’s now time to test if the hardware part is working. What I did in this project is to use the Arduino Uno board to program the chip, and then I just “transplanted” the chip on the breadboard. You can just use the default “blink” sketch to program the microcontroller. After this is done, just replace the chip on the breadboard, and plug your battery (my battery pack even has a nice on/off switch). The LED should just goes on and off every second as expected.

Optimizing for Low-power

So now, we have an autonomous Arduino system. But it still consuming way too much power. Indeed, even when the LED is off, the Arduino chip is still active and consumes power. But there are functions on the microcontroller to put it to sleep during the time it is inactive, and re-activate the chip when we need to change the state of an output or to perform some measurements. I tested many solutions to really reduce the power to the lowest value possible, and the best I found is the JeeLib library. You can just download it and install it by placing the folder in your Arduino/libraries/ folder.

This is the sketch I used:

#include  // Low power functions library
int led_pin = 13;
ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Setup the watchdog

void setup() {
 pinMode(led_pin, OUTPUT);
}

void loop() {

 // Turn the LED on and sleep for 5 seconds
 digitalWrite(led_pin, HIGH);
 Sleepy::loseSomeTime(5000);

 // Turn the LED off and sleep for 5 seconds
 digitalWrite(led_pin, LOW);
 Sleepy::loseSomeTime(5000);
}

You basically just have to include the JeeLib library with:

#include 

Then initialize the watchdog with:

ISR(WDT_vect) { Sleepy::watchdogEvent(); }

Finally, you can put the Arduino to sleep for a given period of time with:

Sleepy::loseSomeTime(5000);

Upload the sketch with the Arduino IDE and replace the chip on the breadboard. You should see your Arduino having the same behavior as before (with 5 seconds intervals). But the difference is that now when the LED is off, the Arduino chip doesn’t use a lot of power. To finish this article, I wanted to actually quantify the power consumption of the system we just built. You can do the exact same by placing a multimeter between one of the power lines. For example, I connected the positive pin of the battery to one pin of my multimeter, and the other pin to the positive power rail of the breadboard. Here are the results:

  • LED off, without the JeeLib library: 6.7 mA
  • LED on, without the JeeLib library: 8.8 mA
  • LED off, with the JeeLib library: 43 uA (!)
  • LED on, with the JeeLib library: 2.2mA

From these results, we can see that our breadboard-Arduino consumes 6.7 mA when doing nothing without caring about putting it to sleep. For information, that will drain your two batteries in about a month. Which is actually not so bad, but we can do better. With the sleep functions, this can be reduced to 43 uA, which is a 150x improvement.

Let’s do some calculations to see how it will impact a real project, for example a temperature sensor. It takes about 500 ms to perform a measurement, at about 2.5 mA of current. Then, the systems sleeps for 10 seconds and the loop starts again. The “mean” is then 0.16 mA over a complete loop. With batteries rated at 2500 mAh, it means in theory the system will last … nearly 2 years without changing the batteries! Of course, some other effects will actually modify this number, but it gives you an idea.

How to Go Further

Really, you can adapt this idea to every system where the active time is small compared to the sleep time, and make your Arduino last for years without changing the battery! If you want to learn more about the topic, note that there is a complete guide on how to build your own systems from scratch in our Home Automation with Arduino product.

Want to learn more? Get my free eBook about Arduino!

Arduino is an amazing platform that you can use to build all sorts of projects. Download today my free eBook "Building a Simple Alarm System with Arduino". Simply click on the button below!

Leave a Comment

Please enter your name.
Please enter your email.
Please enter your comment.
Cikgu Aze 2 years ago
I have built same project a few years ago with microchip 12fxx series. Consume only 12uA during sleep. I use ucurrent gold from eevblog for current measurement. Scroll down this blog you will find ultra low current led flasher http://simf1.blogspot.my/20...
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Gustav Gullstrand 2 years ago
Why can't I read the article even though I follow the Get startet button and signing up on the newsletter?
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
brandan 2 years ago
Thanks for the great article. Thanks to you I now build most of my uno like projects myself starting with the chip. On a recent build I needed a regulated power for an external device and I started messing around with a MCP1700 power regulator and I found that using regulated power which lowered the voltage from the ~4v with the 3 AA batteries that I have been using to a solid 3.3v actually reduced my total power usage. So might reconsider the voltage regulators, but need to get the right kind.Brandan
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Rudi 2 years ago
What good is it that the Arduino can run so long on a set of batteries? The example, with a temperature sensor doesn't really mean much - since you would probably want to do ^something^ with the temperatures collected, whether you want to write it to an microSD card, or transmit (wireless / 3G / bluetooth / LAN / ??) somewhere to be processed.While I do understand that one can run an MCU at really low power, I can't quite see the practical use of it.
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Joe B Rudi 2 years ago
I plan on using it to create an alarm. So it will sit dormant for months without being used and only run when a switch is activated.
Gabriel 3 years ago
congratulations for the article! what will be the logic levels when you feed the microcontroler with 3v? HIGH will be 5v? 3v? thanks!
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
AdrianZ41 3 years ago
Great article!! just what i needed for my project. Quick question though. If I wasnt to use 4 AA batteries within my project (as I need to run a 4-6v Pump) do I need to put any voltage protection in place to not overload the chip?
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Ronaldo Brandão 3 years ago
Good Morning. I made the assembly of the standalone with the sleep mode, but can not get consumption below 2mA. You can help?the ATMEGA328P-PU is configured with internal clock 8Mhz.
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Luis Minvielle 3 years ago
Hi Marco, the whole guide looks appealing. I'm not savvy on electronic issues but I'll be trying to replicate this tutorial. At least I'll learn, even if its by tidbits.Marco, I've been using a controller to move a servo motor via the Internet, using a web server. So, I've been connecting the controller to the internet (via Ethernet), and to a wall outlet for power purposes (12v, 2Am). This is, my controller has 2 cables, one for power and the other for connecting it to the internet.I have to do connect this same controller once again, but wirelessly. So, I've been thinking of shifting to Arduino and following your tutorial to ditch the power supply.But what about connecting to WiFi? Ain't it too power-demanding? I've been checking the "WiFi shields".What I need to do with my device is connecting it to a Web Server (thru Internet) so as to tell the Arduino: "move a Servo motor". That's it. The Web Server should be always online, but maybe Arduino shouldn't be!As I'm clueless on the electronics universe, I can't make the reasoning behind this implementation. Do you think it's possible? Making the batteries last for a couple of months, then changing them, is completely fine to me.
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Marco Schwartz Luis Minvielle 3 years ago
Hi Luis, interesting question. The whole 'trick' in this project is that it is only adapted for projects that can be on for a short time, and off for a long period of time. So even with a WiFi shield that will suck a lot of power, it's ok if your project just need to send data for a few seconds before sleeping again.
nadc 3 years ago
Help! I followed the instructions exactly, I uploaded the "Blink" program to the ATMEGA238P-PU from another Arduino then I installed the chip on the breadboard and connected all the components exactly as described. The led is off and not flashing. See attached image.Things I already tried:- Had the ATMEGA + led + 220 ohm resistor installed on the Arduino Uno board. It starts blinking as expected, the ATMEGA chip doesn't seem to be dead.- Connecting the led + 220 ohm resistor to VCC and GND. It works, so the led and the resistor are good.- Swapped every component out with another identical one, one at a time. That did not help.What else can I try? If anyone has any suggestions, it would be greatly appreciated!
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
nadc nadc 3 years ago
I figured out my solution thanks to help from StackExchange: http://electronics.stackexc.... I had to add a 3rd battery.
AndrewS 3 years ago
This seems to be an interesting solution to run "Arduino" on batteries: https://bitbucket.org/talk2...According to the documentation the whole board consumes less than 4uA when sleeping and can be powered by a single AA.
Reply
Please enter your name.
Please enter your email.
Please enter your comment.
Moebius L. AndrewS 3 years ago
Cool, I got a few of those boards from here: https://talk2.wisen.com.au/... and it's already working for at least three months reporting temperature and humidity from my attic. I'm using 2 AAs and the voltage only dropped from 3.14 to 3.09... expect it to run for a few years! :)
Grant Anderson 3 years ago
Great article! I didn't know about the JeeLib libraries at all. What an eye opener. I should mention something interesting about battery life. As everyone is aware, as the battery ages it will lose it's voltage and continually decline to a point where it's not producing enough voltage to run the Arduino. However, it still contains plenty of energy and more than enough to power the Arduino for a long time to go. So how do you get the extra bit of energy? Simple. If one attaches a tiny little device known as a joule thief, it will sustain the full voltage through out it's entire life and will even draw out all of the energy of the battery until it's absolutely depleted. Look on Youtube for Joule thief circuit and a video of it's inventor (or at least the guy who realized it's potential and gave it the name "joule thief." It's incredibly easy to make with a little piece of iron ferrite and some thin insulated wire and a transistor. The voltage can be "smoothed," by adding a 100uf to 680uf capacitor at it's output.
Reply
Please enter your name.
Please enter your email.
Please enter your comment.