DS1307 Real-Time Clock (RTC) library for Arduino
This library provides an interface for the DS1307 Real-Time Clock chip with Arduino. It was one of the early and most popular DS1307 libraries in the Arduino community.
Originally created by Matt Joyce in 2009 and hosted on Google Code at code.google.com/p/libds1307/.
- March 31, 2009 - Initial release announced on the Arduino forums
- August 2012 - Updated for Arduino IDE v1.0.1 compatibility with contributions from:
- 2016 - Google Code shut down
- 2025 - Migrated to GitHub for preservation
- Read/write time and date from DS1307 RTC
- Start/stop clock functionality
- BCD format handling
- Simple API for Arduino projects
- Compatible with Arduino Wire library
- Download this repository
- Copy the libds1307 folder to your Arduino libraries directory
- Restart the Arduino IDE
- Include the library in your sketch:
#include <DS1307.h>
#include <Wire.h>
#include <DS1307.h>
int rtc[7];
void setup() {
Serial.begin(9600);
// Optional: Set the time
// RTC.stop();
// RTC.set(DS1307_SEC, 0);
// RTC.set(DS1307_MIN, 30);
// RTC.set(DS1307_HR, 14);
// RTC.set(DS1307_DOW, 1); // Day of week
// RTC.set(DS1307_DATE, 8);
// RTC.set(DS1307_MTH, 11);
// RTC.set(DS1307_YR, 25); // Year (2025)
// RTC.start();
}
void loop() {
RTC.get(rtc, true);
Serial.print(rtc[DS1307_HR]);
Serial.print(":");
Serial.print(rtc[DS1307_MIN]);
Serial.print(":");
Serial.println(rtc[DS1307_SEC]);
delay(1000);
}DS1307_SEC- Seconds (0-59)DS1307_MIN- Minutes (0-59)DS1307_HR- Hours (0-23)DS1307_DOW- Day of week (1-7)DS1307_DATE- Date (1-31)DS1307_MTH- Month (1-12)DS1307_YR- Year (0-99, representing 2000-2099)
RTC.get(int *rtc, boolean refresh)- Get all time/date values into an arrayRTC.get(int component, boolean refresh)- Get individual componentRTC.set(int component, int value)- Set individual componentRTC.start()- Start the RTCRTC.stop()- Stop the RTC
This library was released as open source. Please use and modify as needed for your Arduino projects.
Matt Joyce (2009-2012)
This repository was created in 2025 to preserve this historically significant Arduino library after the shutdown of Google Code. The code remains unchanged from the last Google Code version (August 2012).
See CHANGELOG.md.