I have a need for a "reasonably" accurate timekeeper. By "reasonable", I mean "comparable to any cheapo battery-powered clock".

I want to build a timekeeping circuit for a novelty clock - it only needs to display seconds, and then drive a few other electronic bits at the beginning of every minute.

I've done some tests with millis(), but it seems there's a noticeable drift after only a couple of hours so I suspect it wouldn't be suitable to be left running for weeks.

I'd be interested to know what other techniques people might recommend - is there a good solution that can be supported by the Arduino, or would I be better off buying a separate RTC module? Or just go nuts and install an atomic clock decoder?

If you can find an atomic clock decoder cheaply, I'd definately buy it . Or, you could buy a GPS module and extract the time (atomic clock accuracy) from that. On the other hand, you could do what I did and buy a DS1307 IC or module of eBay, or somewhere else, download a library for it and use that. It is easy to do, and gives decent accuracy.

void loop(){ // compose a string of the current time, then print it ... char text[20]; sprintf(text, "%02d:%02d:%02d", g_iHour, g_iMin, g_iSec); lcd.setCursor(4, 1); lcd.print(text); // (note that this is quite wasteful - we only need to update the screen every second, // or when a button is pressed)

// has it been more than a second since the last update? if (millis() >= (g_uLastTick + 1000)) { // yes g_uLastTick += 1000;

You don't say what board is being used but most Unos, etc., use a ceramic resonator for the system clock, which will typically have a frequency tolerance on the order of ±0.5%. Changing to a crystal (say, ±20ppm) might be simplest, but if you're not in a position to do that, then I'd try a DS1307 RTC. DS1307 breakout boards can be had for under $10, some will plug directly into the headers on an Arduino Uno.

Lately I've been experimenting with running an ATmega328P on the internal oscillator, and connecting a 32.768kHz crystal which acts as a clock source for Timer/Counter2. A simple RTC can then be implemented in software. Fairly straightforward, keeps decent time.

You don't say what board is being used but most Unos, etc., use a ceramic resonator for the system clock, which will typically have a frequency tolerance on the order of ±0.5%. Changing to a crystal (say, ±20ppm) might be simplest, but if you're not in a position to do that, then I'd try a DS1307 RTC. DS1307 breakout boards can be had for under $10, some will plug directly into the headers on an Arduino Uno.

Lately I've been experimenting with running an ATmega328P on the internal oscillator, and connecting a 32.768kHz crystal which acts as a clock source for Timer/Counter2. A simple RTC can then be implemented in software. Fairly straightforward, keeps decent time.

Thanks for your comment - yes, I should have mentioned that I'm using an Uno.

DS1307 need a crystal too, and pullup resistors on the SCL/SDA lines.DS3234 doesn't need any of thathttp://pdfserv.maxim-ic.com/en/ds/DS3234.pdfbut is surface mount - so get an adapter (1.27mm pitch pads)http://www.ebay.com/itm/2PK-SO-SOP-SOIC-SSOP-14-16-20-Pitch-0-65mm-and-1-27mm-DIP-Adapter-Converter-/170754392487?pt=LH_DefaultDomain_0&hash=item27c1c141a7

We have seen "clocks" on this forum that used the amount of light to detect morning midday and evening to get the right timing to feed chicken, an error of 30 minutes was no problem, so reasonable is project dependable.

So, can you specify reasonable? What is the maximum error that is acceptable? 1 second per minute, hour, day, week, month, year?

Or maybe you can tell more about the project itself so we can think about what is needed.

To complete the list of proposed solutions: you can add an ethernet shield and use NTP (network Time Protocol) to request time from an Atomic clock.