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();
}
wdt_reset()
resets the watchdog's timer to avoid reset of the MCU. read my answer again