Everyone who wants to use the Arduino on a battery or an akkupack over a longer time knows the problem: How do I supply it? Of course, you can use a huge akkupack, but the more elegant way is to set your arduino - better said the ATmega 328 - in an energy saving mode. How this works you will find here.
The few lines of codes are on GitHub.
What stays behind? First of all I want to show the diffrent methods, how you can save energy:
- Turn off all unused devices. I mean LED's, displays and modules. But note: the hardware of these modules must be able to handle it!
- Set all unused pins to "INPUT". This state uses less currency on the ATmega.
- Turn off the analog to digital conversion. You should only do this when you don't need it.
- Reduce the clock speed. This you can only achieve by changing the hardware.
- Turn off brown-out. This is used to determine very small changes of voltage. Therefor an even smaller voltage is used as an comparison voltage.
- Set the Arduino into the energy saving mode.
The program works with interrupts. When such an interrupt is recognized on a pin a connected function is called. In this case the functions name is interruptHandler.
attachInterrupt(0, interruptHandler, RISING);
RISING means that the function is only called, when the voltage on the pin switches from the logical level 0 to 1 (0V to 5V).
This interrupt will be caused by a button click. Clicking the button starts the energy saving mode and also terminates it.
The function sleepMode goes through every neccessary point that set the controller to energy saving mode.
noInterrupts(); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); interrupts(); sleep_cpu();
Durring the initialization the interrupts have to be disabled. Otherwize it could happen during the process and you controller sleeps forever.
That's it. You can implement the sleepMode-function everywhere in your code. It doesn't need to be started by an interrupt.
It is simple. Just add a button on pin 2, but don't forget the 10kΩ resistor!
This structure is enough to set the Arduino to an energy saving mode. Unfortunately this is not really purposeful, because the modules on the Arduino board itself needing a huge amount of energy. Especially the serial communication, but also the voltage converter needs many.
The better way is to build your own Arduino. You can achieve this in a few steps and with cheap components as well! The following two pictures shall show you how to do it.
What you need:
You can easily connect a power bank on the USB-jack (or another power supply). This way you are using your Arduino standalone. First of all you have to let the ATmega in your Arduino board. Then you upload the program code. After this step you have to carefully remove the ATmega from the Arduino board and place it on the breadboard.
Here I want to show you the advantages of the energy saving mode:
- The Arduino UNO needs in its unchanges form without the energy saving mode 50 mAh. That's quite a lot.
- Is the energy saving mode on: 34.5 mAh. You can see, we saved energy, but not much.
- The standalone version needs without energy saving mode only 15.15 mAh. That's much better, because there is no serial communcation anymore.
- And if you turn on the energy savong mode now: 0.6 μAh ( = 0.006 mA ). Whoah!
If the Arduino is supplied with a battery that has 0.05 Ah, it would last one hour. The selfmade board (with mode on) lasts 8333,3 hours. That's almost one year!
Questions and comments: deloarts.wordpress.com