Go Down

Topic: Waking Arduino once per minute on timer based int (Read 4448 times) previous topic - next topic


Hi - I am fairly new and am struggling to figure out for a battery powered application how to sleep the Arduino but wake it say once per minute to do some work, then sleep again.  I dont want to use external interrupt as that would require more circuitry and 555 timer or similar and would use valuable battery power.

I think I need to use the timers and prescalers, and that I need to use a timer based interrupt to trigger which will wake the chip up again, but how?

Surely someone must have done this?

Hope someone can help with this!



You can use an RTC, and take advantage of the programmable square wave output.


OK - do you have a suggested RTC chip that can generate a suitable square wave?

I dont need exactly 1 minute intervals - timing is not critical, but battery life is so any way to wake the arduino regularly without consuming much power is what I need.

Thanks in advance!

Using the timers and interrupts within the arduino the slowest trigger I could find was about 60 times per second!

Coding Badly

Apr 28, 2009, 09:40 pm Last Edit: Apr 29, 2009, 06:19 am by bcook Reason: 1
Have you looked at this...


- Brian


Thanks florinc - I will check out the datasheet.

I just noticed though that Timer1 is 16 bit though rather than 8 bits, so if I can use that like the Timer2 interrupt presumably it will overflow much slower, maybe any seconds or more?

Spent a couple of hours reading the Mega168 datasheet and cant figure out how to do it though...arghhh!

Anyone a master of the timers, overflows, sleep and interrupts?


Brian - having perfected a low power 555 timer circuit to wake my device every minute, and convinced myself thats the way to go, I just studied the Nightingale program you posted above and it works!  It only gets me a max of 8 second sleep but I can easily link 8 or so toigether to get close to a minute, without the need for extra electronics.

Thanks for the suggestion.  My only concern is that I dont fully understand how it works, but more time on the datasheet will no doubt help!

Coding Badly

May 06, 2009, 03:09 am Last Edit: May 06, 2009, 03:11 am by bcook Reason: 1
Bear in mind that...

  • The watchdog timer is not terribly accurate.  My current test board (based on the AT90USB162) is slow by about 7½%.  I believe the watchdog timer can be off by ±10%.

  • The Nightingale example uses SLEEP_MODE_PWR_DOWN.  In this mode, with this processor, all the timers are shutoff and remain off after the processor wakes.

The documentation for this processor is a bit sparse on the watchdog details.  I plan to spend some this week researching (especially SLEEP_MODE_PWR_DOWN).  If you're interested, I'd be happy to publish details when I have them.


Coding Badley - definitely - anything you can find would be of interest for sure, and vice versa.  I'm using Arduino pro mini.
Like I said above what I really want is to wake the chip from sleep periodically (say once per minute).  Power consumption is critical as I need several years life from 2 x AA, so it needs to be as efficient as possible.  


A back of the napkin calculation on this requirement (2 AA (unchanged, I assume) batteries for several years) results in a max current of less than 100uA, doesn't it? Also, assuming that the batteries don't deplete by themselves, this is a pretty tough requirement. (I used 8760 hours in a year, 2000mAh per battery).


Yep - but the chip is only taking 50uA in sleep mode, and thats the Arduino pro mini which has an annoying tiny red LED that I need to desolder!

Providing I can keep the sleep to 99.9% and only awaken do process quickly then sleep I should be ok.

But I guess you can see why I really want the chip to sleep for a minute or more rather then the 8 seconds that I have managed so far...

My current solution is to sleep for 8 secs, then wake and add a counter.  If gthe counter reaches 8 then zero it and do processing, else sleep.  It gives me 64 seconds which I can live with, but it does mean that I am waking up much more often than I want which ultimately wastes power.

Coding Badly

With the right settings, the watchdog can be set to fire after 112 seconds (almost two minutes).  

Do you need help getting that to work?

- Brian


Brian - definitely - that would be a great help.

How do I do it?  I have the Nightingale program working and giving me 8 seconds sleep.  How can this be made longer?  I've search everywhere on this but got to the conclusion that 8 seconds is the limit?

Coding Badly

May 10, 2009, 07:49 am Last Edit: May 10, 2009, 10:10 pm by bcook Reason: 1
First, some things I've discovered...

  • The watchdog timer is very inaccurate.  My test processor is typically long by about 11%.
  • The watchdog timer is affected by temperature.  The clock runs a bit faster when the processor is cooler.
  • Shorter delays run longer.  Note: I cannot fathom why this one is true.  I suspect there's a bug in my measurement code.
  • There's some "jitter".  I've seen differences of as much as 0.2% between successive tests.
  • There's some "drift".  I've seen differences of 1% over the course of a day.
  • A high pin driving an LED slows the clock by about 0.02%.

Now for your question...

How do I do it?

You have to set the "Watchdog Timer Clock Divider".  I've put code here...


...that should help.  The code should let you set the time-out to any valid value.

Some notes about the code...

  • I currently only have an AT90USB82 processor for testing.  I have no idea if the code works with other processors.
  • I tried to follow the datasheet to the letter but it's a bit contradictory and a bit vague.  I could easily have gotten something wrong.  Test the code thorougly and use it at your own peril.
  • The "WatchdogTimeoutInfo" array and its type definitions "TrdWatchdogTimeoutInfo" and "TrdSleepDuration" are not used; you can remove them.
  • Before running the code, change "PIN_LED_ONBOARD" to a pin with an LED connected.  I believe Arduino compatible boards have an onboard LED on pin 13.

Good luck,

Todd Houstein

Hi Brian,
Your code is great, but unfortunately the ATMega168 and ATMega328 (which I believe come with the Arduino Duemilanove, which I have on order) do not have watchdog clock dividers, unlike the AT90USB82 that you are using.

This means that the maximum time between watchdog interrupts for the Arduino Duemilanove is 8 seconds... Bummer!

Looks like the best I can do is what r55boy suggested... waking it up every 8 seconds to increment a counter then putting it back to sleep again... On every n wake ups execute the main code.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131