Build it step by step
0 of 8 doneInstall the libraries
RTClib and TM1637.
Wire the display
VCC, GND, CLK to D5, DIO to D6.
Wire the clock
VCC, GND, SDA to A4, SCL to A5.
Wire the buttons
D2 and D3 each to GND.
Upload the sketch
The time appears with a blinking colon.
Set the hours
Press the hours button.
Set the minutes
Press the minutes button.
Unplug and replug
The time carries on.
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
| From | To | Why |
|---|---|---|
| Display VCC | Nano 5V | Power |
| Display GND | Nano GND | Common ground |
| Display CLK | Nano D5 | Clock line |
| Display DIO | Nano D6 | Data line |
| Clock module VCC | Nano 5V | DS3231 board |
| Clock module GND | Nano GND | Common ground |
| Clock module SDA | Nano A4 | I2C data |
| Clock module SCL | Nano A5 | I2C clock |
| Hours button | Nano D2 to GND | Adds an hour |
| Minutes button | Nano D3 to GND | Adds 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.
| Check | Expected |
|---|---|
| Power on | Time appears, colon blinks once a second |
| Press hours | Adds one hour |
| Press minutes | Adds one minute |
| Power off and on | Time still correct |
| Clock battery removed | Time 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 →
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.
