Suppose we want to save battery power, and we use sleep mode and also prevent the Arduino from hanging and use the watchdog timer.

The problem is here that when the Arduino goes to sleep the watchdog timer never (or can't be) reset again because of sleep and it will overflow over and over and reset the Arduino over and over.

So what do you suggest to solve this problem, I mean running sleep mode and watchdog timer at the same time in a code?

  • 1
    Please show us the sketch you're using.
    – VE7JRO
    Commented Mar 17, 2020 at 19:59

2 Answers 2


When you sleep the Arduino is locked up. So yes, the watchdog timer will time out and reset the Arduino.

But, since you're in sleep mode, it's not so much a "reboot" as a "wakeup".

The watchdog timer is one of the normal ways of waking up periodically to do things. If you want to use the watchdog for its other "anti-lockup" purpose then you will have to arrange some other way of waking up before the watchdog is due to expire so you can "kick" it.

Or you disable the watchdog entirely before going to sleep so that the only wakeup source is whatever source you have configured. Then you can turn the watchdog on again when you wake up.

However that probably means that the watchdog is useless, since chances are you won't be awake for long enough periods for the watchdog to have any effect.

Sleeping and using the internal watchdog as a watchdog are pretty much mutually exclusive. If you sleep, then the watchdog is a periodic wake-up source.

  • If you set the arduino to sleep while the watchdog is running, the arduino will reset after the set amount of time. Unless you set the watchdog to trigger an interrupt. The watchdog isn't a wake-up source, unless you set it up as one. Also note that the watchdog unsets the interrupt when triggered. This is so that, if the program hangs, the first timeout it will call the interrupt, and the second timeout will cause a reset.
    – Gerben
    Commented Mar 18, 2020 at 13:20

Either set the watchdog to 8s, and setup the WDT interrupt. And deal with the fact that the MCU wakes up every 8s. You could have it go back to sleep, unless a button is pressed, or something. The extra power usage for these short wakeups is negligible in most cases.

Or disable the watchdog right before sleeping, and enable right after waking up. And hope the MCU never hangs in between.

  • the periodically reset(or reboot) doesn't hurt the MCU?
    – sepehr
    Commented Mar 19, 2020 at 16:36
  • No. Won't hurt the MCU.
    – Gerben
    Commented Mar 21, 2020 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.