real time clock DS1307 interfacing with Arduino

real time clock DS1307 interfacing with Arduino, In this article you will learn how to interface real time clock DS1307 with Arduino. What is real time? why real time clock is used? what is dedicated integrated circuit for real time clock? how to make digital clock using Arduino and integrated circuit DS1307? What are application of real time clock DS1307? Hardware connections of liquid crystal display 16 X 2 LCD and real time clock DS1303 with Arduino. How to use library of real time clock to display time and date on LCD? You will get answers of all your questions in this article.

Before reading this article you should have a basic knowledge about Arduino and its use. You should know how to interface LCD with Arduino and how to use input/ output ports of Arduino. If you don’t know how to do these things. I recommend you to go throgh following articles to get better understanding of this article. Because  I have already posted articles on such things. For more information check following articles.

Getting started with Arduino UNO R3.
LED blinking using Arduino UNO R3
How to use push button with Arduino UNO R3
LCD interfacing with Arduino UNO R3

What is real time clock?

As it name suggests, real time clock is used to keep record off time and to display time. It is used in many digital electronics devices like computers, electronics watches , date loggers and situation where you need to keep track of time. one of the great benefits of real time clock is that it also keep record of time even if power supply is not available. Now the question is how can a electronics device like real time clock work without use of power supply. Because it have small power cell of about 3-5 volt inside which can work for years. Because real time clock consume minimum amount of power. There is many dedicated integrated circuits are available in market which is used to make real time clock by adding necessary electronic components. But in this article I will discuss DS1307 real time clock IC.

DS1307 IC for real time clock:

DS1302 is IC for real time clock which is used to count seconds, minutes , hours, days, months any years. It use I2C communication protocol for communicating with other devices like in our case we are using Arduino. Arduino read values of time and date from DS1307 using I2C communication protocol. It also have feature to keep record of exact time in case of power failure. It is a 8 bit IC. It is used to make real time clock using some other electronic components. Pin configuration of DS1307 is given below:

pin configuration of DS1307
pin configuration of DS1307

Functionality of each pin is given below:

  • pin number one and two is used for crystal oscillator . Crystal oscillator value usually used with DS1307 is 32.768k Hz.
  • Pin three is used for back up battery. Its value should be between 3-5 volt. voltage more than 5 volt may burn DS1307 permanently. Back battery is used to keep track of time in case of power failure to DS1307. After getting power DS1307 shows correct time due to back up battery.
  • pin 4 is ground pin of power supply.
  • pin 5 and 6 is used to communicate with other devices with the help of I2C communication protocol.
  • pin 5 is serial data pin and pin 6 is serial clock. If you don’t know about I2C communication, i recommend you to learn about it.
  • Pin 8 is used for 5 volt power supply.

you need external components to connect with DS1307 to use it as a real time clock. Circuit diagram with necessary components is given below:

real time clock DS1307 circuit diagram
real time clock DS1307 circuit diagram

In above circuit diagram there is no connection for power supply and ground at pin number four and eight. Don’t forget to to provide power supply of 5 volt to this circuit while making this circuit.

Real time clock DS1307 with Arduino :

real time clock DS1307 with Arudino circuit is given below. pin number 5 and 6 of DS1307 is connected with SCL and SDA pins of Arduino. If you have already gone through above mentioned article on LCD interfacing with Arduino and other basic articles to get know how of Arduino, you can easily understand following circuit.


circuit diagram of DIgital clock using real time clock and Arduino
circuit diagram of DIgital clock using real time clock and Arduino

All connections in above circuit diagram is self explanatory, but if you still have any issue. your comments are welcome.


The code for arduino based rtc and temperature monitor given below is write to display date and time on LCD.

#include <Wire.h>
#include “RTClib.h”
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup () {
lcd.begin(20, 4);


if (! RTC.isrunning()) {
Serial.println(“RTC is NOT running!”);
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));

void loop () {
DateTime now =;
lcd.setCursor(0, 0);
lcd.print(, DEC);
lcd.print(now.month(), DEC);
lcd.print(now.year(), DEC);
lcd.print(‘ ‘);
lcd.setCursor(0, 1);
if (now.hour()<10)
lcd.print(now.hour(), DEC);
if (now.minute()<10)
lcd.print(now.minute(), DEC);
if (now.second()<10)
lcd.print(now.second(), DEC);

The result of above code is given below:

circuit diagram of DIgital clock using real time clock and Arduino result
circuit diagram of DIgital clock using real time clock and Arduino result

In above code “#include “RTClib.h”” is used to include library of real time clock. If you don’t have already library installed in your Arduino IDE compiler. you can add it very easily. Download library from given below link. After downloading code, abstract the code and paste the file into libraries folder of Arduino UNO folder.

RTC library

you can also use above library for days. Good luck for your project. Kindly don’t forget to share it with your friends thanks 🙂

7 thoughts on “real time clock DS1307 interfacing with Arduino”

  1. I would like to make an automatic college bell, but I want to see a video how to make it step by step, to know what I need to buy. If you already have a video on youtube please give me the link, if not, you can send me an email ([email protected] – my email adress). I wait your answer.
    Thank you !

  2. Hello sir… Thanx for the code… It is working properly in software…
    But I want to know if it will work on hardware as well.. Is it not needed to set the time for the first time to RTC module as by default time is something else like 01-01-2000 date 12:00

  3. can you help me out to make an automatic school alarm bell using ARDUINO? I want to store the entries of 1 week but the projects available over the internet is for only 1 day entry.

    Please help me….!!!!!


Leave a Comment