Projects / Blinking-colon clock

Blinking-colon clock

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO16:42DS3231

    Install the libraries

    RTClib and TM1637.

  2. NANO

    Wire the display

    VCC, GND, CLK to D5, DIO to D6.

  3. NANO12:45

    Wire the clock

    VCC, GND, SDA to A4, SCL to A5.

  4. NANO

    Wire the buttons

    D2 and D3 each to GND.

  5. NANO12:45

    Upload the sketch

    The time appears with a blinking colon.

  6. NANO

    Set the hours

    Press the hours button.

  7. NANO

    Set the minutes

    Press the minutes button.

  8. NANO

    Unplug and replug

    The time carries on.

In short

How do you build a blinking-colon clock?

A four-digit display with a colon shows the time from a battery-backed clock, and the colon blinks each second. You need Arduino Nano, 0.56 inch 4-digit clock display (TM1637, colon), DS3231 RTC module, Tactile push button 6 mm × 2 and Breadboard 830 Tie Points. It takes 8 steps and about 75 minutes.

Level
Beginner
Time
About 75 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Display VCCNano 5VPower
Display GNDNano GNDCommon ground
Display CLKNano D5Clock line
Display DIONano D6Data line
Clock module VCCNano 5VDS3231 board
Clock module GNDNano GNDCommon ground
Clock module SDANano A4I2C data
Clock module SCLNano A5I2C clock
Hours buttonNano D2 to GNDAdds an hour
Minutes buttonNano D3 to GNDAdds a minute

Code

A DS3231 clock module keeps accurate time with its own battery, so the clock keeps running when the Nano is unplugged and is correct to within a minute or two a year. The sketch asks the clock for the time ten times a second and shows hours and minutes on the four-digit display. A seven-segment display with a colon has one extra segment between the second and third digit, and the display library lets you turn that colon on or off, so the colon blinks once a second. When the clock has just been fitted or its battery was removed, the sketch sets it to the time the code was compiled, which will be a little behind real time, so use the two buttons to fix it: one adds an hour and the other adds a minute, each with a short wait to stop it racing ahead. Seconds are set to zero every time you adjust, so press the minute button at the right moment to match another clock. Lower the brightness with setBrightness for a bedroom, or raise it for a bright room.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

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

RTC_DS3231 rtc;
TM1637Display display(5, 6);          // CLK on D5, DIO on D6

const int HOUR_BTN = 2, MIN_BTN = 3;
unsigned long lastPress = 0;

void setup() {
  Serial.begin(9600);
  pinMode(HOUR_BTN, INPUT_PULLUP);
  pinMode(MIN_BTN, INPUT_PULLUP);
  display.setBrightness(3);           // 0 to 7
  if (!rtc.begin()) { Serial.println("Clock not found"); while (1) { } }
  if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));   // set from the compile time
}

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

  if (millis() - lastPress > 250) {
    bool h = digitalRead(HOUR_BTN) == LOW, m = digitalRead(MIN_BTN) == LOW;
    if (h || m) {
      int hh = now.hour(), mm = now.minute();
      if (h) hh = (hh + 1) % 24;
      if (m) mm = (mm + 1) % 60;
      rtc.adjust(DateTime(now.year(), now.month(), now.day(), hh, mm, 0));
      lastPress = millis();
      now = rtc.now();
    }
  }

  int hhmm = now.hour() * 100 + now.minute();
  uint8_t colon = (now.second() % 2 == 0) ? 0b01000000 : 0;   // colon on for even seconds
  display.showNumberDecEx(hhmm, colon, true);                 // true keeps leading zeros
  delay(100);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Clock not found

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Power onTime appears, colon blinks once a second
Press hoursAdds one hour
Press minutesAdds one minute
Power off and onTime still correct
Clock battery removedTime resets to the compile time

If it does not work

Display blank

Check CLK and DIO and the library pins.

Wrong time at first

Set it with the two buttons.

Colon missing

Your module may have a different colon bit, try 0b11100000.

Clock not found

Check SDA and SCL and the module power.

Time drifts quickly

The clock battery is flat, replace it.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the blinking-colon clock?

Arduino Nano, 0.56 inch 4-digit clock display (TM1637, colon), DS3231 RTC module, Tactile push button 6 mm × 2 and Breadboard 830 Tie Points.

How long does the blinking-colon clock take to build?

About 75 minutes for a beginner maker, in 8 steps.

How do I know the blinking-colon clock works?

Power on: Time appears, colon blinks once a second. Press hours: Adds one hour. Press minutes: Adds one minute.

Display blank: what should I check?

Check CLK and DIO and the library pins.

Wrong time at first: what should I check?

Set it with the two buttons.

Colon missing: what should I check?

Your module may have a different colon bit, try 0b11100000.

Clock not found: what should I check?

Check SDA and SCL and the module power.