

The Adafruit RTC DS3231 is a highly accurate real-time clock (RTC) module designed to keep track of the current time and date, even during power outages. It features an integrated temperature-compensated crystal oscillator (TCXO) to ensure high precision and low drift over time. The DS3231 is ideal for applications requiring precise timekeeping, such as data logging, alarms, and scheduling tasks in embedded systems. Its low power consumption makes it particularly suitable for battery-powered projects.








The Adafruit RTC DS3231 module offers the following key technical details:
| Parameter | Value |
|---|---|
| Supply Voltage | 2.3V to 5.5V |
| Timekeeping Current | 3.5 µA (at 3.3V, typical) |
| Temperature Accuracy | ±3°C |
| Timekeeping Accuracy | ±2 ppm (0°C to +40°C) |
| Communication Interface | I2C (Inter-Integrated Circuit) |
| Operating Temperature | -40°C to +85°C |
| Backup Battery Support | CR2032 coin cell (not included) |
The DS3231 module has the following pinout:
| Pin | Name | Description |
|---|---|---|
| 1 | GND | Ground connection |
| 2 | VCC | Power supply input (2.3V to 5.5V) |
| 3 | SDA | I2C data line for communication with the microcontroller |
| 4 | SCL | I2C clock line for communication with the microcontroller |
| 5 | SQW | Square wave output (optional, can be used for alarms or periodic interrupts) |
| 6 | 32K | 32.768 kHz output (optional, for external clocking purposes) |
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 an Arduino UNO:SDA connects to A4.SCL connects to A5.SQW pin for square wave or alarm signals.32K pin for an external 32.768 kHz clock signal if needed.SDA and SCL lines if your microcontroller does not have internal pull-ups.0x68 by default.Below is an example of how to use the DS3231 with an Arduino UNO to read the current time and date. This code uses the popular RTClib library.
#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
// Check if the RTC is connected and working
if (!rtc.begin()) {
Serial.println("Couldn't find RTC. Check connections!");
while (1); // Halt the program if RTC is not found
}
// Check if the RTC lost power and set the time if necessary
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() {
// Get the current date and time from the RTC
DateTime now = rtc.now();
// 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
}
RTC Not Detected:
SDA and SCL connections. Ensure the I2C address is set to 0x68.Incorrect Time or Date:
rtc.adjust() function.No Output on Serial Monitor:
Serial.begin(9600) is called in setup() and the Serial Monitor is set to 9600 baud.Square Wave Output Not Working:
Q: Can the DS3231 module work without a backup battery?
A: Yes, but it will lose track of time when the main power is disconnected.
Q: What is the default I2C address of the DS3231?
A: The default I2C address is 0x68.
Q: Can I use the DS3231 with a 3.3V microcontroller?
A: Yes, the DS3231 supports a supply voltage range of 2.3V to 5.5V, making it compatible with both 3.3V and 5V systems.
Q: How accurate is the DS3231?
A: The DS3231 has an accuracy of ±2 ppm, which translates to a drift of about ±1 minute per year under typical conditions.