Arduino – Enabling and using WatchDog timer

Spread the love

By default in official Arduino documentation no any information about WatchDog timer. WatchDog timer (WDT in short) – is a hardware external timer that reset the microcontroller if the main program crashed or go to the infinite loop or etc error action.

How does it work? Need set interval (for example, 1 second), during which the main program must reset the timer. If timer didn’t reset – watchdog will restart controller.

For Arduino, need to add additional library wdt.h, set timer interval and add reset function (wdt_reset()) to the main loop.

Sample:

#include "avr/wdt.h"
void setup() {
wdt_enable(WDTO_4S);
}
void loop() {
wdt_reset();
}

Table with constants for wdt_enable function.

Constant nameConstant valueDelay
WDTO_15MS015 MS
WDTO_30MS130 MS 
WDTO_60MS260 MS
WDTO_120MS3120 MS
WDTO_250MS4250 MS
WDTO_500MS5500 MS
WDTO_1S61 S
WDTO_2S72 S
WDTO_4S84 S
WDTO_8S98S

 

Leave a Reply