Watchdog Timers – how to reduce power usage in your Arduino projects

Aaron ArdiriBlogs

Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+

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 your device can power down while not in use.

So, what is a watchdog timer?

A watchdog timer (WDT); sometimes called a computer operating properly or COP timer, or simply a watchdog – is an electronic timer that is used to detect and recover from computer

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 trying to perfect an implementation on your own.

Library Repo Links License
Low-Power Project Home, Blog CC-SA 3.0
JeeLib Project Home, Wiki MIT
narcoleptic Project Home GNU GPL v3.0
Enerlib Project Home undefined

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 example puts to device to sleep for eight seconds (the maximum interval provided by the AVR hardware) – you could make multiple requests to extend this (2×8 = 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 and unfortunately a lot of off the shelf devices are not very power efficient due to extra electrical components.

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.

The use of watchdog timers in your project could make a drastic difference to the amount of information your Arduino projects could gather and transmit to the cloud; this information could then be displayed on a mobile device by writing an application in Evothings Studio. You’ll find plenty of templates to use in your own projects at the Evothings Studio website for controlling and monitoring your Arduino projects.