Millis() in an Arduino 24/7

Hi

I'm using a Nano in an alarm system I built, and millis() is used for example if the siren is triggered then it will stop after n seconds. Now, what if between

initialMillis = millis();
...
...
and
...
if (millis() - initialMillis > nSeconds)..

millis() is reset by the board?
?

Boeing restarts their 787s every 49 51 days. Boeing 787s must be turned off and on every 51 days to prevent 'misleading data' being shown to pilots • The Register

I do not think millis ever resets, but if you mean wraps around, then yes, every 49 days it goes back to zero.
You will need to reset it yourself under your conditions, maybe midnight each day or any other time you decide. That involves timekeeping which may be an issue for you. Another way is to check for a millis value that is equal to 1, 7, 30 days of millis and reset then.

  unsigned long millisWrap = 1024 * secsPerMin * minsPerHour * resetHours;
Or go one more step with hoursPerDay * resetDays

Not very clear (btw, always post a complete code, even if made just from snippets), what do you mean with "millis() is reset by the board"?
A board reset? In this case the millis() returns the milliseconds elapsed since the last board start, so it starts with zero.
If you mean the "unsigned long" range overlap (approx. 49 days after last board start), the if() syntax you're using there will automatically handle the rollover, and you don't need to do anything more.

Looks ok to me.

  • Cannot think why that would ever happen, unless you power cycle or reset the Controller. :thinking:

  • A millis() based TIMER has no problem with overflow.

OP will not need to do anything like that, unless they want their alarm siren to be on continuously for more than 49 days and then turn off on day 50 or later.

Hey, I didn't even have my first coffee. It could happen, right?