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 Batteries 보기

관련 상품 참조

A000066 | Arduino Uno Rev3

Arduino Corporation Embedded System Development Boards and Kits 보기

최신 뉴스

Sorry, your filter selection returned no results.

개인정보 보호정책이 업데이트되었습니다. 잠시 시간을 내어 변경사항을 검토하시기 바랍니다. 동의를 클릭하면 Arrow Electronics 개인정보 보호정책 및 이용 조건에 동의하는 것입니다.

당사의 웹사이트에서는 사용자의 경험 향상과 사이트 개선을 위해 사용자의 기기에 쿠키를 저장합니다. 당사에서 사용하는 쿠키 및 쿠키 비활성화 방법에 대해 자세히 알아보십시오. 쿠키와 추적 기술은 마케팅 목적으로 사용될 수 있습니다. '동의'를 클릭하면 기기에 쿠키를 배치하고 추적 기술을 사용하는 데 동의하는 것입니다. 쿠키 및 추적 기술을 해제하는 방법에 대한 자세한 내용과 지침을 알아보려면 아래의 '자세히 알아보기'를 클릭하십시오. 쿠키 및 추적 기술 수락은 사용자의 자발적 선택이지만, 웹사이트가 제대로 작동하지 않을 수 있으며 사용자와 관련이 적은 광고가 표시될 수 있습니다. Arrow는 사용자의 개인정보를 존중합니다. 여기에서 당사의 개인정보 보호정책을 읽을 수 있습니다.