The DS3231 RTC module, manufactured by DORHEA (Part ID: DS3231 AT24C32), is a highly accurate real-time clock (RTC) designed to keep track of time and date. It features a temperature-compensated crystal oscillator (TCXO) to ensure precise timekeeping, even under varying environmental conditions. The module communicates via the I2C interface, making it easy to integrate with microcontrollers like Arduino, Raspberry Pi, and other embedded systems.
Explore Projects Built with DS 3231 RTC
Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
This circuit integrates two RTC DS3231 real-time clock modules with a Glyph C3 microcontroller. The RTC modules are connected to the microcontroller via I2C communication protocol, using the SCL and SDA lines for clock and data respectively. Both RTC modules and the microcontroller share a common power supply (3V3) and ground (GND), indicating that they operate at the same voltage level.
This circuit connects an ESP32 Devkit V1 microcontroller with an RTC DS3231 real-time clock module. The ESP32 provides power to the RTC and communicates with it via I2C, with D21 and D22 serving as the data (SDA) and clock (SCL) lines, respectively. The common ground (GND) ensures a reference point for the voltages, and the 3V3 pin from the ESP32 powers the RTC module.
This circuit connects an ESP32 microcontroller to a DS3231 Real Time Clock (RTC) module. The ESP32's Vin and GND pins are connected to the VCC and GND pins of the DS3231, providing power to the RTC. The SCL and SDA pins of the DS3231 are connected to the D22 and D21 pins of the ESP32, respectively, enabling I2C communication between the microcontroller and the RTC module.
This circuit features an Arduino UNO microcontroller connected to a DS3231 Real Time Clock (RTC) module and a 12V single-channel relay. The Arduino provides power to both the RTC and the relay, and it communicates with the RTC via I2C using the SDA and SCL lines connected to A4 and A5 respectively. The relay is controlled by the Arduino through a digital output on pin D13, allowing the Arduino to switch external loads on and off based on time events managed by the RTC.
Square Wave Output: Configurable frequency (1Hz, 4kHz, 8kHz, 32kHz)
Pin Configuration and Descriptions
The DS3231 RTC module has the following pinout:
Pin
Name
Description
1
GND
Ground connection
2
VCC
Power supply input (3.3V to 5.5V)
3
SDA
I2C data line (connect to microcontroller's SDA pin)
4
SCL
I2C clock line (connect to microcontroller's SCL pin)
5
SQW/OUT
Square wave output or interrupt output (optional, configurable via software)
6
32K
32kHz output (optional, used for external clocking applications)
Usage Instructions
The DS3231 RTC module is straightforward to use in a circuit. Below are the steps and best practices for integrating it into your project.
How to Use the Component in a Circuit
Power the Module: Connect the VCC pin to a 3.3V or 5V power source and the GND pin to ground.
Connect I2C Lines:
Connect the SDA pin to the SDA pin of your microcontroller.
Connect the SCL pin to the SCL pin of your microcontroller.
Optional Connections:
Use the SQW/OUT pin for square wave output or alarms if needed.
The 32K pin can be used for an external 32kHz clock signal.
Install Backup Battery: Insert a CR2032 coin cell battery into the battery holder to maintain timekeeping during power loss.
Important Considerations and Best Practices
Pull-Up Resistors: Ensure that the I2C lines (SDA and SCL) have pull-up resistors (typically 4.7kΩ). Some modules include these resistors by default.
Battery Backup: Always use a backup battery to maintain timekeeping when the main power supply is disconnected.
EEPROM Usage: The onboard AT24C32 EEPROM can be used to store additional data, such as configuration settings or logs.
Temperature Compensation: The DS3231 automatically adjusts for temperature variations, so no manual calibration is required.
Example Code for Arduino UNO
Below is an example of how to use the DS3231 RTC module with an Arduino UNO. This code sets the time and reads the current time and date.
#include <Wire.h>
#include <RTClib.h> // Include the Adafruit RTC library
RTC_DS3231 rtc; // Create an RTC object
void setup() {
Serial.begin(9600); // Initialize serial communication
Wire.begin(); // Initialize I2C communication
if (!rtc.begin()) {
Serial.println("Couldn't find RTC module!");
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 time and date
// Print the current time and date 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
}
Troubleshooting and FAQs
Common Issues and Solutions
RTC Not Detected by Microcontroller:
Ensure the SDA and SCL lines are correctly connected.
Check if pull-up resistors are present on the I2C lines.
Verify the I2C address of the module (default is 0x68).
Incorrect Time or Date:
If the RTC lost power, reinitialize the time using the rtc.adjust() function.
Ensure the backup battery is installed and functional.
Square Wave Output Not Working:
Verify that the SQW/OUT pin is configured correctly in the software.
Check the module's datasheet for square wave configuration commands.
EEPROM Not Accessible:
Ensure the EEPROM I2C address (0x57) is used when accessing the AT24C32 memory.
FAQs
Q: Can the DS3231 RTC module work without a backup battery?
A: Yes, but it will lose timekeeping functionality when the main power is disconnected.
Q: What is the default I2C address of the DS3231?
A: The default I2C address is 0x68.
Q: How accurate is the DS3231 RTC module?
A: The module has an accuracy of ±2 ppm from 0°C to +40°C, which translates to a drift of about ±1 minute per year.
Q: Can I use the DS3231 with a 3.3V microcontroller?
A: Yes, the module supports both 3.3V and 5V logic levels.
By following this documentation, you can effectively integrate and use the DS3231 RTC module in your projects.