DS1307 is a Real Time Clock IC that is commonly used in electronic project among hobbyist. An example of real time clock would be the clock in our computer. Even after the power is shut down, after restarting the computer, we are still able to get an accurate time.

This IC is able to provide accurate informations such as hour, minute, second, day of week, day, month, year. DS1307 uses an I2C communication interfacing which only requires 2 line, data (SDA) and clock (SCL). However, if you are using Arduino, there are ready made library to use rtc to ease your job.

You can download the rtc library at this link, https://github.com/adafruit/RTClib .

The connections for DS1307 are quite simple too.

pin connection
Pin Connection

This schematic is taken from the DS1307 datasheet. Notice that there is a Vbat in the circuit, it is used provide the IC battery supply to continue counting even after the main supply is off. I used a 3V, CR-2032 lithium coin battery to supply it.

ds1307

There are examples for DS1307 together with the library. I had made some changes to display it on a Liquid Crystal Display (LCD).


#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>

LiquidCrystal lcd(5,6,7,8,9,10);
RTC_DS1307 RTC;

void setup()
{
 Serial.begin(9600);
 Wire.begin();
 RTC.begin();
 lcd.begin(16,2);

 if(!RTC.isrunning())
 {
 RTC.adjust(DateTime(__DATE__,__TIME__));
 }
}

void loop()
{
 DateTime now = RTC.now();
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Time:");
 lcd.setCursor(6,0);
 lcd.print(now.hour(),DEC);
 lcd.print(":");
 lcd.print(now.minute(),DEC);
 lcd.print(":");
 lcd.print(now.second(),DEC);

 lcd.setCursor(0,1);
 lcd.print("Date:");
 lcd.setCursor(6,1);
 lcd.print(now.day(),DEC);
 lcd.print("/");
 lcd.print(now.month(),DEC);
 lcd.print("/");
 lcd.print(now.year(),DEC);

 delay(500);
}

DSC06754
Display of time and date on LCD.
DSC06752
DS1307 setup with 3V lithium coin battery.
A 10k pull up resistor is used for data and clock line respectively.

There you go, a video demo for DS1307.

There is still a lot that we can do with DS1307 RTC. Gonna try it soon. 🙂

Advertisements