Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use DS 3231 RTC: Examples, Pinouts, and Specs

Image of DS 3231 RTC
Cirkit Designer LogoDesign with DS 3231 RTC in Cirkit Designer

Introduction

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!
Dual RTC DS3231 Synchronization with Glyph C3 Microcontroller
Image of DS: A project utilizing DS 3231 RTC in a practical application
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.
Cirkit Designer LogoOpen Project in Cirkit Designer
ESP32-Based Real-Time Clock Synchronization
Image of DS3231: A project utilizing DS 3231 RTC in a practical application
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.
Cirkit Designer LogoOpen Project in Cirkit Designer
ESP32-Based Real-Time Clock Synchronization
Image of RTC: A project utilizing DS 3231 RTC in a practical application
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.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO Controlled Relay with DS3231 RTC
Image of Hooter connections: A project utilizing DS 3231 RTC in a practical application
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.
Cirkit Designer LogoOpen Project in Cirkit Designer

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!
Image of DS: A project utilizing DS 3231 RTC in a practical application
Dual RTC DS3231 Synchronization with Glyph C3 Microcontroller
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.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of DS3231: A project utilizing DS 3231 RTC in a practical application
ESP32-Based Real-Time Clock Synchronization
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.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of RTC: A project utilizing DS 3231 RTC in a practical application
ESP32-Based Real-Time Clock Synchronization
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.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Hooter connections: A project utilizing DS 3231 RTC in a practical application
Arduino UNO Controlled Relay with DS3231 RTC
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.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications and Use Cases

  • Time-stamping data in data logging systems
  • Alarm clock and timer applications
  • Scheduling tasks in embedded systems
  • Real-time event tracking in IoT devices
  • Calendar-based automation systems

Technical Specifications

The DS3231 RTC module is designed for high accuracy and ease of use. Below are its key technical details:

Key Technical Details

  • Operating Voltage: 3.3V to 5.5V
  • Timekeeping Accuracy: ±2 ppm (parts per million) from 0°C to +40°C
  • Interface: I2C (2-wire)
  • Temperature Range: -40°C to +85°C
  • Backup Battery Support: CR2032 coin cell battery
  • Memory: Includes an AT24C32 EEPROM (32KB) for additional data storage
  • Oscillator: Built-in temperature-compensated crystal oscillator (TCXO)
  • Alarm Functions: Two programmable alarms
  • 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

  1. Power the Module: Connect the VCC pin to a 3.3V or 5V power source and the GND pin to ground.
  2. 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.
  3. 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.
  4. 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

  1. 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).
  2. 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.
  3. 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.
  4. 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.