Friday, 28 June 2013

DS1307 RTC IC





A DS1307 is a pretty simple , inexpensive and easy to use real time clock IC. This IC can count date and time accurately. Once the time and date is set, it will continue its counting if the power(backup battery) is there ! The backup battery ( coin cell battery) is there to keep the DS1307 counting operation if the main power supply is cut off.



Have you ever wanted to make yourself a digital clock ? If the answer is yes, then this post is for you !
I will be explaining roughly about how to get started on getting the time, date and day of the week.

The hardware that you need for this are :
- DS 1307 RTC IC x 1
- 32.768kHz Quartz Crystal X 1
- Coin cell CR2032 & the holder
- 10k resistor x 2 
- LCD board x 1
- Arduino x 1



The software required :
- Arduino IDE 

Ok, let's get started.

First of all, connect the DS1307 circuit as below :

Below are the details that I obtained from datasheet of DS1307 :


I make use of 10k pull up resistor at the SDA and SCL pins. This is because the DS1307 communicates through I2C interface,

SDA - arduino pin A4
SCL - arduino pin A5

Next, wire up the LCD according to the schematic below :
       The R3 value normally to be 220 ohm/330 ohm as a current limiting resistor.




I read from my friend, Wai Hung's blog that there is actually a pretty easy to use library for this purpose.
The library is RTClib which you can download it here :


Library download  
RTClib

This library is so much easy to use that a few lines of coding will do the trick !
I uploaded below sketch to my arduino UNO.


Download Code

This code basically just set the time and date according to when the sketch is compiled. It might have some slight delay. Then the set date , time and day of the week will be displayed on a LCD screen. In my case, I am using a 20 x 4 LCD screen. :)

The picture of my clock :
HAHAHA


The main controller circuit ( constructed on prototyping shield) :



I have made a simple DIY DS1307 RTC Module V1.0 for easy interface :

Below is the simple demo on my digital clock :


More to improve soon, probably will add on more features such as timer, alarm and etc.

Thanks for reading and hope you enjoy !


-VK

Google+