user65824: Dear Stack Exchanger's,
I want to reset my Arduino and system in every 24h for preventing frozen software and also other connectivity stuffs.
I wrote a program which connects a digital pin to reset pin of Arduino and I want to reset with that way.
For example my code :
unsigned long myTime; // Millis() function time value 
int timeExpected = 5000; // I want to reset it in every 5 secs for testing.
const int RESET_PIN = 2; // Reset pin's connection

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN,OUTPUT);
}
void loop() {
  digitalWrite(LED_BUILTIN,HIGH);
    myTime = millis();
    Serial.println(myTime); // prints time since program started
     delay(1000);

   if(myTime % timeExpected == 0) {
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
     Serial.println("RESET");
    //digitalWrite(RESET_PIN, LOW);(I just test with LED_BUILTIN Low function)
    }

  }

I have tried the watchdog timer but I cannot do it for 24 hours.
If you have another solution for reset in 24h please tell me and send me the related article/book/link etc. I will check and implement into my code.
UPDATE:
I have done this but it does not reset at very 5s .
Code :
#include <avr/wdt.h>
unsigned long myTime;
int timeExpected = 5000; 


void setup() {
  Serial.begin(9600);
Serial.println("Setup started :");
// make a delay before enable WDT
// this delay help to complete all initial tasks
delay(2000);
wdt_enable(WDTO_2S);
}


void loop() {
    myTime = millis();
    delay(1000);
    Serial.println(myTime); // prints time since program started
   if(myTime == timeExpected) {
     Serial.println("RESET");
    wdt_reset();
    }


user37622: You can do an almost immediate full reset with watchdog by activating it 'on place'.
wdt_enable(WDTO_15MS); // resets the MCU after 15 milliseconds
while (true);

You can use millis() for timing the reset as any other timed function.

user78443: You can use the watchdog timer, but you have to change the way you measure the elapsed time. Try this code:
#include <avr/wdt.h>

unsigned long myTime; // Millis() function time value
unsigned long elapsedTime;
unsigned long timeExpected = 5000; // I want to reset it in every 5 secs for testing.
const int RESET_PIN = 2; // Reset pin's connection

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  myTime = millis();
  Serial.println("INIT");
  wdt_enable(WDTO_2S); //Enable wdt every two seconds

}
void loop() {

  //************RESET HANDLER********************//
  elapsedTime = millis() - myTime;
  if (elapsedTime > timeExpected) {
    Serial.print("RESET");
    while (1); //Intentionally halt the program, so the watchdog performs the reset    
  }
  //**********************************************
  //****************REST OF THE PROGRAM***********
  wdt_reset(); //Ensure one call to this function at least one time in two seconds or less
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.println(elapsedTime); // prints time since program started
  delay(1000);           
}

Please note that if you have multiple delays in your program, you have to ensure the call to wdt_reset() in order to prevent unwanted resets.
Personally I try not to use delays and would recommend avoid delays as much as possible. You may check out this tutorial if you want to see how to avoid delays. If you achieve avoiding delays you can call wdt_reset() just one time at the begining of the loop.

65824: <p>Dear Stack Exchanger's,</p>
<p>I want to reset my Arduino and system in every 24h for preventing frozen software and also other connectivity stuffs.</p>
<p>I wrote a program which connects a digital pin to reset pin of Arduino and I want to reset with that way.</p>
<p>For example my code :</p>
<pre><code>unsigned long myTime; // Millis() function time value 
int timeExpected = 5000; // I want to reset it in every 5 secs for testing.
const int RESET_PIN = 2; // Reset pin's connection

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN,OUTPUT);
}
void loop() {
  digitalWrite(LED_BUILTIN,HIGH);
    myTime = millis();
    Serial.println(myTime); // prints time since program started
     delay(1000);

   if(myTime % timeExpected == 0) {
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
     Serial.println(&quot;RESET&quot;);
    //digitalWrite(RESET_PIN, LOW);(I just test with LED_BUILTIN Low function)
    }

  }
</code></pre>
<p>I have tried the watchdog timer but I cannot do it for 24 hours.
If you have another solution for reset in 24h please tell me and send me the related article/book/link etc. I will check and implement into my code.</p>
<p>UPDATE:
I have done this but it does not reset at very 5s .
Code :</p>
<pre><code>#include &lt;avr/wdt.h&gt;
unsigned long myTime;
int timeExpected = 5000; 


void setup() {
  Serial.begin(9600);
Serial.println(&quot;Setup started :&quot;);
// make a delay before enable WDT
// this delay help to complete all initial tasks
delay(2000);
wdt_enable(WDTO_2S);
}


void loop() {
    myTime = millis();
    delay(1000);
    Serial.println(myTime); // prints time since program started
   if(myTime == timeExpected) {
     Serial.println(&quot;RESET&quot;);
    wdt_reset();
    }
</code></pre>
 37622: <p>You can do an almost immediate full reset with watchdog by activating it 'on place'.</p>
<pre><code>wdt_enable(WDTO_15MS); // resets the MCU after 15 milliseconds
while (true);
</code></pre>
<p>You can use millis() for timing the reset as any other timed function.</p>
 78443: <p>You can use the watchdog timer, but you have to change the way you measure the elapsed time. Try this code:</p>
<pre><code>#include &lt;avr/wdt.h&gt;

unsigned long myTime; // Millis() function time value
unsigned long elapsedTime;
unsigned long timeExpected = 5000; // I want to reset it in every 5 secs for testing.
const int RESET_PIN = 2; // Reset pin's connection

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  myTime = millis();
  Serial.println(&quot;INIT&quot;);
  wdt_enable(WDTO_2S); //Enable wdt every two seconds

}
void loop() {

  //************RESET HANDLER********************//
  elapsedTime = millis() - myTime;
  if (elapsedTime &gt; timeExpected) {
    Serial.print(&quot;RESET&quot;);
    while (1); //Intentionally halt the program, so the watchdog performs the reset    
  }
  //**********************************************
  //****************REST OF THE PROGRAM***********
  wdt_reset(); //Ensure one call to this function at least one time in two seconds or less
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.println(elapsedTime); // prints time since program started
  delay(1000);           
}
</code></pre>
<p>Please note that if you have multiple delays in your program, you have to ensure the call to wdt_reset() in order to prevent unwanted resets.
Personally I try not to use delays and would recommend avoid delays as much as possible. You may check out <a href="https://youtu.be/xcvXUCih30Y" rel="nofollow noreferrer">this tutorial</a> if you want to see how to avoid delays. If you achieve avoiding delays you can call wdt_reset() just one time at the begining of the loop.</p>
