DS3231 RTC Clock with Arduino
Build a real-time clock that survives a power cut and stays accurate to ±2 ppm — about a minute a year.
Difficulty: Through-hole. Estimated build time: about 50 minutes. Estimated parts cost: about US$11.00. 4-line bill of materials. Compare supplier offers when available. Most microcontrollers can keep time, but the moment you lose power the clock resets.
Wire I²C between Arduino and DS3231
The DS3231 uses standard I²C — two wires, SDA and SCL. On an Arduino Uno, SDA is pin A4 and SCL is pin A5. Connect the module's VCC pin to the Arduino's 3.3 V output (the chip is 3.3 V tolerant; some modules accept 5 V too, but 3.3 V is safest). Connect GND to GND, SDA to A4, SCL to A5. The chip's I²C address is fixed at 0x68.
Insert the CR2032 backup cell
The DS3231 module has a CR2032 cell holder on the underside. Drop a fresh CR2032 in with the positive (+) side up — the chip uses this cell only to keep its oscillator running when main VCC is gone. Drawing roughly 3 µA from the cell, a fresh CR2032 will run the clock for 8–10 years. Without the backup cell the time resets every time you unplug the Arduino.
Install the RTClib library
In the Arduino IDE, open Tools → Manage Libraries and search 'RTClib' (Adafruit). Install the latest version. This library handles the binary-coded-decimal date/time format the DS3231 uses internally and exposes a clean DateTime API.
Set the time, then never set it again
Upload the RTClib 'ds3231' example sketch. The first time you run it, uncomment the rtc.adjust(DateTime(F(__DATE__), F(__TIME__))) line — that sets the chip's clock to the moment you compiled the sketch. Upload again with that line commented out, and from then on the DS3231 keeps time on its own. Open the Serial Monitor at 9600 baud — current time prints once a second.
Read the chip's built-in temperature sensor
The DS3231 also exposes its internal temperature sensor over I²C — it uses temperature to compensate the crystal, and gives you the reading for free. Add Serial.print(rtc.getTemperature()) to your loop and you get the ambient temperature in 0.25 °C steps. Useful for a weather station or thermal-aware data log without adding a second chip.