RTC Arduino Module Tutorial: How to Pair a Real Time Clock

发布人是

Arduino boards and similar microprocessors can accomplish a wide variety of tasks. If, for example, you want to turn on an LED once per second, use the delay() or millis() commands. Unfortunately, small variations in a system's resonator or crystal oscillator may cause the board to keep uneven time.

All About Arduino SerialWhile this time variation is miniscule—a .05% (.0005x) deviation from the actual time—the lag eventually adds up. For example, if you're trying to make an alarm clock, a .05% variation would mean that your system varies from reality by 43.2 seconds per day. That won't make a difference for the first week, but when you're getting to work 20 minutes late after a month, you might start to get annoyed.

So, what is one to do? The answer, of course, comes in the form of an RTC, or real-time clock module. Options include the PCF8523 and DS1307, as well as the DS3231 chip we'll discuss below.

Connect a Real Time Clock (RTC) Module to Arduino

If you want to get started with an RTC module and Arduino, I recommend using a breakout board with the following features:

- DS3231 chip

- Connections that go to the Arduino

- Holder and connections for a coin-cell (CR2032) battery

The battery keeps it ticking even without external power, so if you have to shut down the main system, it will still read the correct time when you power it back on. You can also use a real time clock module to wake your processor up at set intervals for power savings.

For this setup, hook things up as shown here on an Arduino Uno board, connecting 5V and ground to the appropriate connections, and the SDA and SCL lines to the corresponding Arduino connections. On the Uno, A4 is SDA and A5 is SCL, but the lines are also conveniently broken out here next to the reset button where they connect in the picture above. Plug in a CR2032 battery to keep the chip "ticking."

RTC usage_IMAGE 2

RTC usage_IMAGE 3

Program Your RTC Arduino Device

Here's the process:

1. Install the Adafruit RTC library through the Arduino IDE search function or via this GitHub page.

2. Navigate to File - Examples – RTClib and open ds3131.

3. Open a serial monitor for feedback, then upload the program to your Arduino board.

The first time you do this, the serial monitor will note: "RTC lost power, let's set the time!" This loads the time into the real time clock module based on when the sketch was compiled. After that, it will display the current time/date, time since midnight 1/1/1970, and the temperature.

The time will generally be off by several seconds, because it gets the time from the computer when the program compiles. You can also manually set the time by adjusting the rtc.adjust line with a specific date.

If you want to input the time again, disconnect the module and remove the battery. Plug everything in again and reprogram your Arduino as described above.

RTC usage_IMAGE 4

Battery backup keeps the RTC module on time even when the main power is disconnected.

Clocking Your Project

Now you're ready to get started experimenting with more accurate Arduino RTC timekeeping. Try creating your own timekeeping device or automating processes around your home or business. With more development, you're free to explore endless product possibilities.

参阅相关产品

CR2032

BeStar Technologies 电池 查看

参阅相关产品

A000066 | Arduino Uno Rev3

Arduino Corporation 嵌入式系统开发板和套件 查看

最新消息

Sorry, your filter selection returned no results.

请仔细阅读我们近期更改的隐私政策。当按下确认键时,您已了解并同意艾睿电子的隐私政策和用户协议。

本网站需使用cookies以改善用户您的体验并进一步改进我们的网站。此处阅读了解关于网站cookies的使用以及如何禁用cookies。网页cookies和追踪功能或許用于市场分析。当您按下同意按钮,您已经了解并同意在您的设备上接受cookies,并给予网站追踪权限。更多关于如何取消网站cookies及追踪的信息,请点击下方“阅读更多”。尽管同意启用cookies追踪与否取决用户意愿,取消网页cookies及追踪可能导致网站运作或显示异常,亦或导致相关推荐广告减少。

我们尊重您的隐私。请在此阅读我们的隐私政策。