Arduino resets when disabling Watchdog Timer!


While working on a small arduino project that will run on batteries I needed to enable deep sleep mode to reduce the energy consumption when not needed until the arduino is awaken by an external interrupt.  However, I am also using the Watchdog Timer (WDT) to make sure the system will not hang up or get into in infinite loop due to some bug or unknown situation. The maximum time that the WDT on the Atmega328p supports is 8 seconds, and if 8 seconds has passed before calling wdt_reset() the WDT will reset the microcontroller, however, my boards will sleep for way longer than 8 seconds so I have to disable the WDT before going to sleep and enable it back once waken up.

Disabling WDT should be an easy thing to do by simply calling wdt_disable(), however, calling this statement also caused the atmega328 to reset!

After looking into the content of the header file “avr/wdt.h” it seems like the Arduino IDE or AVR compiler (not sure who is responsible) is not defining the correct board/chip even though I set the correct board & processor in the Arduino IDE. And the way I solved the issue was to define the correct microcontroller before including the wdt.h:

#define __AVR_ATmega328P__
#include <avr/wdt.h>

Now the code works as intended without causing a reset.


 Previous
Let your Arduino get enough sleep Let your Arduino get enough sleep
To enable 1hr Arduino sleep, the author leverages ESP8266's deep sleep. ESP8266's wake-up pin triggers Arduino INT0, which then resets ESP8266 for full activation.
Next 
Add Wireless charging to your car phone holder Add Wireless charging to your car phone holder
A DIY car phone holder with integrated Qi wireless charging. Modified a bare board charger, trimming & painting it, then mounted it into a vent holder for easy phone charging while navigating.
2015-08-28