How to Use a Real-Time Clock Module (DS3231)

by melastmohican in Circuits > Arduino

952 Views, 4 Favorites, 0 Comments

How to Use a Real-Time Clock Module (DS3231)

20201125-191944.jpg
20201125-184258.jpg

The DS3231 is a low-cost, extremely accurate I2C real-time clock (RTC) with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The device incorporates a battery input and maintains accurate timekeeping when main power to the device is interrupted.

Supplies

Install Battery

BAT-CR2032_full.jpg

The battery input is 3V and a typical CR2032 3V battery can power the module and maintain the information for more than a year.

Connection

DS3231_bb.jpg

Wiring the RTC module is pretty straightforward!

VCC -> Arduino 5V
GND -> Arduino GND
SCL -> SCL or A5
SDA -> SDA or A4

Library

Screen Shot 2020-11-25 at 7.44.25 PM.png

Arduino library for the DS3231 real-time clock (RTC) can be installed directly in Library Manager.

Setting Up the Clock

The clock is most likely set to 1 January 1970 initially. If you need real-time in your projects, synchronize this RTC with your computer.

Looked into the DS3231_set example from the DS3231 library and it seems like it expects a date sent in this format YYMMDDwHHMMSS, with an 'x' at the end.

Few lines of Python code using pyserial and ntplib should get time from the time server and send a string to Arduino.

Test RTC

Screen Shot 2020-11-25 at 8.11.46 PM.png

In library, examples find DS3231/echo_time.ino. Upload it to Arduino and you should see time printed in serial monitor.