LongSleep

Back to Arduino Interrupts
The requirements for this example are:

  • “sleep” for an hour while monitoring pin 2 for rising edges
  • Report the hourly count

The code is too long to post, so I just uploaded a file with the code here.

The trick to get this working was to enable the watchdog timer duration to be 8 seconds.  I did not reset the watchdog timer in the ISR or in the reporting code or anywhere else.  It just keeps on firing an interrupt every 8 seconds.  The ISR just increments a count.  To sleep for an hour, I sleep for 8 seconds 450 times.  Well, the WDT oscillator is not that accurate and I had to tune that down to about 398 seconds.  Depending on voltage, temperature, and individual processor, the exact value will need to be determined experimentally.

I am using an Ethernet Shield to report the hourly results to a SparkFun data stream.  If you want to post data for your testing, you will need the private key.  Send me email or post to the mailing list to get the key.  I was thinking of publishing it right here, but that key allows you to clear and delete the stream.  If someone deleted the stream, that would be a bad thing.

This code puts the processor in the deepest sleep, but there are additional things you can do to further reduce power consumption while sleeping.  Do some web searches and look at the ATmega328P datasheet to see what you can turn off to save power.  Voltage regulators, internal and external pullup and pulldown resistors, voltage divider circuits, brownout detector, A/D, … are all examples of things to take notice of.  There are several sites that give current measurements as they strive for minimal consumption.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Triangle Embedded Interest Group