>> WATCHDOG TIMERS (WDT) - MAXIMIZING POWER USAGE ON THE ARDUINO
This type of dog wont be chasing the mail man or other intruders any time soon.
Do you have an
Arduino
project configured to periodically gather some sensory information and you
are noticing it draining power quickly while waiting for the next interval?
Do you want to get the maximum operating period on those small batteries?
Then it is time to consider implementing a WatchDog Timer (WDT) so conserve
power when it is not in use.
So, what is a watchdog timer?
While typically used to detect when a computer system crashes or becomes
unresponsive - it can also be used to wake up a device if it has been on
purpose put into a power down state; something that becomes applicable to
saving power and reducing power consumption.
You could theoretically write your own; using the in-built features of
the Atmel AVR platform - specifically the <avr/wdt.h>,
<avr/sleep.h>, <avr/power.h> and
<avr/interrupt.h> headers or you could use a third-party
library and save yourself a few headaches.
I found the above four libraries; some in better states than others and
depending on the type of open-source license you are looking for the
one you decide on will vary. I took a look at the code state of each
project and I believe the "Low-Power" library is streamlined well and
very simple to integrate into an existing Arduino project.
The Low-Power library provides three example cases; either to
put the device in idle mode for a short timeframe or do a full power
down and wake-up after a period of time or after an external interrupt
occurs (ie: Serial, sensor or a network event).
#include "LowPower.h"
void setup()
{
// No setup is required for this library
}
void loop()
{
// Enter power down state for 8 s with ADC and BOD module disabled
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
// Do something here
// Example: Read sensor, data logging, data transmission.
}
The above code puts to device to sleep for eight seconds
(the maximum interval provided by the AVR hardware) - you could
make multiple requests to extend this (2x8 = 16 seconds) or if you
want you could hook up an
external timer and trigger the wake-up with an interrupt. It also
increases the basic compiled sketch size from 450 to 642 bytes
(using 1.5.x IDE) and adds a single byte of dynamic memory for the
LowPower reference object - minimal for the job.
But while it sounds great - there is a small caveat; power reduction
relies not only on software but it also relies on the hardware used
(off the shelf devices are not very power efficient).
I found a great
blog post
comparing the power consumption of an Arduino UNO by default with a
watchdog timer (45.6mA vs 34.4mA - a small reduction) and using a custom
board removing any power hungry components such as regulators and LEDs;
to get right down to µA levels. Rocket Scream have a
blog post outlining
similar results.