Skip to content
Free Delivery on Orders Above Rs 999/- Pan-India
Cash on Delivery Available for Orders above Rs.500/- and Upto Rs 3000/-
SAVE more when you BUY more. Upto 30% Off on BULK PURCHASE
GST Invoices for Your Business
Dedicated Technical Support Team
Safely Delivering Genuine Products PAN INDIA

DS3231 vs DS1307 RTC Module: Accuracy, Wiring, and Arduino Code

DS3231 vs DS1307 RTC Module: Accuracy, Wiring, and Arduino Code
-
Written By - Robocraze -
📅 Updated on 18 Nov 2026
✨ Summarize with AI
✅ Prompt copied

Summary

DS3231 or DS1307? This guide compares both RTC modules on accuracy, voltage and features, then shows how to wire a DS3231 to Arduino, set and read time with RTClib, use alarms and the temperature sensor, and avoid the coin cell charging problem on common ZS-042 boards. Our pick: the DS3231.

DS3231 vs DS1307 RTC Module: Accuracy, Wiring, and Arduino Code - Cover Image

The DS3231 wins for almost every project. It has a built-in temperature-compensated crystal accurate to about ±2 ppm, which is roughly a minute a year. It runs on 3.3V or 5V and adds alarms and a temperature sensor. The DS1307 drifts more and needs 5V. For most projects, we pick the DS3231.

Feature DS3231 DS1307
Crystal Built-in, temperature-compensated (TCXO) External 32.768 kHz crystal
Accuracy ±2 ppm (0 to 40°C), about 1 minute/year Depends on the crystal and temperature, often minutes/month
Supply voltage 2.3V to 5.5V (3.3V and 5V boards) 4.5V to 5.5V (5V only)
I2C speed Up to 400 kHz Up to 100 kHz
I2C address 0x68 0x68
Alarms 2 programmable alarms + interrupt pin None
Temperature sensor Yes, ±3°C No
Battery-backed RAM None (module adds AT24C32 EEPROM) 56 bytes + module EEPROM
Best for Data loggers, alarms, ESP32, outdoor builds Budget 5V clocks where small drift is fine

Pick your module

What an RTC Module Does and Why Arduino Needs One

A real time clock module is a tiny board that counts seconds, minutes, hours, days, months, and years on its own. It has its own coin cell, so it keeps counting even when your Arduino is switched off.

An Arduino can count time with millis(), but it has two weaknesses:

  • It forgets. Every reset or power cut starts the count from zero again.
  • It drifts. The board's resonator is not built for precise timekeeping, so the count wanders over days.

The RTC module solves both. Your Arduino simply asks, "What time is it?" over I2C, and gets the answer back in a few microseconds.

How it keeps time: The RTC chip counts pulses from a 32.768 kHz quartz crystal. That number is 2¹⁵, so the chip divides it down to exactly one tick per second. The difference between our two chips is how steady that crystal stays. The DS1307 uses a separate crystal on the board, and its frequency shifts as the room heats up and cools down. The DS3231 has the crystal sealed inside the chip and measures its own temperature every 64 seconds to correct for that shift.

Where you will use one:

  • Data loggers that timestamp sensor readings
  • Digital clocks and alarm clocks
  • Timers that switch pumps, lights, or relays at set times
  • Attendance and access-control systems
  • Battery projects that sleep and wake up on a schedule
DS3231 & DS1307 RTC modules

Components and Supplies

SmartElex DS3231 RTC Module with EEPROM (I2C, AT24C32)SmartElex DS3231 RTC Module with EEPROM (I2C, AT24C32)

    SmartElex DS3231 RTC Module with EEPROM (I2C, AT24C32)

    SmartElex DS3231 RTC Module with EEPROM (I2C, AT24C32) The SmartElex DS3231 RTC Module with EEPROM is a high-precision RTC module designed for accurate date and time tracking in embedded systems and IoT projects. Based on the DS3231 chip with an integrated temperature-compensated crystal oscillator...
    Rs 819/-
    Rs 819/-
    Rs 999/-
    Save Rs 180/-
    DS3231 Real Time Clock Module (No Battery) – Accurate RTC for time-based applications.-RTC Module -RobocrazeDS3231 Real Time Clock Module (No Battery) – Accurate RTC for time-based applications.-RTC Module -Robocraze

      DS3231 Real Time Clock Memory Module without Battery

      DS3231 Real Time Clock Memory Module without Battery DS3231 is a low-cost, extremely accurate I2C real-time clock (RTC), with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. Real-time clock generator seconds, minutes, hours, day, date, month and year timing and provide valid until the...
      Rs 315/-
      Rs 315/-
      Rs 349/-
      Save Rs 34/-
      DS1307 Real Time Clock Module – Real-time clock module for timekeeping applications - RobocrazeDS1307 Real Time Clock Module – Real-time clock module for timekeeping applications - Robocraze

        DS1307 Real Time Clock Module

        DS1307 Real Time Clock Module The DS1307 is a low-power clock/calendar with 56 bytes of battery backup SRAM. The clock/calendar provides seconds, minutes, hours, day, date, month and year-qualified data. The end date of each month is automatically adjusted, especially for months with less...
        Rs 49/-
        Rs 49/-
        Rs 69/-
        Save Rs 20/-
        Original Arduino Uno R3 microcontroller board with ATmega328P and USB port - Arduino Uno Board -RobocrazeOriginal Arduino Uno R3 microcontroller board with ATmega328P and USB port - Arduino Uno Board -Robocraze

        Arduino Uno R3 Original

        Arduino UNO R3 Original The Arduino Uno R3 is a microcontroller board based on the ATmega328P chip and is widely recognized as the best original Arduino Uno board for beginners and projects. This board has 14 digital I/O pins (6 support PWM), 6 analog...
        Rs 2,750/-
        Rs 2,750/-
        Rs 3,499/-
        Save Rs 749/-
        Arduino Uno R3 Board compatibleArduino Uno R3 Board compatible

          Arduino Uno R3 Board compatible

          Arduino Uno R3 Compatible Board  The Arduino Uno R3 ATMEGA328P Development Board is more than just a microcontroller board; it's a gateway to endless possibilities in the world of electronics and programming. For hobbyists, students, and makers, it stands out as the best Arduino Uno...
          Rs 429/-
          Rs 429/-
          Rs 699/-
          Save Rs 270/-
          CR2032 3V Lithium Coin Battery -Batteries & Power Supply -Other Batteries -RobocrazeCR2032 3V Lithium Coin Battery -Batteries & Power Supply -Other Batteries -Robocraze

            CR2032 3V Lithium Coin Battery

            CR2032 3V Lithium Coin Battery The CR2032 3V Lithium Coin Battery is widely utilized due to its dependable and long-lasting power supply for a variety of small electronic devices. This cr2032 battery includes calculators, wristwatches, remote controls, various medical devices, fitness gadgets, machines, toys,...
            Rs 15/-
            Rs 15/-
            Rs 19/-
            Save Rs 4/-

            DS3231 Pinout and Wiring (I2C 0x68)

            The DS3231 module talks over I2C, so you need just four wires to get started. The common ZS-042 board has a 6-pin header on one side and a 4-pin pass-through header on the other, for chaining more I2C devices.

            DS3231 pinout
            Pin Function Connect it?
            VCC Power, 3.3V or 5V Yes
            GND Ground Yes
            SDA I2C data Yes
            SCL I2C clock Yes
            SQW Square wave or alarm interrupt output (active LOW) Only for alarms
            32K 32.768 kHz clock output Usually no

            I2C addresses: The DS3231 sits at 0x68. The AT24C32 EEPROM on the same board sits at 0x57 by default. The DS1307 also uses 0x68, so you cannot run both on the same bus.

            Wiring to Arduino Uno

            • VCC → 5V
            • GND → GND
            • SDA → A4
            • SCL → A5
            • SQW → D2 (optional, for alarms)
            DS3231 to Arduino Uno wiring · 4 required wires + optional SQW

            The dashed SQW wire is only needed for alarms. D2 is used because it is one of the Uno's two interrupt pins (D2 and D3).

            On an Uno R3, the SDA and SCL pins next to AREF are the same as A4 and A5, so either pair works. Check our Arduino Uno pin diagram guide if you are unsure where they are.

            Board SDA SCL VCC
            Arduino Uno / Nano A4 A5 5V
            Arduino Mega 2560 20 21 5V
            Arduino Leonardo 2 3 5V
            ESP32 GPIO 21 GPIO 22 3.3V

            The module already has pull-up resistors on SDA and SCL, so you do not need to add your own. The DS1307 module wires up exactly the same way, but it must get 5V.

            Most communication problems come from swapped SDA and SCL wires, and not from faulty modules. If the code cannot find the RTC, check those two first.

            Code: Set and Read Time With RTClib

            The easiest way to use an RTC module with Arduino is the RTClib library by Adafruit. It supports the DS3231, DS1307, and PCF8523 with almost identical code.

            Install it:

            1. Open the Arduino IDE and go to Sketch → Include Library → Manage Libraries.
            2. Search for RTClib and install the one by Adafruit.
            3. Click Install All when it asks about dependencies.

            Now upload this sketch:

            
            // DS3231 RTC: set and read time with RTClib
            #include <Wire.h>
            #include <RTClib.h>
            
            RTC_DS3231 rtc;
            
            const char daysOfWeek[7][12] = {
              "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
            };
            
            void setup() {
              Serial.begin(9600);
              if (!rtc.begin()) {
                Serial.println("Couldn't find DS3231. Check SDA/SCL wiring!");
                while (1) delay(10);
              }
            
              // Set the time only when the RTC has lost power (new module or dead cell)
              if (rtc.lostPower()) {
                Serial.println("RTC lost power, setting time to compile time...");
                rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
                // Or set an exact time: rtc.adjust(DateTime(2026, 11, 6, 10, 30, 0));
              }
            }
            
            void loop() {
              DateTime now = rtc.now();
              char buf[] = "YYYY-MM-DD hh:mm:ss";
              Serial.print(now.toString(buf));
              Serial.print("  ");
              Serial.println(daysOfWeek[now.dayOfTheWeek()]);
              delay(1000);
            }
            

            Open the Serial Monitor at 9600 baud. On a brand-new module, you should see this:

            
            RTC lost power, setting time to compile time...
            2026-11-06 10:19:28  Friday
            2026-11-06 10:19:29  Friday
            2026-11-06 10:19:30  Friday
            2026-11-06 10:19:31  Friday
            2026-11-06 10:19:32  Friday
            RTC module Arduino code serial output
            
            

            How the code works

            • rtc.begin() checks that the module answers at address 0x68. If it does not, you get the wiring error.
            • rtc.lostPower() returns true on a new module or after the coin cell dies. Only then do we set the clock, so a reset never overwrites a good time.
            • DateTime(F(__DATE__), F(__TIME__)) is the moment your sketch was compiled. Uploading takes a few seconds, so the clock may start a few seconds behind. For exact time, use the commented line with your own values.
            • rtc.now() returns a DateTime object. Read parts with .year(), .month(), .day(), .hour(), .minute() and .second(), or get a Unix timestamp with .unixtime() for data logs.

            Using a DS1307 instead? Change RTC_DS3231 rtc; to RTC_DS1307 rtc; and replace rtc.lostPower() with !rtc.isrunning(). Everything else stays the same.

            Using Alarms and the Temperature Sensor

            This is where the DS3231 pulls ahead. It has two alarms that pull the SQW pin LOW at a set time, which can trigger an interrupt on your Arduino. That means no constant time checking in loop(), and your board can even sleep until the alarm wakes it.

            The sketch below logs the temperature once a minute. Wire SQW to D2 first.

            
            // DS3231 RTC: once-a-minute alarm interrupt + temperature logging
            #include <Wire.h>
            #include <RTClib.h>
            
            RTC_DS3231 rtc;
            
            const byte ALARM_PIN = 2;          // D2 = interrupt pin on Uno/Nano
            volatile bool alarmFired = false;
            
            void onAlarm() {
              alarmFired = true;               // keep the ISR short: just set a flag
            }
            
            void setup() {
              Serial.begin(9600);
              if (!rtc.begin()) {
                Serial.println("Couldn't find DS3231. Check SDA/SCL wiring!");
                while (1) delay(10);
              }
            
              if (rtc.lostPower()) {
                rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
              }
            
              rtc.disable32K();                    // 32K pin not needed
              rtc.writeSqwPinMode(DS3231_OFF);     // SQW pin = alarm interrupt output
              rtc.clearAlarm(1);
              rtc.clearAlarm(2);
              rtc.disableAlarm(2);
            
              // Alarm 1 fires whenever seconds == 00, i.e. once a minute
              // (only the seconds field matters in this mode)
              rtc.setAlarm1(DateTime(2000, 1, 1, 0, 0, 0), DS3231_A1_Second);
            
              pinMode(ALARM_PIN, INPUT_PULLUP);    // SQW is open-drain, goes LOW on alarm
              attachInterrupt(digitalPinToInterrupt(ALARM_PIN), onAlarm, FALLING);
            
              Serial.println("Logging temperature once a minute...");
            }
            
            void loop() {
              if (alarmFired) {
                alarmFired = false;
                rtc.clearAlarm(1);                 // must clear, or SQW stays LOW
                DateTime now = rtc.now();
                char buf[] = "YYYY-MM-DD hh:mm:ss";
                Serial.print(now.toString(buf));
                Serial.print("  Temp: ");
                Serial.print(rtc.getTemperature());
                Serial.println(" C");
              }
            }
            

            Serial Monitor output:

            
            Logging temperature once a minute...
            2026-11-06 10:43:00  Temp: 27.25 C
            2026-11-06 10:44:00  Temp: 27.25 C
            2026-11-06 10:45:00  Temp: 27.50 C
            

            Alarm modes you can use

            Mode Fires Example
            DS3231_A1_PerSecond Every second Blink or heartbeat
            DS3231_A1_Second When seconds match (once a minute) Logging every minute
            DS3231_A1_Minute When minutes + seconds match (once an hour) Hourly readings
            DS3231_A1_Hour When hours + minutes + seconds match (once a day) 6:00 AM plant watering

            For a daily 6:00 AM alarm, use rtc.setAlarm1(DateTime(2000, 1, 1, 6, 0, 0), DS3231_A1_Hour);.

            Two rules to remember:

            • Always call rtc.clearAlarm(1) after an alarm. If you skip it, SQW stays LOW and the alarm never fires again.
            • Use an interrupt pin. On the Uno and Nano, only D2 and D3 support attachInterrupt().

            About the temperature sensor: rtc.getTemperature() reads the chip's own sensor, which the DS3231 uses to correct its crystal. It updates every 64 seconds in 0.25°C steps and is accurate to about ±3°C. It is handy for a rough room reading, but use a DHT22 or DS18B20 if you need a precise one.

            Coin Cell Battery: Which One and the Charging Circuit Warning

            The coin cell is what keeps your RTC ticking when the Arduino is off. Pick the wrong one, and you risk a swollen or leaking battery.

            CR2032 LIR2032
            Type Non-rechargeable lithium Rechargeable lithium-ion
            Voltage 3.0V 3.6V to 3.7V nominal (4.2V when full)
            Capacity About 220 mAh About 40 mAh
            Safe to charge? No Yes, up to 4.2V
            Easy to buy? Very Less common

            The problem with common DS3231 modules

            Most DS3231 boards, including the popular ZS-042, include a simple charging circuit. It is just a 200 Ω resistor (often marked "201") and a diode, feeding VCC into the battery. It was designed for an LIR2032.

            Here is the catch:

            • With a CR2032 fitted: this circuit tries to push current into a battery that must never be charged. Over time, that can make it swell or leak.
            • Even with an LIR2032 at 5V: the circuit has no charge control, so the cell can be pushed past its safe 4.2V limit.
            • At 3.3V: the voltage after the diode is too low to properly charge an LIR2032 anyway.
            DS3231 module charging circuit resistor

            The simple fix

            1. Find the 200 Ω resistor (marked "201") or the diode next to it near the 6-pin header.
            2. Remove it with a soldering iron, or carefully cut one of its legs.
            3. Fit a regular CR2032. The DS3231 draws so little from the battery that a fresh CR2032 should last several years.

            This turns off charging completely and is the setup we recommend for most projects.

            Some DS1307 "Tiny RTC" boards also have a charging circuit meant for an LIR2032. Check your board's listing or schematic before fitting a CR2032.

            Build Next

            Your RTC is running. Put it to work in a real project:

            Final Thoughts

            When it comes to DS3231 vs DS1307, the answer is simple for most makers. The DS3231 costs a little more but keeps time to about a minute a year, works with both 3.3V and 5V boards, and gives you alarms for free. The DS1307 still works for basic 5V clocks on a tight budget.

            Whichever you choose, remember the two lessons from this guide: set the time only when lostPower() says so, and check that charging circuit before you fit a CR2032.

            Grab a DS3231 RTC module and start building. Got a question or a project to share? Drop it in the comments below.

            Excerpt

            DS3231 vs DS1307 compared: accuracy, voltage, alarms and pinout, plus RTClib Arduino code and the coin cell charging warning most guides skip.

            Frequently Asked Questions

            1. Which is better, DS3231 or DS1307?

            The DS3231 is better for almost every project. It is far more accurate, works on 3.3V and 5V, and adds alarms and a temperature sensor. The DS1307 only makes sense for a very low-cost 5V build where a little drift is fine.

            2. How accurate is the DS3231?

            The DS3231 is accurate to ±2 ppm between 0°C and 40°C, and ±3.5 ppm from −40°C to 85°C. In practice, that is roughly a minute of drift per year.

            3. What is the I2C address of DS3231?

            The DS3231 uses I2C address 0x68. The AT24C32 EEPROM on most DS3231 modules uses 0x57. You can confirm both with an I2C scanner sketch.

            4. Does the RTC keep time without power?

            Yes. When main power is removed, the module switches to its coin cell and keeps counting. It will have the correct time when your Arduino powers up again.

            5. Can we use a DS3231 with ESP32?

            Yes. The DS3231 runs at 3.3V, so connect VCC to 3.3V, SDA to GPIO 21 and SCL to GPIO 22. The same RTClib code works. For other pins, call Wire.begin(SDA_PIN, SCL_PIN); before rtc.begin().

            6. Why is my RTC showing the wrong time?

            The usual causes are:

            • A few seconds behind: the time was set at compile time, before uploading finished.
            • Resets on every upload: rtc.adjust() runs every time. Keep it inside the lostPower() check.
            • Off by hours: the RTC stores whatever time you gave it. It does not handle time zones or daylight saving.
            • Forgets after unplugging: the coin cell is missing, dead or fitted the wrong way.
            • Shows 2165-165-165: the I2C read failed. Check wiring and power.

            7. How long does the coin cell last in a DS3231 module?

            A fresh CR2032 should last several years, because the DS3231 draws only a few microamps from it. Remove the charging resistor first if you use a CR2032 (see the battery section above).

            8. Will my DS1307 code work on a DS3231?

            Mostly yes. Both use address 0x68 and similar time registers. With RTClib, change RTC_DS1307 to RTC_DS3231 and swap isrunning() for lostPower().

            Prev Post
            Next Post

            Leave a comment

            Please note, comments need to be approved before they are published.

            Thanks for subscribing!

            This email has been registered!

            Shop the look

            Choose Options

            Edit Option
            Back In Stock Notification
            Compare
            Product SKU Description Collection Availability Product Type Other Details

            Choose Options

            this is just a warning
            Login
            Shopping Cart
            0 items
            FREE SHIPPING!
            ₹100 OFF
            ₹200 OFF
            ₹999
            ₹2500
            ₹4900
            WhatsApp Chat Chat