Home > Projects > Clock – Timer Projects > Do You Have The Time? DS1307 RT Clock + Arduino

Do You Have The Time? DS1307 RT Clock + Arduino

Summary of Do You Have The Time? DS1307 RT Clock + Arduino


This article introduces the DS1307 Real-Time Clock (RTC) as a solution for microcontrollers needing time awareness, specifically focusing on SparkFun's RTC module for Arduino projects. It explains that the chip uses I2C to transmit data in Binary Coded Decimal (BCD), requiring conversion to decimal for use. The text also notes that the clock may drift by approximately one minute per month due to environmental factors like temperature and magnetic fields, suggesting the DS3234 as a more precise alternative if accuracy is critical.

Parts used in DS1307 RTC Module Project:

  • DS1307 RTC (Real Time Clock) chip
  • SparkFun RTC Module
  • Backup battery
  • Crystal oscillator
  • Arduino microcontroller

Most microcontrollers are time-agnostic, meaning they are unaware of the time around them, but that’s ok as most things we make have no need for it. But… every once in awhile you come up with an idea that requires knowing the actual time. Mostly this is used for data-logging, or creating this year’s newest clock. (Why do we come up with harder ways to tell time?) But whatever your reason, we have a solution: The DS1307 RTC (Real Time Clock).Do You Have The Time DS1307 RT Clock + Arduino

For this article we will be discussing and using Sparkfun’s RTC Module because it incorporates everything you need to make it work, including a backup battery good for a minimum of 9 years. It also comes with the time preset so you may not even need to configure it when you get it.

Why write this article?

If you look around, this chip has been used for years, and there are dozens of tutorials on using it. So why write another? I read a lot of them and they all had slightly different information, and most of them talked about the chip without the crystal or other needed addons. So im writing this specifically about using Sparkfun’s RTC module version, and specifically for use on an Arduino.

About

The DS1307 is actually a very simple I2C chip. It just gives you back 7 bytes of information that is the time. So all we need to do is receive it … and transcode it to decimal. “Transcode it to decimal?!?” Yeah, don’t worry, it sounds scary, but it’s not. See the DS1307 encodes all the data in “Binary Coded Decimal” or BCD. BCD is just a way to encode numbers, and works by encoding each digit in 4 digits of binary… like so:
157 = 0001 0101 0111
1 = 0001
5 = 0101
7 = 0111

Normally you would say that 157 = 10011101. But that is 157, BCD encodes each digit separately. 1, 5, 7 not 157. hence 0001, 0101, 0111 not 10011101.

Ok, now that we know we will be receiving the data as BCD, we just need a way to convert that to decimal. Luckily, John Boxall over at TronixStuff (incredibly awesome site) has a pretty simple function to do that for us. Lucky for me too because my method was much more complicated.Schematic Do You Have The Time DS1307 RT Clock + Arduino

Time Shifting

Like all clocks, minus maybe atomic clocks, this clock isn’t perfect. Just as the clock on your microwave, the time on this chip will shift. It uses a crystal oscillator to be as precise as possible, but these are susceptible to drift based on temperature changes and magnetic fields, so it’s going to shift. How much? Well the spec sheet is a little vague about that. But from what I have read, about one minute per month is considered normal. If this is just too much drift, you do have other options – The DS3234 clock’s drift is +/- only 1min a year.

For more detail: Do You Have The Time? DS1307 RT Clock + Arduino

Quick Solutions to Questions related to DS1307 RTC Module Project:

  • What is the primary function of the DS1307 RTC?
    The DS1307 provides real-time information to microcontrollers that are normally time-agnostic, useful for data-logging or creating clocks.
  • Why choose SparkFun's RTC module over other versions?
    This specific module includes all necessary components like a crystal and a backup battery good for at least 9 years, unlike many tutorials that discuss the chip without these addons.
  • How does the DS1307 encode time data?
    The chip encodes data in Binary Coded Decimal (BCD), where each digit is encoded separately in 4 bits of binary rather than encoding the whole number.
  • Is it possible to use the time preset without configuration?
    Yes, the SparkFun module comes with the time preset so you may not need to configure it upon receipt.
  • How much time drift should be expected from the DS1307?
    The clock typically shifts about one minute per month due to susceptibility to temperature changes and magnetic fields.
  • What causes the time on this chip to shift?
    Drift occurs because the crystal oscillator is susceptible to changes in temperature and magnetic fields.
  • Are there alternatives with better precision than the DS1307?
    Yes, the DS3234 clock offers significantly better precision with a drift of only plus or minus one minute per year.
  • What communication protocol does the DS1307 use?
    The DS1307 is a simple I2C chip that returns 7 bytes of time information.

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