Introduction: Real Time Clock - DS1302

This is a VERY simple tutorial on how to use the DS1302 Real Time Clock with an Arduino, or Versilino, board.  I will walk you through the wiring, code, and example.  All of which can be found at www.Virtuabotix.com.  This is my ifrst try at creating an instructable, so I welcome any feedback that anyone has, and I hope you enjoy it.  So let's get this started...

Step 1: The Background

The DS1302 trickle-charge timekeeping chip contains a real-time clock/calendar and 31 bytes of static RAM.  It communicates with a microprocessor via a simple serial interface.  The real-time clock/calendar provides seconds, minutes, hours, day, date, month, and year information.  Only three wires are required to communicate with the clock/RAM: CE, I/O (data line), and SCLK (serial clock). Data can be transferred to and from the clock/RAM 1 byte at a time or in a burst of up to 31 bytes. The DS1302 is designed to operate on very low power and retain data and clock information on less than 1μW.  The DS1302 has dual power pins, one for primary and another for backup.  in this example the Priamry power will be provided by the Arduino, and the back up by a CR2032 battery.

The 31 bytes of RAM is formatted as shown in the table below.  Notice that the numeric positions have their own bits to fill.  Specifically the 0-9 value of the 'ones' place have 4 bits, and the 0-9 value of the 'tens' place has 3 bits for the byte filled with the seconds value.  These values are combined to create the entire byte.

This product, as well as the manufacturers datasheet, can be found at https://www.virtuabotix.com/product/virtuabotix-ds1302-real-time-clock-rtc-module-arduino-versalino/.

Step 2: Parts Selection

The parts were chosen based on cost, availibility, and compatibility.  This instructable utilized the above parts:

Step 3: Wiring Setup

Step 4: Code

The original code was provided from the Arduino website, http://playground.arduino.cc/Main/DS1302, which was contributed by user "Kodal". That code was translated into a full library, and expounded upon by Virtuabotix, LLC. The full description of the library, and its functions, can be found at https://www.virtuabotix.com/virtuabotix-ds1302-real-time-clock-module-pin-out-coding-guide/. Simply go to the 'Code' Section to find the link to the library.


This Instructable will address two examples that utilize the library.

*NOTE: The library does NOT use the full functionality of the DS1302 chip, it does use the most common functions that are requested.

Step 5: Code (Example 1)

This example simply allows for printing out the data, and allows for direct user access to the individual elements. Thus printing each element at a time. This, of course, can be printed out in any format, this one just seemed the easiest. As always, this example can be turned into a function..

This example is included in the library that can be found at: The full description of the library, and its functions, can be found at https://www.virtuabotix.com/virtuabotix-ds1302-real-time-clock-module-pin-out-coding-guide/. Simply go to the 'Code' Section to find the link to the library. Once the library is imported, you can find the example in File->Examples.

Step 6: Code (Example 2)

This example utilizes two Superbright LEDs to indicate whether your RTC is actively updating. This is illustrated by wither a Green LED, for good; or a RED LED for not updating. This is simply accomplished by storing a read of the seconds and checking that against the current RTC time. If it has updated you get a Green LED illuminated, if not you get the Red LED.

This example is included in the library that can be found at: The full description of the library, and its functions, can be found at https://www.virtuabotix.com/virtuabotix-ds1302-real-time-clock-module-pin-out-coding-guide/. Simply go to the 'Code' Section to find the link to the library. Once the library is imported, you can find the example in File->Examples.

Step 7: Conclusion

This project was a vast learning experience.  There were a unimaginable amount of resources out there, but very few of them were actually helpful.  I hope this library, linked above, is helpful and I look forward to any input for future projects and feedback.  If you are attempting to use this Instructable and need any assistance contact me, and I will do my best to help.  Good Luck!!

Step 8: Demo

This video has a Demo of both Examples:

As before the examples and the library can be found at https://www.virtuabotix.com/virtuabotix-ds1302-real-time-clock-module-pin-out-coding-guide/....

Thanks for viewing my first Instructable...