Arduino DS3231 RTC with RTClib: Wiring, Code and Simulator

To build this Arduino DS3231 RTC with RTClib project you need an Arduino Uno and an RTC DS3231. The same RTClib with the more accurate DS3231 module. Make the 4 connections in the wiring table, upload the Arduino C++ code, and print rtc.getTemperature(): the DS3231 has a thermometer inside.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1RTC DS3231A precise real-time clock on I²C (0x68) with a coin-cell backup: the same time registers as the DS1307, read with RTClib (RTC_DS3231).

Wiring

#FromTo
1Arduino Uno 5VRTC DS3231 VCC
2Arduino Uno GNDRTC DS3231 GND
3Arduino Uno A4RTC DS3231 SDA
4Arduino Uno A5RTC DS3231 SCL

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an RTC DS3231 from the parts palette.
  3. Wire 1. Connect Arduino Uno 5V to RTC DS3231 VCC.
  4. Wire 2. Connect Arduino Uno GND to RTC DS3231 GND.
  5. Wire 3. Connect Arduino Uno A4 to RTC DS3231 SDA.
  6. Wire 4. Connect Arduino Uno A5 to RTC DS3231 SCL.
  7. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  8. Run it. Press Run. Print rtc.getTemperature(): the DS3231 has a thermometer inside.

Arduino C++ code

// RTClib with a DS3231: the same library, a more accurate clock chip.
#include <RTClib.h>

RTC_DS3231 rtc;

void setup() {
  Serial.begin(9600);
  if (!rtc.begin()) {
    Serial.println("DS3231 not found.");
    while (true) {}
  }
  rtc.adjust(DateTime(2026, 1, 15, 8, 0, 0));
}

void loop() {
  DateTime now = rtc.now();
  char line[16];
  snprintf(line, sizeof line, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
  Serial.println(line);
  delay(1000);
}

What to try

Print rtc.getTemperature(): the DS3231 has a thermometer inside.

Frequently asked questions

How do I wire the DS3231 RTC with RTClib project on an Arduino Uno?

Make 4 connections: Arduino Uno 5V to RTC DS3231 VCC; Arduino Uno GND to RTC DS3231 GND; Arduino Uno A4 to RTC DS3231 SDA; Arduino Uno A5 to RTC DS3231 SCL.

What parts do I need for this Arduino project?

An Arduino Uno and an RTC DS3231.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

The same RTClib with the more accurate DS3231 module.

More Arduino Uno projects