Reliability of Millis()

Dear friends.

I have a doubt. I have made a gardening system which turns on and off a solenoid valve at a particular time. And the complete timing is taken care of by the millis() function.

The program is working fine but I have a doubt if the millis will work fine for say atleast a month or so? In case anyone having any experience with using millis() for long durations, kindly share your experience. Timing accuracy is not an issue for me, so I would like to know if we can manage the timing reliably with the millis() itself or should we go for an external RTC.

You will get errors as time goes by, but, isn’t there the problem of a power fail.
Highly recommend you to go with a RTC.

http://www.ebay.ca/sch/i.html?_from=R40&_trksid=p2050601.m570.l1313.TR0.TRC0.H0.Xrtc+32.TRS0&_nkw=rtc+32&_sacat=0

You can keep track of time using millis() (or micros()), but I would recommend an external source for longer periods as well.

If you do... want to keep track of time using millis() (or micros()), keep in mind they're 32-bit values, overflowing after a certain period of time. After about 49,7 days (millis()) or 71,6 minutes (micros()) both functions will start from 0 again.

http://www.gammon.com.au/millis

A solution with a cheap ESP8266 Wifi module might be nice as well, it gives you the possibility to fetch time from an NTP-server and make your project accessible over wifi.

For long time periods you probably need the accuracy of a Real Time Clock (RTC) module. The Arduino oscillator does not run at exactly 16 MHz.

The fact that millis() rolls over after 49 days or so is not a problem. As long as you always test it using subtraction if (millis() - prevMillis >= interval) it will work properly even during the roll-over.

...R

An RTC module is a good idea. For plant watering, a DS1307 type module is adequate. The DS3231 and DS3234 types are more accurate, but slightly more expensive.

The DS3231 is well worth the small amount more. Picked up 30, most are within 10 seconds per month.

wow!! Thanks a lot dear friends. I shall go for an RTC then.. I really appreciate all your response. Thanks a lot.