Real Time Clock (RTC) Module With Arduino (DS1307 and DS3231

About: Share Knowledge about Arduino, ESP,GSM,Basic Electronics, DIY PROJECTS, Raspberry pi

This post is about how to use the DS1307 Real Time Clock (RTC) module with the Arduino. You can also follow this guide for other similar modules like the DS3231 RTC.

Introducing the Real Time Clock module

The real time clock module is the one in the figure Above (front and back view).

When you first use this module, you need to solder some header pins.
As you can see in the picture above, the module has a backup battery installed. This allows the module to retain the time, even when it’s not being powered up by the Arduino. This way, every time you turn on and off your module, the time doesn’t reset.

This module uses I2C communication. This means that it communicates with the Arduino using just 2 pins.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Where to Buy?

The Real Time Clock is an affordable module. You can check theDS1307 RTC module

Step 2: Pin Wiring/Schematics

Wiring the RTC module is pretty straightforward!

PinWiring to ArduinoUno

SCL==> A5

SDA==>A4

VCC==>5V

GND==>GND

Step 3: Code

Working with the RTC requires two important steps:

setting the current time, so that the RTC knows what time is it.

retaining the time, so that the RTC always gives the correct time, even when it is turned off

Step 4: Set the Current Time in the Real Time Clock

For setting the current time you need to change the code provided.

set your current time int the function setDS3231time()

The parameters for the function are highlighted in red: seconds, minutes, hours, day of the week, date, month and year (in this order). Sunday is the day 1 of the week and Saturday is 7. Don’t forget to uncomment that line of code.
After setting the current time, you can upload the provided code with the required modifications.

The code provided was written by John Boxall from tronixstuff. You can read his tutorial here.

Step 5: Retain the Time in the Real Time Clock

If you don’t want to reset the time everytime the RTC is turned off, you should do the following:

after setting up the time, you should comment the function that sets the time and upload the code again.

This is a very important step to set up the time in your RTC. If you don’t do this, everytime your RTC resets, it will display the time that you’ve set up previously and not the current time.

Step 6: Demonstration

Open the serial monitor at a baud rate of 9600 and you’ll see the results.

Here’s the Serial Monitor displaying the current date and time, in above fig.

Be the First to Share

    Recommendations

    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    Discussions