How to Run Arduino for Months on a Single Battery

How to Run Arduino for months on a single Battery

Hello and Welcome to Alpha Electronz.!We provide Tutorials (Post + Videos) about Projects based on Arduino, Raspberry Pi, etc.

Today’s tutorial is about running your Favourite Arduino Uno for a long time on stand-alone! So let’s start.

For the 99% of the Times, Your Arduino based Projects are always connected to a Laptop through USB or a DC Adapter for supply. But sometimes you cannot just supply continuous Power to your Arduino Board because of some reasons.

Then you need to manage the supply provided to your Arduino Efficiently. So we are going to build a circuit which won’t consume all the power from your batteries in just an Hour. There are two steps in this Tutorial,

  1. Implement the Hardware
  2. Optimization for low power consumption

Step no 1 –

Implementing the Hardware

Arduino IC and ATMega328p pin Mapping

For implementing the Hardware for this tutorial we will need the ATMega328P Bootloaded IC, Osceola capacitors, breadboard, battery, the full list of components required for this tutorial is given below:

Schematic

Schematic of Running Arduino for months on a single Battery

Above is the complete schematic of the Tutorial. Connect all the components on a breadboard. The circuit should look like these.

Source – OpenHomeAutomation

Testing the circuit

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 go on and off every second as expected.

Blink test code

int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

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.

#include<JeeLib.h>  // 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 <JeeLib.h>

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.

Hope you understood this tutorial.

If you like it then subscribe to our newsletter.

If you have any doubt feel free to ask in the comment section. 

0

Leave a Reply

Your e-mail address will not be published. Required fields are marked *