can anyonelet me advice to change watchdog timer?

Hello :slight_smile:
I want to make arduino sleep for 5minutes(or more) and wake up! and sleep again...
I found an example as below and is implemented very well. but I don't know how to change time which is sat 8 seconds.

help me to change time :slight_smile:

setup(){

  /*** Setup the WDT ***/
  
  /* Clear the reset flag. */
  MCUSR &= ~(1<<WDRF);
  
  /* In order to change WDE or the prescaler, we need to
   * set WDCE (This will allow updates for 4 clock cycles).
   */
  WDTCSR |= (1<<WDCE) | (1<<WDE);

  /* set new watchdog timeout prescaler value */
  WDTCSR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds */
  
  /* Enable the WD interrupt (note no reset). */
  WDTCSR |= _BV(WDIE);
}
void loop(){


if(f_wdt == 1)
  {
    /* Toggle the LED */
    digitalWrite(LED_PIN, !digitalRead(LED_PIN));
    delay(2);
    Serial.println("waked up! and sleep for 8 sec");
     delay(2);
    /* Don't forget to clear the flag. */
    f_wdt = 0;
    
    /* Re-enter sleep mode. */
    enterSleep();
  }
  else
  {
    /* Do nothing. */
  }

}

8 seconds is the max value supported by hardware. For longer timeouts, you will need to add some loop that counts watchdog timeouts until enough of them have passed to equal your total timeout.

kotran:
I want to make arduino sleep for 5minutes(or more) and wake up! and sleep again...

Well you cannot, using the watchdog.

As has been mentioned already the watchdog has a maximum time of around 8 seconds.

So if for example you wanted to 'sleep' for 24 seconds you would need to;

Sleep for 8 seconds
Wake up
Sleep for 8 seconds
Wake up
Sleep for 8 seconds
Wake up
Carry on with program.

get an external watchdog

WDT
https://www.digikey.ca/en/articles/techzone/2012/may/a-designers-guide-to-watchdog-timers

See:
https://code.google.com/archive/p/narcoleptic/

The sleep time can range from 16 to 8,000 milliseconds (eight seconds).

To sleep for longer
periods, you can repeat the delay intervals until you get the period you want:

void longDelay(long milliseconds)
{
  while (milliseconds > 0)
  {
    if (milliseconds > 8000)
    {
      milliseconds -= 8000;
      Narcoleptic.delay(8000);
    }
    else
    {
      Narcoleptic.delay(milliseconds);
      break;
    }
  }
}