Include the header file:
#include <avr/wdt.h>
Enable the WDT
Typically in your applications setup() function
wdt_enable(WDTO_1S);
Possible issue: We’ve had issues with the watchdog enabled and program uploading never leaving the “Uploading…” stage, where disabling the watchdog would fix the issue. There may be a need to delay turning on the WDT at start – TBC.
Available time periods:
ATMega 8, 168, 328, 1280, 2560:
WDTO_15MS (15 ms )
WDTO_30MS (30 ms)
WDTO_60MS (60 ms)
WDTO_120MS (120 ms)
WDTO_250MS (250 ms)
WDTO_500MS (500 ms)
WDTO_1S (1 sec)
WDTO_2S (2 sec)
Reset the watchdog
For instance in your main loop
wdt_reset();
