How to Handle RTC DS3231/DS3232 with Arduino

An RTC (Real Time Clock) IC is designed to provide precise time information ranging from seconds, minutes, hours, dates, days, month to years. There are many types of RTC IC (Integrated Circuit) available on the market, such as DS1307, DS1321, DS1332, etc. Most of them is manufactured by Dallas Semiconductor. Their products are easily identified by the prefix of 'DS' as example that I mentioned previously.

In this tutorial I will explain how to do handle DS3231 RTC with Arduino within 5 minutes only. Pretty easy. Why using Arduino we can make a circuit/system faster? At least there’re two reasons, first, in terms of hardware, the RTC is available in the market are usually already in ready-made modules (turnkey module) and compatible with Arduino pinout. Second, from software side, there is available a ready-to-use library to handle the hardware (i.e. RTC). Just declare the library and you will get you want.

DS3231/DS3232-Arduino Wiring and Materials 

For the experiment, from the hardware side prepare DS3231 RTC module, 4 pieces jumper cable Male to Female, and Arduino Uno board. Then connect DS3231 RTC module and Arduino Uno with following connection:

RTC
Arduino Uno
Vcc
5V
Gnd
Gnd
SDA
A4
SCL
A5

DS3231/DS3232-Arduino Circuit

Roughly prototype circuit would be as shown below



Note: RTC DS3231 module is a circuit that has a synchronous serial communication line called I2C/IIC so it can be directly connected to the I2C Arduino pin on A4 and A5

Please download the software for the first libraries needed here and there. Extract and copy the library to the Arduino IDE ‘libraries’ folder (for example C:/Program Files/Arduino/libraries). If have done, open example sketch 'TimeRTC' through 'File-examples-DS3232RTC-TimeRTC’ menu. Verify the sketch to ensure all libraries can already be used. If there is no error, please upload the sketch to the Arduino Uno board by pressing ‘upload’ button on toolbar or just pressing shortkey ‘CTRL+U’ combination button

If you've uploaded, open ‘Serial Monitor’ window (find in ‘Tools’ menu) to test the prototype circuit. If all wiring is correct, the precise time information should appear as follows:



It’s very easy, right? Now you've homemade a precise digital clock. But please be aware, the time shown in the RTC is the factory default. Because made in USA, the time displayed is local time in there. For how to set RTC time into actual time, I will present in next tutorial.

RTC DS3232 and DS3231 Difference

Basically, both of RTC DS3231 and DS3232 architecture is same. Addressing, how to access their working memory is same. The difference is the amount of internal memory (SRAM). RTC DS3231 has 12H (18) byte SRAM, while DS3232 get FFH (255) byte.

Arduino as RTC

Instead of using external RTC, Arduino could also be programmed as an RTC. Arduino is seemed to have an internal RTC which can be used for many purposes. For more details about the Arduino as an RTC can be read in next tutorial.
Previous
Next Post »