Ordered on weekdays before 14:00 = shipped the same day and delivered the next day in 98% of cases. Free returns 30-day reflection period 1-year warranty

Wiring diagram and code example

How to connect the DS3231 Real Time Clock Module I2C (high-precision RTC) to an Arduino UNO or ESP32, with an example sketch you can upload straight away.

DS3231 Real-Time Clock with Arduino Uno

This project connects a high-precision DS3231 RTC module to an Arduino Uno over I2C. The sketch sets the RTC to the compile time if power was lost, then reads and prints the formatted date, time, and onboard temperature sensor readings to the Serial Monitor every second.

Wiring diagram: DS3231 Real Time Clock Module I2C (high-precision RTC) on an Arduino UNO
Wiring diagram · Click to enlarge
Connection table: DS3231 Real Time Clock Module I2C (high-precision RTC) on an Arduino UNO
Connection table · Click to enlarge
DS3231_Real_Time_Clock_with_Arduino_Uno.ino · compiled and verified
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : DS3231 Real-Time Clock with Arduino Uno
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : DS3231 Real Time Clock Module I2C
 *  Libraries : RTClib 2.1.4
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

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

RTC_DS3231 rtc;

void setup() {
  Serial.begin(115200);
  while (!Serial);

  if (!rtc.begin()) {
    Serial.println(F("Couldn't find DS3231 RTC"));
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    Serial.println(F("RTC lost power, setting time to compile time..."));
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  Serial.println(F("DS3231 RTC initialized."));
}

void loop() {
  DateTime now = rtc.now();

  char dateBuffer[11];
  char timeBuffer[9];
  snprintf(dateBuffer, sizeof(dateBuffer), "%04d-%02d-%02d", now.year(), now.month(), now.day());
  snprintf(timeBuffer, sizeof(timeBuffer), "%02d:%02d:%02d", now.hour(), now.minute(), now.second());

  Serial.print(F("Date: "));
  Serial.print(dateBuffer);
  Serial.print(F(" | Time: "));
  Serial.print(timeBuffer);
  Serial.print(F(" | Temp: "));
  Serial.print(rtc.getTemperature());
  Serial.println(F(" C"));

  delay(1000);
}

Required libraries: RTClib 2.1.4

Wiring diagram and example code generated by Codey.online — https://www.codey.online

ESP32 Real-Time Clock with DS3231

This project reads the current date, time, and internal temperature from the DS3231 Real Time Clock module over I2C. Connect the module to the ESP32's 3.3V rail and default I2C pins, then open the Serial Monitor at 115200 baud to view the live timestamp.

Wiring diagram: DS3231 Real Time Clock Module I2C (high-precision RTC) on an ESP32 DevKit V1
Wiring diagram · Click to enlarge
Connection table: DS3231 Real Time Clock Module I2C (high-precision RTC) on an ESP32 DevKit V1
Connection table · Click to enlarge
ESP32_Real_Time_Clock_with_DS3231.ino · compiled and verified
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : ESP32 Real-Time Clock with DS3231
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : DS3231 Real Time Clock Module I2C
 *  Libraries : RTClib 2.1.4
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

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

RTC_DS3231 rtc;

void setup() {
  Serial.begin(115200);
  while (!Serial) { delay(10); }

  Wire.begin(21, 22); // SDA = GPIO 21, SCL = GPIO 22

  if (!rtc.begin()) {
    Serial.println("Couldn't find DS3231 RTC module!");
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, setting time to compilation time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {
  DateTime now = rtc.now();

  char buffer[30];
  snprintf(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d",
           now.year(), now.month(), now.day(),
           now.hour(), now.minute(), now.second());

  Serial.print("Current Time: ");
  Serial.print(buffer);
  Serial.print(" | Temp: ");
  Serial.print(rtc.getTemperature());
  Serial.println(" °C");

  delay(1000);
}

Required libraries: RTClib 2.1.4

Wiring diagram and example code generated by Codey.online — https://www.codey.online

DS3231 Real Time Clock Module I2C (high-precision RTC)

Real time clock module with the DS3231 chip (. This module ensures that the Arduino knows the exact time at any moment. By connecting the Arduino to the ´sqw´ pin, it is possible to generate an interrupt every second with which sensor values or a display can be addressed.

DS3231 module features:

Communication: I2C interface.
Keeps time accurately, even when the module is not connected (backup battery)
Year - month - day hour : minute : second
Connection for external trigger with interval (1Hz, 4kHz, 8kHz, 32kHz)
56 Bytes Non-volatile memory
Greater precision than the DS1307
Extra memory chip: AT24C32 (32K bytes)
Built-in temperature sensor (deviation of ±3 °C)

Supplied without battery

Please note use rechargeable battery LIR2032

Dimensions
Length: 3.9cm
Width: 2.2cm
Height: 1.2cm

  • DS3231 chip
  • AT24C32 chip
  • Temperature sensor
  • Backup battery

Why choose this product?

  • Accurate time – Keeps time precisely, even without power.
  • I2C interface – Communicates easily with Arduino via I2C.
  • Second pulse – SQW pin generates an interrupt every second.
  • Extra memory – Contains 56 bytes and an AT24C32 chip.
  • Temperature sensor – Built-in sensor with ±3 °C deviation.
Specifications
Dimensions3,9 x 2,2 x 1,2 cm
InterfaceI2C
Memory56 bytes
Extra memory chipAT24C32
Temperature deviation±3 °C

In the package

  • DS3231 RTC module

Frequently bought together

Total: € 7,29

Reviews

★★★★★ 5,0/5 1 review
  • ★★★★★J Lindhout

    Good product

Write a review
Your rating

Shipping & returns

Shipping

  • Parcel with track & trace€ 7,70Within 24 hours
  • Pick up at PostNL location€ 7,40Within 24 hours
  • Letterbox parcel€ 3,70Within 2 business days
  • Letterbox parcel 24 hours€ 4,55Within 24 hours
  • Pick up in storeFree
All about shipping

Returns

Not satisfied? You have 30 days after delivery to return the product.

All about returns

Recently viewed

Voltmeter 0V-100V Green

Voltmeter 0V-100V Green

€ 1,95
Trimpot Potentiometer 202 2K

Trimpot Potentiometer 202 2K

€ 0,50
Relay Module 5V | 8-channel

Relay Module 5V | 8-channel

€ 9,85
Color sensor TCS3200

Color sensor TCS3200

€ 8,85