DIY Cheap Real Time Clock using DS1307

Keywords : RTC, Real Time Clock, DS1307, I2C Communication, RTC Library


INTRO : Real Time clocks are very much useful to keep track of time in most of the electronic appliances. Refer the below images for your reference. However if you are designing a circuit, it would important to make a one yourself rather than using a breakout board which would be much expensive and less convenient. Lets see how to get this done.

In this example I've selected DS1307 serial real time clock which actually would cost few cents.

You can download the datasheet from here. DS1307


Highlights DS1307 Datasheet
Highlights from DS1307 Datasheet
Lets see the typical connection of DS1307


DS1307 typical connection Schematic
DS1307 typical connection Schematic
Notes : In Arduino Uno : Connect SDA Pin to A4 and SCL Pin to A5. Keep the watch crystal as much as closer to the IC oscillator pins (Pin 1 and Pin 2)

DS1307 Arduino Uno Connection Diagram
DS1307 and Arduino Uno Connection Diagram
Required components


  1. DS1307 Integrated IC  (I've selected a DIP version of this)
  2. 32.768 KHz Watch Crystal  (Very cheap and commonly available)
  3. CR2032 Battery and Battery Holder (Can use any other 3V Battery)
  4. 2 x 4.7k resistors (Pull-Up resistors for I2C communication)
  5. Breadboard
  6. Jumper Wires
  7. Arduino Uno (Can use any other microcontroller with I2C, Arduino is much easy)

See How I've Connected the circuit on breadboard,
DS1307 Arduino Circuit
DS1307 Arduino Circuit Assembly
Now we can use I2C Scanner Program to see whether I2C communication is working well. (Skip this if you are confident)


  1. Copy the I2C Scanner Code. (You can find the code from here)
  2. Connect Arduino to the PC
  3. From Tools, Select the Board and Port
  4. Then Upload the I2C Scanner Code 
  5. Open the Serial Monitor (Select Baud rate as 9600)
DS1307 I2C Scanner
DS1307 I2C Scan result


Now Lets download the RTC Library.

1) Go to "Sketch" >> "Include Library" >> "Manage Libraries"


Installing RTC Library
Installing RTC Library
2) Type "DS1307" on the search tab and press "Enter"


Installing RTC Library
Installing RTC Library
3) Find "RTCLib by NeiroN" and Install


Installing RTC Library
Installing RTC Library

Now Lets try the example code

1) Go to "file" >> "examples" >> "RTCLib By NeiroN" >> "rtc_format" and open the code.

RTC Example DS1307
RTC Example Run
2) Go to Tools and select the board and port

3) Upload the code

4) Open the Serial Monitor (Do not forget to change the Baud Rate to "57600"

RTC DS1307 Results
RTC DS1307 Results