ESP32 DS3231 / AT24C32 Real-Time Clock (RTC)

DS3231 / AT24C32 Real-Time Clock (RTC) image

DS3231 / AT24C32

Protocol: I2C

Overview

The DS3231 is a highly accurate I²C real-time clock with an integrated temperature-compensated crystal oscillator, providing precise timekeeping and calendar functions, along with programmable alarms and square-wave output, suitable for applications requiring reliable timekeeping.

About DS3231 / AT24C32 Real-Time Clock (RTC)

The DS3231 is an ultra-accurate I²C real-time clock (RTC) with a built-in temperature-compensated crystal oscillator (TCXO), ensuring stable timekeeping even under temperature fluctuations. It provides leap-year compensation up to 2100 and supports battery backup for uninterrupted operation.

Key Features

  • High-Precision RTC – More accurate than the DS1307.
  • Built-in Temperature Compensation – Ensures consistent timekeeping across temperature changes.
  • Battery Backup Support – Keeps time even during power loss.
  • I²C Communication – Simple integration with ESP32, Arduino, and other microcontrollers.

With its precision and reliability, the DS3231 is perfect for data logging, alarms, scheduling, and real-time event tracking. 🚀

Where to Buy

DS3231 / AT24C32 Real-Time Clock (RTC)

Starting from

3.50$ per unit

Amazon com
Amazon.com Ships worldwide
View Price
Amazon de
Amazon.de Ships to EU
View Price
Aliexpress
AliExpress Best value
View Price

Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.

Technical Specifications

Timekeeping Range Seconds to Years (with Leap-Year Compensation up to 2100)
Operating Voltage 2.3V to 5.5V
Timekeeping Accuracy ±2 ppm from 0°C to +40°C; ±3.5 ppm from -40°C to +85°C
Interface I²C (up to 400 kHz)
Clock Output Frequencies 1 Hz, 1.024 kHz, 4.096 kHz, 8.192 kHz
Alarm Function Two Programmable Time-of-Day Alarms
Temperature Sensor Accuracy ±3°C
Operating Temperature 0°C to +70°C (Commercial); -40°C to +85°C (Industrial)

Pinout Configuration

The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32.

The DS3231 pinout is as follows:

  • 32kHz: 32.768 kHz output (optional).
  • VBAT: Backup battery input.
  • INT/SQW: Interrupt or square-wave output.
  • SCL: Serial Clock Line for I²C communication.
  • GND: Ground connection.
  • SDA: Serial Data Line for I²C communication.
  • RST: Reset input/output.
  • VCC: Power supply input (2.3V to 5.5V).

Wiring with ESP32

To interface the DS3231 with a microcontroller like Arduino or ESP32, connect VCC to a 3.3V or 5V power supply, GND to ground, SDA to the microcontroller's I²C data pin, and SCL to the I²C clock pin. The VBAT pin can be connected to a backup battery to maintain timekeeping during power loss. The INT/SQW pin can be connected to a digital input on the microcontroller if interrupt or square-wave output functionality is required. The RST pin can be used for manual reset control if needed.

Troubleshooting Guide

Common Issues

⏰ RTC Not Advancing Time Correctly

📅 Incorrect or Corrupted Date and Time Display

🌡️ RTC Module Overheating

🕐 Time Resets After Power Loss

Debugging Tips

🔍 Serial Monitor

⚡ Voltage Checks

Code Examples

Arduino Example

C++
🔧

ESP-IDF Example

C++
🏠

ESPHome Example

YAML
🛠️

PlatformIO Example

C++
🐍

MicroPython Example

Python

Conclusion

The ESP32 DS3231 / AT24C32 Real-Time Clock (RTC) is a powerful RTC sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.

For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.

Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.