Home > News & Updates > Electronics News Updates > Using DS1307 and DS3231 real-time clock modules with Arduino

Using DS1307 and DS3231 real-time clock modules with Arduino

Summary of Using DS1307 and DS3231 real-time clock modules with Arduino


This tutorial introduces using DS1307 and DS3231 real-time clock modules with Arduino. It highlights that the DS3231 offers superior accuracy compared to the DS1307, which can drift due to temperature changes. Both modules utilize the I2C bus for connection, requiring SDA and SCL pins (A4 and A5 on Arduino Uno). While they include backup batteries, replacing them with a CR2023 is recommended for permanent projects. The article notes additional features like EEPROM and alarms for future tutorials.

Parts used in the Real-Time Clock Modules Project:

  • DS1307 real-time clock module
  • DS3231 real-time clock module
  • Arduino Uno or compatible board
  • CR2023 battery

We keep getting requests on how to use DS1307 and DS3231 real-time clock modules with Arduino from various sources – so this is the first of a two part tutorial on how to use them. For this Arduino tutorial we have  two real-time clock modules to use, one based on the Maxim DS1307:

There are two main differences between the ICs on the real-time clock modules, which is the accuracy of the time-keeping. The DS1307 used in the first module works very well, however the external temperature can affect the frequency of the oscillator circuit which drives the DS1307’s internal counter.

Using DS1307 and DS3231 real-time clock modules with Arduino

This may sound like a problem, however will usually result with the clock being off by around five or so minutes per month. The DS3231 is much more accurate, as it has an internal oscillator which isn’t affected by external factors – and thus is accurate down to a few minutes per year at the most. If you have a DS1307 module- don’t feel bad, it’s still a great value board and will serve you well.

With both of the modules, a backup battery is installed when you receive them from Tronixlabs, however these are an inexpensive variety and shouldn’t be relied on for more than twelve months. If you’re going to install the module in a more permanent project, its’ a good idea to buy a new CR2023 battery and fit it to the module.

Along with keeping track of the time and date, these modules also have a small EEPROM, an alarm function (DS3231 only) and the ability to generate a square-wave of various frequencies – all of which will be the subject of a second tutorial.

Connecting your module to an Arduino

Both modules use the I2C bus, which makes connection very easy. If you’re not sure about the I2C bus and Arduino, check out the I2C tutorials (chapters 20 and 21), or review chapter seventeen of my book “Arduino Workshop“.

Moving on – first you will need to identify which pins on your Arduino or compatible boards are used for the I2C bus – these will be knows as SDA (or data) and SCL (or clock). On Arduino Uno or compatible boards, these pins are A4 and A5 for data and clock:

 

For more detail: Using DS1307 and DS3231 real-time clock modules with Arduino

Quick Solutions to Questions related to Real-Time Clock Modules Project:

  • How do the DS1307 and DS3231 differ in accuracy?
    The DS1307 can drift by about five minutes per month due to temperature affecting its oscillator, while the DS3231 is accurate to within a few minutes per year.
  • Can I rely on the included backup battery for more than twelve months?
    No, the inexpensive batteries installed when received should not be relied upon for more than twelve months.
  • What is the best way to ensure long-term reliability for the battery?
    It is a good idea to buy a new CR2023 battery and fit it to the module for permanent projects.
  • Which pins are used for the I2C bus on an Arduino Uno?
    The SDA (data) and SCL (clock) pins are located at A4 and A5 respectively on Arduino Uno boards.
  • Does the DS3231 have features that the DS1307 does not?
    Yes, the DS3231 includes an alarm function which the DS1307 lacks.
  • What communication protocol do these modules use to connect to Arduino?
    Both modules use the I2C bus for connection.
  • Do these modules include EEPROM functionality?
    Yes, both modules have a small EEPROM along with time and date tracking capabilities.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top