Skip to content
Arduino library for the DS1302 Real Time Clock chip
Branch: master
Clone or download
atsampson and msparks Fix incorrect reads from some DS1302 versions.
The code as provided worked for me on a DS1302 labelled "DS1302 0137A4
618AE", but not on one labelled "DS1302 1528C2 +163AN"; the latter
produces good data and bad data on alternate seconds. Comparing the code
with Krodal's public domain DS1302 library (which works on both)
revealed that this library has no explicit delays, and after an 8-bit
write could lower the clock line while the IO pin was still in output

Add delays after IO operations that need them, and fix the 8-bit write
Latest commit 5650f7d Oct 31, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Move fritzing file to examples/. Jan 3, 2015
DS1302.cpp Fix incorrect reads from some DS1302 versions. Mar 18, 2018
DS1302.h Fix incorrect reads from some DS1302 versions. Mar 18, 2018 Update README with features. Jan 3, 2015

DS1302 RTC library for Arduino

This project is a library for the Arduino platform. It provides a simple interface to the Maxim DS1302 timekeeping chip. It allows Arduino projects to keep accurate time easily.


Of the features on the DS1302, this library provides support for:

  • Setting and retrieving the time, using the burst modes.
  • Setting and clearing the Write Protect (WP) flag.
  • Setting and clearing the Clock Halt (CH) flag.
  • Setting and accessing the 31 bytes of static RAM. Single-byte and multi-byte (burst) modes are supported.
  • Low-level register access.

Trickle charging support is the only major feature of the DS1302 not directly supported by this library. However, trickle charging can be enabled using the low-level register access functions if desired.

Examples and documentation

The header file is well-commented, and the examples directory contains example sketches for immediate use.


Place the DS1302 directory in the libraries subdirectory of your Arduino sketch directory. On OS X, for example, your sketch directory might be:


In that case, you should put the DS1302 directory at:

You can’t perform that action at this time.