

The DS3231 is a highly accurate real-time clock (RTC) module designed to maintain precise time and date information. It features an integrated temperature-compensated crystal oscillator (TCXO) for enhanced accuracy and includes an onboard EEPROM for non-volatile data storage. The module communicates via the I2C interface, making it easy to integrate with microcontrollers like Arduino, Raspberry Pi, and others. Additionally, the DS3231 includes a backup battery input, ensuring uninterrupted timekeeping during power outages.








| Parameter | Specification |
|---|---|
| Supply Voltage | 2.3V to 5.5V |
| Communication Interface | I2C (Two-Wire Interface) |
| Timekeeping Accuracy | ±2 ppm (0°C to +40°C) |
| Operating Temperature Range | -40°C to +85°C |
| Backup Battery Voltage | 3.0V (CR2032 recommended) |
| EEPROM Size | 32 KB |
| Oscillator Stability | Temperature-compensated crystal |
| Pin Name | Pin Number | Description |
|---|---|---|
| GND | 1 | Ground connection |
| VCC | 2 | Power supply input (2.3V to 5.5V) |
| SDA | 3 | I2C data line |
| SCL | 4 | I2C clock line |
| SQW/INT | 5 | Square wave or interrupt output (optional) |
| 32K | 6 | 32.768 kHz output (optional) |
VCC pin to a 3.3V or 5V power source and the GND pin to ground.SDA and SCL pins to the corresponding I2C pins on your microcontroller. For Arduino UNO, connect:SDA to A4SCL to A5SQW/INT pin for square wave or alarm interrupts.32K pin for a 32.768 kHz clock signal if required.SDA and SCL lines for I2C communication.RTClib for Arduino to simplify communication with the DS3231.Below is an example of how to use the DS3231 RTC module with an Arduino UNO to read and display the current time and date:
#include <Wire.h>
#include "RTClib.h"
// Create an RTC_DS3231 object to interact with the module
RTC_DS3231 rtc;
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 baud
Wire.begin(); // Initialize I2C communication
if (!rtc.begin()) {
Serial.println("Couldn't find RTC module. Check connections!");
while (1); // Halt execution if RTC is not found
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, setting the time...");
// Set the RTC to the current date and time
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now(); // Get the current date and time
// Print the current date and time to the Serial Monitor
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
delay(1000); // Wait for 1 second before updating
}
RTClib library simplifies communication with the DS3231. Install it via the Arduino Library Manager.rtc.adjust() function sets the RTC to the current date and time based on the computer's clock when the code is compiled.RTC Not Detected:
Incorrect Time or Date:
rtc.adjust() function to set the correct time and date.No Output on Serial Monitor:
Serial.begin(9600) matches the Serial Monitor's baud rate.EEPROM Not Accessible:
Q: Can the DS3231 operate without a backup battery?
A: Yes, but it will lose timekeeping functionality during power outages.
Q: What is the default I2C address of the DS3231?
A: The default I2C address is 0x68.
Q: How long does the backup battery last?
A: A CR2032 battery can typically last several years, depending on usage and environmental conditions.
Q: Can I use the DS3231 with a 3.3V microcontroller?
A: Yes, the DS3231 is compatible with both 3.3V and 5V systems.
This concludes the documentation for the DS3231 RTC Module with EEPROM.