Simple Guide to Setting Time on a DS3231/DS3107/DS1337 Real Time Clock With Arduino UNO

About: Mom, maker, tinkerer, technophile.

The DS3231 is a highly accurate, widely used Real Time Clock (RTC), as are its slightly less accurate counterparts, DS3107 and DS1337. Before it can be useful, however, it needs to be set to the correct time. This Instructable is strictly for the purpose of setting the correct time on a Real Time Clock board using an Arduino UNO. There are other very informative guides about RTC boards, but they contain a lot of extra information that you may not want to read through. You won't get a lot of background in this Instructable, but hopefully, if you've come here looking to set your DS3231 to the correct time, you'll find what you need!

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: Parts

You'll need only:

  • DS3231 (or DS3107/DS1337) Real Time Clock (EBay is among the cheapest sources)
  • An Arduino UNO (you could use another board but it may use different pins for SCL/SDA)
  • A coin cell battery (This article claims you need a rechargeable LIR2032 battery, though they often ship with a CR2032 battery)
  • 4 x Male to female breadboard cables

Step 2: Connect RTC to Arduino

  1. Place the coin-cell battery in the RTC. (The positive side faces outward on most RTC boards)
  2. Connect only the following four sets of pins together using the male to female jumper cables:
    VCC -> Arduino 5V
    GND -> Arduino GND
    SDA -> Arduino A4
    SCL -> Arduino A5

Step 3: Download the Arduino Library and Run the SetTime Sketch

  1. Download and install the DS1307RTC Library from http://www.pjrc.com/teensy/td_libs_DS1307RTC.html. If you don't know how to install an Arduino library, read the instructions here.
  2. Connect your Arduino to your computer, then open the Arduino IDE, and open the SetTime sketch which you can find under: File->Examples->DS1307RTC->SetTime.
  3. Be sure your Arduino is connected to the computer and download the sketch to the Arduino
  4. Open up the Serial Window - make sure the baud rate is set to 9600. If everything goes correctly, you should see a success message as shown in the last image above.

That's it! You're now all set to use the correct time in your future projects.

Time Contest

Participated in the
Time Contest

2 People Made This Project!

Recommendations

  • Made with Math Contest

    Made with Math Contest
  • Multi-Discipline Contest

    Multi-Discipline Contest
  • Robotics Contest

    Robotics Contest

7 Discussions

None
DagaduP

Question 4 months ago

I have uploaded sketch as per ur instructions on uno its run successfully but last message is not appearing..ie success message.. what to do...also while i am using the RTC 3231 for other ...its message that RTC battery discharged even if i just set new 2032 cell into that.. what to do

None
SaintSkinny51792

9 months ago

I noticed your using the DS1307 settime example sketch, is that made to work with the DS3231 as well?

1 reply
None
bmonroeSaintSkinny51792

Reply 7 months ago

Not "made for DS3231" but works exactly as indicated with it with the additional header as noted below.

None
KeneilweK

Question 10 months ago on Introduction

I have downloaded the code. But it has not been useful to me for setting the time on my rtc clock. Is asks 'Skip time setting process (Y/N) and then gives very little time for a response. Once I do get a response in, it automatically sets the year to '13' which means 2013 then asks me for a month, when I type '06'/'6' it responds by making the month 48 or 50 sometimes. Is there a way to fix this or should I just try another code to set the time ?

I am using a DS3231 rtc clock on adruino mega.

None
kentsn

1 year ago

Thanks for the Time Set answer. The additional lib did the trick.

None
kentsn

Question 1 year ago

When I run the RTC st-time sketch I receive this error: 'tmElements_t' does not name a type". I opened the sketch exactly as you described. Any ideas?

Thanks

Kent

1 answer
None
DR272727kentsn

Answer 1 year ago

I just did this myself using an Arduino Uno R3, a DS3231 RTC module and the Arduino IDE ver. 1.8.5 on Windows 10. It works.

Make sure you have both the TimeLib.h and Wire.h librarys already installed.