Adding RTC to my project

I see alot of info about adding RTC to Arduino projects. 1.) They appear to just be one line comments. 2.) I see alot of modules like 1307 and DS3231, but most of these write-ups are almost 10 years old or older.

Can someone point me to the latest and greatest RTC module w/library and where to get it so that I get a good version ?

Thank You.

Don't stress to much, use a DS3231 and install the library of the same name from the Library Manager

Do you think its possible that the design of the DS3231 was so adequate, that there was little to be gained by developing an 'improved' RTC ?

> I get a good version ?

What problems do you have with the DS3231 ?

DS3231 RTC is one 8-pin dip, CR2032 coin cell, crystal, and 5 pin connector on a minimally sized pcb. It works well. Whats not to like?

Some DS3231 modules have a battery charger circuit for a rechargeable lithium backup battery. That can be a problem if used with non-rechargeable batteries. This page shows how to disable the charge circuit if necessary.

The DS3231 is a good RTC (more accurate than some that came before it, like the 1307).

I have been using a module like this.


Very easy to use. Im using the the standard DS3231 library, and had no issues.

This module also includes an EEPROM chip. You may need a different library to use that.

Does it come in a DIP package? Never seen one.

Internal to the chip.

Perhaps the ChronoDot?
https://shop.macetech.com/products/chronodot-v2-1-high-precision-rtc?variant=35621878595733

As for a library, I don't use one, because it was simple enough for me to write my own code to read and write the time. See my clock project here:
https://forum.arduino.cc/t/ds3231-calendar-clock-with-hourly-chime/979069

1 Like


I buy em 2 at a time from Walmart for $8 per two pack. No battery. They work great. Add battery, connect, up and running on the first try

const int kCePin    = 26;  // Chip Enable - grn
const int kIoPin    = 27;  // Input/Output - yel
const int kSclkPin  = 28;  // Serial Clock - orn
#include <DS1302.h>       // RTC library
//
// Create a DS1302 RTC object.
//
DS1302 rtc(kCePin, kIoPin, kSclkPin);
// Somewhere in setup()
  //
  // Fire up RTC
  //
  rtc.writeProtect(false);  //Gotta unlock before letting it run
  rtc.halt(false);          //Let clock run
  Time t = rtc.time();    // Device data type - read RTC
//
// Somewhere in loop()
//
  //
  Time t = rtc.time();  // Poll clock
//
// This creates t.hr, t.min, t.sec etc.
//
// In the clockSet() function:
//
            //
            setRTC(clockYr, clockMon, clockDt, clockHr, clockMin, clockDoW);
            //


This is extracted from a running module. The only things you should have to change is the pin assignments.

That looks like a DS1302, not a DS3231 ?

Dunno. It says RTC. I buy, they run. Code given works with THAT device. YMMV

Well there are many RTC chips. The OP was asking for a recommendation. The DS3231 is better than the DS1302.

Sorry. I saw RTC and I've got a bunch working on that device. Never had an issue.
What is the major difference between the two? I mean, it keeps time, what else should it do?

The DS1302 and DS1307 are relatively ancient devices. Neither will keep time as accurately as a DS3231 and neither has a built in alarm output.

Main difference is the DS3231 has an internal oscillator, and can also compensate for changes in temperature. It is therefore a lot more accurate than the earleirs versions. It also includes 2 built in alarms, as mentioned above.

Old devices have the advantage of a known track record and volume pricing. LOL (speaking as a rather old device myself!)

I like increased accuracy. I phased out DHT-11's for -22's and added BME280s for better accuracy. For an indoor app tho, temp stability is not normally an issue in an environment that only ever changes a degree or two (ain't central air wonderful?) But I like the alarms and better accuracy/stability never hurts in a clock.

Thank you for all the feed back.

Are there multiple versions of the "DS3231" ?
One that has the ability to recharge its battery and one that does not ?

If I purchase a version that does not recharge its battery, what is the life expectancy of the battery ?
We very rarely have power-outage events, does that make a difference on life expectancy ?
Yeah, the battery is probably only intended for use when project looses power, but that's just what the documentation states. I want to know what the project builders are experiencing.

Thank you.

That would depend on the capacity of the battery used and the backup current the DS3231 uses, which will be found in its datasheet ..................

There are multiple board versions that use the same IC. The most common is the one shown in reply #6, the ZS-042. It's designed for a rechargeable lithium battery, but a non-rechargeable one will last over ten years, probably about equal to the shelf life of the rechargeable one. It's not safe to use the board with a non-rechargeable battery, so you need to modify it by removing the resistor adjacent to the cylindrical orange diode on the board, to disable the charging circuit. You can use the board safely with no mods, if you run it on 3.3V instead of 5V. But that is only reasonable when the I2C bus is also using 3.3V.

If you look at the standby current of the IC, and compare with the capacity of a 2032 battery, you will see by simple math that the non-rechargeable battery life is not an issue.

Other boards do exist, that don't have this confusing issue. I have some, they work fine and there is no difference in software, no difference in the I2C connection. They just cost a little bit more.

It would be a very sorry hobby if we had to depend on anecdotal reports to know how the hardware performs. Do you really think that a multinational semiconductor fab would lie to its customers, over such a crucial specification? In what kind of world would the advice of random strangers on an internet forum be considered more reliable?

Would a design engineer sit down and think, "hmmm. I guess it really doesn't matter much if the battery is draining while the device is powered on... ah who will notice anyway!" Come on.