Any suggestions on improving the code would be more than welcome. I just read that millis() resets every 50 days, so I am gonna have to write some code to deal with that.
What I mean is that if the millis function resets to zero and my last value was somewhere in the 100000's , timeNow - timeLast will equal a huge negative number. which will mess up my code for sure?
I struggle to find a fix that makes sure no seconds are lost in this scenario
I struggle to find a fix that makes sure no seconds are lost in this scenario
Question : What will happen to the BlinkWithoutDelay example after 49 and bit days when millis() resets to zero ?
Answer : It will carry on regardless and not miss a beat because of how it is written
patrixx:
if i remove the arduino power then install it again. will the time continue or i should set the time again manually?
Without a source for the current time such as an RTC the Arduino cannot maintain time when powered off so you will need to set the time manually each time it is powered up or reset.
The conclusion in the "instructable" that you don't need an RTC for accurate timekeeping is not very well supported imho.
Many Arduinos use a ceramic resonator instead of a crystal. These have a tolerance of around 0,5% (1 second in about 3 minutes).
Even crystals age, that it their frequency changes slightly with age. The better RTC chips (say DS3231) include an age compensation.
Apart from all that, one of the main benefits of an RTC is the battery backup so you don't have to reset the time after a power off.
Finally, RTC modules can be had for half a dollar. So the matter is hardly worth discussing.
I have had several similar modules with the model numbers ZS-042 abd DS3231. These were advertised as having a rechargeable battery but actually came with a non-rechargeable battery which can, when the circuit is powered at 5 volts, explode.
Ignoring that minor detail, the clock modules keep excellent time.
In mine, I remove the resistor in the charging circuit and use normal CR2032 cells for the backup (see picture).
I have made an Arduino clock to work without an external RTC, but I included two buttons so you could set the time by hand. Later, I added support for an external RTC, but my clock will still run without one.
I have built a couple of clocks using esp, Wemos mini to be precise. Used Time library with code to get time from ntp server once per day. These appear to keep time very accurately. One is a chiming clock. It chimes within a second or two of the time signature (the "pips") on the radio. On the other hand, the radio is DAB, and they lag behind the live broadcast by a few seconds.
RoboticEngineer1997:
Unluckily, my nano drift off more than 1 second in less than 10 mins. It is a cheap clone though, maybe the genuine Arduino borad may work better.