Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.
RTC Digital Clock: the finished build
UnoStudent projects

Digital clock that keeps time through power cuts (Arduino Uno + DS3231)

A clock that keeps exact time even through power cuts.

Difficulty
Easy
Build time
45 min
Parts cost
₹690 · $8
Verified — core avr 1.8.8, RTClib 2.1.4, 3 Nov 2026Compile-only

Community draft — report a mistake

Parts list

PartQtyApprox.Buy
Arduino Uno R3 (compatible)1₹450Buy Arduino Uno R3 (compatible)
DS3231 RTC module + CR2032 cell1₹150Buy DS3231 RTC module + CR2032 cell
TM1637 4-digit display module1₹60Buy TM1637 4-digit display module
Jumper wires1₹30Buy Jumper wires
Total₹690

Affiliate disclosure: “Buy” links may earn FlashReady a small commission at no extra cost to you. Prices are indicative.

Wiring

Arduino Uno R3Only the pins used are shown · 5 V logicDS3231 real-time clock (RTC) moduleTM1637 4-digit 7-segment display5VGNDD2D3SDA · 18SCL · 1932K (not connected)SQW (not connected)SCLSDAVCCGNDCLKDIOVCCGND
Every connection
Arduino Uno R3Part · pinWireNotes
5VDS3231 real-time clock (RTC) module · VCCred
GNDDS3231 real-time clock (RTC) module · GNDblack
SDADS3231 real-time clock (RTC) module · SDAblue
SCLDS3231 real-time clock (RTC) module · SCLyellow
D2TM1637 4-digit 7-segment display · CLKorange
D3TM1637 4-digit 7-segment display · DIOgreen
5VTM1637 4-digit 7-segment display · VCCred
GNDTM1637 4-digit 7-segment display · GNDblack

Board quirks: On first power-up the clock is set to the time the sketch was compiled — upload right after compiling for the best start. Many DS3231 modules have a charging circuit meant for a rechargeable LIR2032. With a normal CR2032, remove the charging diode or resistor as the module’s documentation describes.

Code

rtc-digital-clock.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// RTC digital clock — Arduino Uno + DS3231 real-time clock + TM1637 4-digit display.
// Keeps time through power cuts on the DS3231's coin cell; the colon blinks every second.
// DS3231 on I2C (SDA/SCL, 0x68). TM1637 CLK → D2, DIO → D3.
#include <Wire.h>
#include <RTClib.h>
#include <TM1637Display.h>

RTC_DS3231 rtc;
TM1637Display display(2, 3);

void setup() {
  Serial.begin(9600);
  display.setBrightness(4);
  if (!rtc.begin()) {
    Serial.println(F("DS3231 not found"));
    for (;;) delay(1000);
  }
  if (rtc.lostPower()) {
    // First power-up (or a flat coin cell): set the clock to the time this sketch was compiled.
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    Serial.println(F("Clock set from compile time"));
  }
}

void loop() {
  DateTime now = rtc.now();
  bool colon = now.second() % 2 == 0;
  display.showNumberDecEx(now.hour() * 100 + now.minute(), colon ? 0b01000000 : 0, true);
  static uint8_t lastSecond = 99;
  if (now.second() != lastSecond) {
    lastSecond = now.second();
    Serial.print(now.timestamp(DateTime::TIMESTAMP_TIME));
    Serial.print(F("  chip temp "));
    Serial.println(rtc.getTemperature(), 2);
  }
  delay(100);
}

Compiled for uno on avr 1.8.8 with RTClib 2.1.4 · 3 Nov 2026

How it works

The DS3231 is a real-time clock with a temperature-compensated crystal inside the chip — accurate to about a minute a year. A coin cell on the module keeps it running when the main power is off, which is what makes it survive power cuts.

On start-up the sketch asks whether the clock lost power. If it did (first use, or a dead coin cell), it sets the time from the moment the sketch was compiled using the __DATE__ and __TIME__ macros. After that, the DS3231 keeps time on its own.

Every 100 ms the Uno reads the time and shows hours and minutes on the TM1637 display, with the colon on during even seconds — the familiar blink. The chip’s built-in temperature sensor is printed to the Serial Monitor, too.

The RTClib library handles the I2C registers and BCD encoding, and the TM1637 library drives the display over two wires.

Troubleshooting

The time resets after a power cut

The coin cell is flat or missing. Fit a fresh CR2032 and re-upload to set the time once.

It shows the wrong hour

The clock is set from your computer’s time at compile time. Re-upload, or add a serial command to set it.

“DS3231 not found”

Check SDA/SCL and run the I2C scanner; the DS3231 answers at 0x68 (and the module’s EEPROM at 0x57).

Upgrades

  • Add an alarm with a buzzer using the DS3231’s alarm registers.
  • Show temperature (the DS3231 has a sensor inside) every few seconds.
  • Dim the display at night.

↑↓ to move · Enter to open