

The DS-3231 is a highly accurate real-time clock (RTC) module with an integrated temperature-compensated crystal oscillator (TCXO). It is designed to provide precise timekeeping by tracking seconds, minutes, hours, day, date, month, and year, with leap-year compensation valid up to 2100. The DS-3231 is widely used in applications requiring reliable timekeeping, such as data logging, alarms, and scheduling in microcontroller-based projects and embedded systems.








The DS-3231 offers robust performance and features that make it a preferred choice for timekeeping applications. Below are its key technical specifications:
The DS-3231 module typically comes with a 5-pin header. Below is the pinout description:
| Pin | Name | Description |
|---|---|---|
| 1 | GND | Ground connection |
| 2 | VCC | Power supply input (2.3V to 5.5V) |
| 3 | SDA | Serial Data Line for I²C communication |
| 4 | SCL | Serial Clock Line for I²C communication |
| 5 | SQW/INT | Square-wave output or interrupt output (configurable via software) |
The DS-3231 is easy to integrate into circuits, especially with microcontrollers like the Arduino UNO. Below are the steps to use the DS-3231 in a project:
VCC pin to the Arduino's 5V pin and the GND pin to the Arduino's GND.SDA pin to the Arduino's A4 pin and the SCL pin to the Arduino's A5 pin (for older Arduino boards). For newer boards like the Arduino UNO R3, use the dedicated SDA and SCL pins.SQW/INT pin to a digital input pin on the Arduino.The following example demonstrates how to read the time and date from the DS-3231 using the popular RTClib library:
#include <Wire.h>
#include <RTClib.h>
// Create an RTC object
RTC_DS3231 rtc;
void setup() {
Serial.begin(9600); // Initialize serial communication
Wire.begin(); // Initialize I²C communication
if (!rtc.begin()) {
Serial.println("Couldn't find RTC. 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.print(now.second(), DEC);
Serial.println();
delay(1000); // Wait for 1 second before updating
}
SDA and SCL) may require pull-up resistors (typically 4.7kΩ) if not already included on the module.RTClib or DS3231 for simplified communication and configuration.RTC Not Detected
SDA and SCL are connected to the correct pins. Verify the power supply voltage.Incorrect Time or Date
rtc.adjust() function to set the correct time and date.No Output on Serial Monitor
Serial.begin(9600) is called in the setup() function and the Serial Monitor is set to 9600 baud.Square-Wave Output Not Working
Q1: Can the DS-3231 operate without a backup battery?
A1: Yes, but it will lose track of time when the main power supply is disconnected.
Q2: How accurate is the DS-3231?
A2: The DS-3231 has an accuracy of ±2 ppm from 0°C to +40°C, which translates to a drift of about 1 minute per year.
Q3: Can I use the DS-3231 with 3.3V microcontrollers?
A3: Yes, the DS-3231 operates within a voltage range of 2.3V to 5.5V, making it compatible with both 3.3V and 5V systems.
Q4: What happens if the temperature sensor fails?
A4: The DS-3231 will continue to function as a standard RTC, but its accuracy may degrade without temperature compensation.