0

While I was researching ideas for an Arduino clock, I found several clocks that incorporated an RTC (Real Time Clock) module.

I don't know why it is used in some clocks.

So, here are my questions:

  • How does an RTC module work?
  • Do I have to use it "like a rule" (is an RTC necessary or unnecessary) in my clock?
dlu
1,6612 gold badges15 silver badges29 bronze badges
asked Jan 17, 2016 at 18:42
2
  • It is only necessary if you want the clock to keep accurate time. ;-) Commented Jan 29, 2017 at 5:32
  • Or if you want to set alarms: arduino.stackexchange.com/questions/30638/… Commented May 7, 2017 at 21:06

5 Answers 5

2

How does a RTC module works?

It counts. As simple as that. Once a second it ticks and counts up. It also remembers - most have a battery backup and will continue ticking when you turn the main power off.

I have to use it "like a rule" (if it is necessary or unnecesary) in my clock?

If you want accuracy and continuation, yes. An RTC is designed to tick at (as close as reasonably possible) once per second. Trying to do that with just an Arduino is incredibly difficult. The ceramic resonator on an Arduino is not as accurate as the quartz crystals used with an RTC. After a week you may find you are an hour out.

answered Jan 17, 2016 at 19:59
1

RTC modules are used because they make it easier to keep accurate time. They do this by maintaining time when the system is shut down or rebooted (by way of a battery or some other mechanism for keeping running independently of the host system) and by providing a time base that is, usually, more accurate than that of the host.

Another way to keep very accurate time (potentially better than you can get with all but the best RTC modules) is to get your time from a GPS or from the Internet using NTP. If you're going to use a GPS anyway or need an Internet connection then either of those approaches are very good ways to go. If you don't, then they are considerably more expensive than an RTC module.

answered Jan 17, 2016 at 21:52
1

I built a clock designed a while ago by Geoff Graham, who synchronized to a GPS around every 24 hours, and used the internal clock in-between. The GPS corrected for drift in the internal clock (and, of course, gave you the time accurately in the process).

This is more expensive than a RTC, but more accurate. If you also had an RTC it would drift less during the day. Or, you could read from the GPS all the time and not have an RTC.

I made a GPS clock myself which does that - just shows the GPS time.

GPS clock

Higher-contrast image:

GPS clock face

Internals:

Inside GPS clock


This is another project that uses an RTC clock chip (indicated on photo):

Temperature sensor

However if you go for just an RTC chip you can expect it to drift over time. They are more accurate than counting processor ticks (and survive a power outage because of the backup battery) but are not as accurate as the GPS.

Those clock chips are pretty cheap. I got 30 of them for 10ドル from eBay.

answered Jan 18, 2016 at 5:05
0

How does a RTC module works?

It is a specialized counter. It counts seconds, minutes, hours, days, months and years, properly handling such annoying problems as leap year, different days in months, etc.

Additionally it allows powering with a battery, so that clock ticks even when the device is not powered on, until battery discharges.

Usually RTC is clocked at 32768Hz using standarized quartz crystal.

I have to use it "like a rule" (if it is necessary or unnecesary) in my clock?

Unless your microcontroller has RTC built-in, you should use an external one. There are many RTCs with I2C interface.

Built-in timer available in Arduino is not accurate enough and cannot tick when you remove power. Inaccurate counter will cause your clock to drift considerably and no backup power forces your clock to be connected all the time.

You can check out this example to see how to hook up: https://iobtoolkit.com/docs/tutorials/i2c_terminal_mcp7940n.html

Disclaimer: i'm the author of IOB, but you don't need to use it. It's just a nice analysis of a rather popular RTC.

answered Jan 17, 2016 at 21:19
0

For this "rule", and for many "rules" like this, the answer is "it's more of a guideline" (usually "it's not required, but may be easier that way").

Keeping time requires 3 things: an accurate "tick", a way of knowing the time initially, and counting the time since then.

The (16mHz) clock on the Arduino will give you a reasonably accurate "tick" - on the order of 50 parts per million. That means, over a million seconds, your clock will drift about 50 seconds. This works about (ballpark) 1 minute per fortnight. Is this accurate enough? This depends on what you are using it for.

The next thing on the list is knowing the time initially. If you buy a RTC, it may be set to the right time, or it may not. Even if it is "set", it may not be set to your timezone. Setting these is pretty easy. It will need to be set every time the clock (be it a RTC or your homebrew clock) loses power. For this reason, RTCs usually have a battery back up. How will your clock get it's time when it starts up? Note that, if your project is network connected, you may be able to get the clock from the internet - this will also mean the drift of your clock will not be an issue - you can retrieve it once per day, so it will never drift more than 4 seconds before it gets corrected.

The final thing that it needs (and the easiest) is a way of counting the time. This is probably the easiest - use the millis() function. Note that this overflows (resets to 0) after 4294967296 milliseconds - about once every 50 days. Millis() will tell you the number of milliseconds since the Arduino last rebooted. If you want your clock to run more than 50 days, you need to be prepared to that. This will happen part way through a second.

Note that this will give you milliseconds, and, fairly easily, seconds, minutes, hours. If you want the day (of the month), then you need to keep track of which month and year, since the length of each month will vary, as will leap days.

answered Jan 18, 2016 at 2:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.