Hello, 

In this tutorial, we are going to make a real-time clock using Arduino and DS1307 sensors.

Hardware Required

Software Required


 

  • An RTC is a timekeeper device that is usually in the form of an Integrated Circuit. An RTC is battery powered so it keeps track of time even when there is no power supplied to it. 
  • RTCs are generally present in computers, server rooms, etc. where keeping track of time is necessary. 

Importance of Real-time clocks

  • Almost every microcontroller like Arduino has built-in timers and timekeepers. But they are power-dependent. So when the power supply is shut off, the clock will reset to zero.
  • We have to adjust the clock manually each time the power supply has been shut off. This is acceptable for projects which do not require accurate time to be kept.
  • But for projects which require accurate time measurement irrespective of the power supply being shut off or the microcontroller being reprogrammed, like alarms, clocks, data loggers etc.  RTCs are an absolute necessity. 
  • Almost all RTCs use very small currents and run for very long on a single cell. One of the most commonly used ICs for this purpose is the DS1307 RTC module. This is because this IC gives great performance and is very economical. 

DS1307 Real Time Clock module

  • DS1307 RTC module is one of the cheapest and low-power real-time clock modules which can keep track of time and date i.e. Hours, minutes, seconds, and Year, Month, Day. 
  • This module can keep dates and times till the year 2100. 
  • It has an incredibly low power consumption. It only consumes less than 500 mA while operating on a battery. 
  • One more great feature of this IC is that it can automatically switch between battery power and regulated power supply.
  • It has two options to showtime. Between 24-hour and 12-hour options. 

Pinout of the RTC module

  • DS pin: This pin is supposed to output the temperature if the sensor DS18B20 is installed on the chip
  • SQW pin: This pin is used to output square wave frequencies. This can be enabled and edited via programming. 
  • SCL pin: This is the serial clock used to sync the data movement from the sensor to the board.
  • SDA pin: This is used for data transfer in the I2C communication. 
  • VCC pin: This is the power supply pin.
  • GND pin: This is the ground pin.
  • BAT pin: This is the backup power supply pin. This is used to keep the time when the regulated power supply is interrupted. 

Circuit Diagram

Pins on DS1307 

Pins on Arduino

5V

5V

GND

GND

SDA

A4

SCL

A5

Pins on I2C LCD Display

Pins on Arduino Uno

VCC

5V

GND

GND

SDA

A4

SCL

A5

Working concept 

  • The working concept of this project includes three components: DS1307 module, Arduino board, and the LCD Display
  • The DS1307 module sends the real-time clock data to the Arduino board via I2C communication. 
  • This data is read by the Arduino board and then sent to the LCD Display to show to the user.

Arduino Code

 

  • Download the "DS1307 Real-time" library here.
  • Download the "Time" library here
  • Install both the libraries in Arduino IDE.
  • Upload the above code onto the Arduino board. 

Now your Real-time clock is ready for use.