I am using a DS3231 RTC module. It requires to set the time every time it is reset. I was wondering if I could read my MacBook's time and date and feed into the module at the setup stage. Is this possible?

P.S. I do not have to use a battery.

  • 2
    Actually the whole point of an RTC is that it has a battery backed up clock that does NOT reset on power loss.
    – Kwasmich
    Commented Apr 2, 2019 at 12:44
  • Yes. But due to some reason, I have a RTC without a battery backup. I had myself opened the Amazon packing today and unboxed the module. And the bottom side has no battery. Commented Apr 2, 2019 at 12:45
  • 5
    So.... attach a battery?
    – Majenko
    Commented Apr 2, 2019 at 12:52
  • 1
    Please note that some of these modules have a (badly designed) charging circuit, and thus require a rechargeable coin cell (LIR2032). Or you can remove the charging resistor from the board.
    – Gerben
    Commented Apr 2, 2019 at 14:30
  • 1
    What I've do with one of my clocks if create an interactive serial console, where I could type the current time, when the code saw that the RTC was reset. There is no way to get the time from the USB host without some software running on the host, or like I did, some manual serial data entry.
    – Gerben
    Commented Apr 2, 2019 at 14:32

2 Answers 2


You can use __DATE__ and __TIME__ compiler time constants in IDE and do check inside of your setup() function if the RTC clock is zeroed then parse and set compile time values.

char cr[] = __DATE__;
char ct[] = __TIME__;

At the compile time these macros will be replaced with text constants "Apr 4 2019" and "10:35:22" respectively.


You could use softRTC library to get date/time from your system. So program flow could be get date/time from softRTC library during setup part and then use those variables in loop set your DS2321 RTC which will always be running till you poweroff.

  • 2
    softRTC is relying on the preprocessor. So each time you want to set the time you will have to open ArduinoIDE and compile+upload the sketch. This is not going to work in stand alone. Beside Atmel only guarantees 10.000 write cycles when uploading code.
    – Kwasmich
    Commented Apr 2, 2019 at 14:26
  • I can't find softRTC library. how does it solve the use of DS3231 without battery?
    – Juraj
    Commented Apr 2, 2019 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.