How to wire a DS3231 RTC to an Arduino Nano
To wire a DS3231 RTC to an Arduino Nano, connect VCC to 5V, GND to GND, SCL to pin A5 and SDA to pin A4. The module carries its own I2C pull-ups, so the bus needs no extra resistors, and the chip answers at the fixed address 0x68. The sketch below uses the RTClib (RTClib.h) library. It sets the clock if it lost power and prints the date, the time and the chip temperature every second.
- 5 V logic
- Library: RTClib.h
- 4 wires
DS3231 RTC to Arduino Nano wiring table
Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.
| DS3231 RTC pin | Arduino Nano pin | Wire color | Why |
|---|---|---|---|
| VCC | 5V | red | Most DS3231 modules run from 3.3 to 5.5 V. |
| GND | GND | blue | Common ground. |
| SCL | pin A5 | cyan | I2C clock. The module has its own pull-up resistors. |
| SDA | pin A4 | violet | I2C data. |
Power and logic levels for DS3231 RTC and Arduino Nano
Logic level
The Arduino Nano’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.
Supply
The DS3231 RTC takes 5 V from 5V. That is the Arduino Nano’s 5 V rail, so the part shares the current the board can supply.
This pair
The Nano has the Uno’s chip, so I2C is A4 (SDA) and A5 (SCL), on the analog side of the board next to A6 and A7. The module carries its own I2C pull-ups, and the chip answers at the fixed address 0x68. The 32K and SQW pins are outputs this page leaves unwired.
Pins to leave alone
A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.
The working code for the Arduino Nano
Library: RTClib (RTClib.h). This is the sketch the circuit above runs.
#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc; // on I2C: SDA pin A4, SCL pin A5, address 0x68
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("No DS3231 found");
for (;;) {}
}
if (rtc.lostPower()) {
Serial.println("Clock lost power, setting it");
rtc.adjust(DateTime(2026, 11, 7, 9, 30, 0));
}
}
void loop() {
DateTime now = rtc.now();
char text[24];
snprintf(text, sizeof(text), "%04d-%02d-%02d %02d:%02d:%02d",
now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second());
Serial.print(text);
Serial.print(" Chip: ");
Serial.print(rtc.getTemperature(), 2);
Serial.println(" C");
delay(1000);
}
What you should see
Open the serial monitor at 9600 baud. If the clock lost power the sketch says so and sets it to a fixed time; after that it prints the date and time and the temperature of the chip once a second.
The 32K and SQW pins are outputs this guide leaves unwired.
The serial monitor prints this, recorded from the circuit above running for a few seconds:
Clock lost power, setting it
2026-11-07 09:30:00 Chip: 25.00 C
2026-11-07 09:30:01 Chip: 25.00 C
2026-11-07 09:30:02 Chip: 25.00 CCommon mistakes wiring a DS3231 RTC to an Arduino Nano
Setting the time on every boot
A sketch that calls rtc.adjust() unconditionally resets the clock each time the board restarts. Guard it with lostPower(), as above, so a real module with a battery keeps its time.
Another chip at 0x68
The MPU6050 also answers at 0x68. Two such parts on one bus clash; the DS3231 has no address pin to move it.
Using compile time on an old build
DateTime(F(__DATE__), F(__TIME__)) sets the time the sketch was compiled, not now. If you upload a day later, the clock is a day behind.
Build your own DS3231 RTC project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.