Sleep(ms)

When not busy, I want to put the Arduino asleep. It will wake up one of three ways:

  1. power cycle (i.e. reset)

  2. hardware interrupt - For example, the user presses a button which is tied to pin 2 which is monitored by attachInterrupt(). Fairly straightforward and well documented.

  3. sleep(time) - When a certain amount of time has elapsed (10 seconds, 4 hours, whatever), the Arduino should wake itself up. The delay() function would work but I want the power savings of sleep.

The sleep functions (</avr/sleep.h>) don't use any kind of time delay which means a hardware interrupt is the only way to wake up. I want a timer interrupt.

Looking at various AVR code it looks like timer2 should be able trigger an interrupt (ISR). Unfortunately I don't know how to do this and I can't find any good examples.

Has anybody written a Sleep(time) function? It seems to me that sleep(time) should even be part of the core library. Is it really that difficult or am I missing something obvious? If someone can point me at documentation for a potential solution, I'd appreciate it.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1291420085

Thanks for the link. Too bad there's not a more concise synopsis somewhere. Reading through that forum page answers some questions but is far from straightforward.

Here's a much better link: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/

And another: http://www.jasoncavett.com/2011/03/accessing-watchdog-timer-on-arduino-uno.html

"nightingale" is an unusual, but useful search term:

http://arduino.cc/forum/index.php/topic,59867.0.html