Reset Bits after WDT Setup

Hi there,

I’m making my Arduino periodically wake up using the WDT and 'SLEEP_MODE_PWR_DOWN" and I’m using this bit of code from this website to set up the WDT bits.

void WDT_setup() {
  MCUSR &= ~(1<<WDRF); // Clear the reset flag
  // In order to change WDE or prescaler, we need to set WDCE
  // (this will allow updates for 4 clock cycles).
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  WDTCSR = 1<<WDP0 | 1<<WDP3; // Set watchdog timeout prescaler value, 8s
  WDTCSR |= _BV(WDIE); // Enable the WD interrupt (note no reset)

However, my question is, if while the code is running, I wanted to sleep the Arduino indefinitely instead of periodically waking up, how do I clear those WDT settings back to default so that these commands


make it sleep indefinitely without waking up until the RESET button is pressed?


Stop the WDT by clearing the appropriate bits in the WDT control register.

The ATMega328 data sheet explains the procedure.

I understand I have to clear the appropriate bits, but could you please point me in the right direction at least? Like a page on the spec sheet, etc.? Thanks.

EDIT: looks like the datasheet talks about the MCUSR and WDTCSR registers on page 54, but I'm not sure what sequence of commands I need to use.

Is it just turning off the WDT like this, show on page 52?

void disable_WDT() {
  MCUSR &= ~(1<<WDRF); // Clear the reset flag
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  WDTCSR = 0x00;

The beauty of Arduino is that you can try something and see if it works, in a matter of minutes!