Countdown, milliseconds?

I'm programming a countdown timer for our schoollessons. So the students can see how much time is over in a lesson.

The lessons are 45 minutes, the pauses 15 minutes.

Now, I start with a number of 2700000 milliseconds and every 1000 milliseconds I substract 1000 from that starting number. I use therefor the blink-without-delay-method.
Very simple, but it works.

One thing: the whole loop takes a bit of time too. So, when I countdown a second, it will be a bit more then a second, i think?

Would it be more accurate when I 'm using an RTC? Or is the deviation small enough for one whole day?


Precision is crucial when it comes to students and lesson duration, use RTC

Which loop would that be?

You think wrong. The millis counter us updated by interrupts so unless you have anything that disables the interrupts in your code you will not loose any time because if that.

The accuracy is determined by how accurate your crystal or resonator is.

if you use millis() you'll be dependant on the quality of the 16Mhz circuit that is used in your Arduino.

Typical Arduinos do have a ceramic resonator instead of a good crystal. The tolerance range for crystals is pretty narrow, but with ceramic resonators you never know.

If I remember well, you get ±-0.5% accuracy for the ceramic resonators so you could be off by 3 minutes at the end of a 10 hours day (8am to 6pm).

a cheap half baked solution would be to measure how much you gain / loose with your specific arduino in a typical day (temperature could impact this) and put some stuff in the code to take this into account (as you know how fast/slow your clock really is).

Using a good RTC (DS3231 or better) would be more precise but you probably need a way to sync to a "real clock" (NTP if you have internet access from your Arduino, GPS signal etc) from time to time to accommodate for small imprecision over time.

There is an 7-segment display, based on a ledstrip, connected.
And it must switch between lessons and pauses.
And there is an option to show the clock (an rtc is already in use, but not in the countdown part).

Thanks everyone!
Indeed i have a ds3231 connected. And (sorry, I don't tell) I use a wemos d1 mini.
So, I can check the real time at any moment.

But thats a bit more difficult te code... (for me...)

I will try to use the RTC and update this RTC daily with NTP.


There’s no need to update a DS3231 on a daily basis. Even more true if you are only using it to time something unrelated to the actual time of day.

Post the code you have now. Try to get an example RTC sketch working independently to gain confidence, then you can retrofit the original code.


Not when you are using millis().

It depends on how you use it... (or rather, potentially misuse it).

But, we haven't seen the code .

Then a DS3231 is not needed if you have internet near.
The WeMos D1 mini has a crystal clock, and will keep perfect time between (daily?) internet NTP updates.

Can it do that in its sleep? How sound a sleep mode?

At what reduced power consumption level will this be true? A board is not just the chip.

Depends on how low you can get the sleeping current and how long you want what battery you choose to be able to run you device.


A post was split to a new topic: Problems with my code millis

Nobody mentioned battery power or sleep.
There is no need to sleep a WeMos on mains power.

Thanks all of you!
I have enough information to keep going.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.