Feed on

Ever wanted to know how to reduce the power consumption of your Atmel microcontroller when it’s not doing anything? The 2 videos below will step you though how you can reduce the power consumption of your Atmel microcontroller (in this case the ATtiny85) by using the power down sleep mode with the Watchdog timer.

The beauty of the watchdog timer is it allows us to not require an external interrupt to wake up the microcontroller, instead it wakes up after a certain amount of time by itself.

Link to the modified example for ATtiny85: ATtiny85_watchdog_example
Power consumption calculator: http://oregonembedded.com/batterycalc.htm
ATmega168 Sleep Watchdog website: http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery/

12 Responses to “Reduce ATtiny power consumption by sleeping with the Watchdog Timer”

  1. James Printer says:


    How did you get your ATTiny to work with the Arduino IDE? I’ve been using AVR Studio for this, but I’d love to use Arduino IDE as I’m used to it from using my Duemilanove/ATMega328.


  2. James Printer says:

    Awesome, thanks! Saves me buying an ISP programmer.
    I think I may have to use AVR Studio as I have a ATTiny13. I suppose I could try and modify the ATTiny45/85 ZIP file too, I expect they are very similar both having 8 pins. I’d gain the advantage of not having to learn hex codes to do everything like in AVR Studio 🙂

  3. Ben says:

    This is an awesome tutorial. I will be making an auto filling water bowl for my dogs. I was looking at the code and was wondering if I can make the attiny85 sleep longer than 8sec. I really only need to check the level once a minute. I see, in setup_watchdog, that if ii>9 it will be set to 9. Can this number only be a single digit?

    • Alex says:

      Hi Ben,

      The maximum sleep time for the watchdog timer is 8 seconds (9 value), this is taken from the ATtiny25/45/85 datasheet on page 32.

      Potentially you could just have a counter variable which would count to 7 or thereabouts (7 x 8sec sleep = 56sec) which is incremented/compared and once it reaches 7 it runs your water level check code. The downside is that it will always wake up every 8 seconds however the power consumption used when waking up, checking the counter variable and then going back to sleep would be small, it would probably only last 50ms. An example is shown in Standalone Temperature Logger Part 7.

      However if really sleeping for 1 second is required, then the ATmega168/328 might be the way to go, it costs more and is larger. On page 39 of the ATmega168/328 data sheet it shows that it can be woken up by timer2 so potentially you could configure timer2 to count up to exactly 1 second by selecting the right prescaler and/or enabling the compare. I think a separate clock source is needed though.

      So the easiest solution is to use a counter and watchdog timer if exact timing isn’t that important and extreme battery life isn’t needed.

  4. Ugi says:

    Great article.

    I tried to adapt this for a project of mine and discovered one feature – the current code only works becuase you sleep for longer than you are awake (you sleep for 4s but are awake for only 1). If you set the watchdog timer for a short period and then stay awake for longer (e.g. sleep 1, wake 4) the next time the WDT times out it will reset the AVR rather than issuing an interrupt.

    All you need is the line: “WDTCR|=B01000000;” inside the WDT ISR routine. That resets the WDT to issue another interrupt rather than a reset next time (sets WDTIE). See the datasheet at 8.5.2 (p 47) here: http://www.atmel.com/Images/doc2586.pdf



  5. […] I always use sleep mode for the lowest power usage when not transmitting. It’s set to transmit about once every 6 minutes. There are several sleep mode routines for the ATmega processors, but the ATtiny needs entirely different registers set. I found good info on sleep mode, and good tutorials for the ATtiny at brownsofa.org and Inside Gadgets. […]

  6. […] fare quindi un po’ di esperimenti con l’Attiny85 in sleep mode basandomi sul codice di insidegadgets, riuscendo ad ottenere un consumo di circa 4.5uA in standby, e di circa 3mA durante il lampeggio […]

  7. […] battery. I started so a little experiments with the ATtiny85 low power modes using the sketch of insidegadgets, achieving a power consumption of about 4.5uA in standby and of about 3mA during the led flash that […]

  8. […] in order to reduce the conflicts of having other motion sensors on the same band. I also used some code from Alex for running the ATtiny at low power, so it is battery […]

  9. ed says:

    after looking at the code, there seems to be some superflous commands in there if I am not mistaken
    The system sleep routine issues the commands:
    sleep_mode(); // System sleeps here
    sleep_disable(); // System continues execution here when watchdog timed out

    But if I look in sleep.h and see how ‘sleep_mode() actuallyis defined, I see this:
    636 #define sleep_mode() \
    637 do { \
    638 sleep_enable(); \
    639 sleep_cpu(); \
    640 sleep_disable(); \
    641 } while (0)

    So, in fact ‘sleep_mode()’ already does a sleep_enable() and a sleep_disable()

  10. Yves says:

    If I read the datasheet correctly, 7.1.3 Power-down Mode, the INPUT ports are the ones that stay enabled, so you want to turn any INPUT port into an OUTPUT port before sleeping, not the other way around. Furthermore, according to table Table 7-1 the ADC is automatically turned off in power down mode, no need to do that.

Leave a Reply