Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use DS3231 RTC: Examples, Pinouts, and Specs

Image of DS3231 RTCDesign with DS3231 RTC in Cirkit Designer

Introduction

The DS3231 is a highly accurate, low-cost real-time clock (RTC) module with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. It maintains seconds, minutes, hours, day, date, month, and year information, with automatic adjustment for leap years and months with fewer than 31 days. The module communicates with a microcontroller via I2C protocol.

Explore Projects Built with DS3231 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 ESP32-Based Real-Time Clock Synchronization: A project utilizing DS3231 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.

Open Project in Cirkit Designer
Image of Dual RTC DS3231 Synchronization with Glyph C3 Microcontroller: A project utilizing DS3231 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.

Open Project in Cirkit Designer
Image of ESP32-Based Real-Time Clock Synchronization: A project utilizing DS3231 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.

Open Project in Cirkit Designer
Image of Arduino UNO with RTC DS3231 Timekeeping: A project utilizing DS3231 RTC in a practical application
Arduino UNO with RTC DS3231 Timekeeping

This circuit connects an Arduino UNO microcontroller with a DS3231 Real Time Clock (RTC) module. The Arduino provides 5V power and ground to the RTC and communicates with it via the I2C protocol using the A4 (SDA) and A5 (SCL) pins. The embedded code on the Arduino is used to initialize the RTC, check for power loss, set the current time if needed, and periodically read and print the current time to the serial monitor.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

Key Technical Details

Pin Configuration and Descriptions

Pin Number Name Description
1 VCC Power supply (2.3V to 5.5V)
2 GND Ground connection
3 SDA Serial Data Line for I2C communication
4 SCL Serial Clock Line for I2C communication
5 SQW Square Wave/Interrupt Output
6 32K 32kHz Output
7 RST Reset Input (Active Low)

Usage Instructions

How to Use the DS3231 in a Circuit

  1. Connect VCC to a 2.3V to 5.5V power supply.
  2. Connect GND to the ground of the power supply.
  3. Connect SDA and SCL to the I2C data and clock lines of the microcontroller.
  4. Optionally, connect SQW to an interrupt pin on the microcontroller if square wave or alarm interrupt functionality is needed.
  5. Optionally, connect 32K to an input pin if a 32kHz clock signal is required.
  6. If a reset feature is needed, connect RST to a digital output pin; otherwise, it can be left unconnected or pulled high.

Important Considerations and Best Practices

Example Code for Arduino UNO

#include <Wire.h>
#include <RTClib.h>

RTC_DS3231 rtc;

void setup() {
  Serial.begin(9600);
  
  // Check if the RTC is connected correctly
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  // Check if the RTC lost power and if so, set the time
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // The following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {
  DateTime now = rtc.now();
  
  // Print the current date and time
  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);
}

Troubleshooting and FAQs

Common Issues Users Might Face

Solutions and Tips for Troubleshooting

FAQs