Arduino TM1637 clock
Build a 7-segment digital clock with Arduino, TM1637 and DS3231
A four-digit red 7-segment display, an RTC module that won't drift more than a minute a year, and an Arduino Nano that's cheaper than a sandwich. This is the canonical "first clock" build — fewer than ten wires, two libraries, and ~30 lines of sketch. The result is a clock that survives power cuts, keeps accurate time without the internet, and looks satisfyingly retro on a desk.
What you'll need
| Item | AliExpress | Amazon |
|---|---|---|
| Arduino Nano (CH340 clone is fine) | AliExpress Link | Amazon Link |
| TM1637 4-digit 7-segment display module (with center colon) | AliExpress Link | Amazon Link |
| DS3231 RTC module with CR2032 holder (ZS-042 form factor) | AliExpress Link | Amazon Link |
| CR2032 coin cell (for the RTC backup) | AliExpress Link | Amazon Link |
| 400-point breadboard | AliExpress Link | Amazon Link |
| Female-to-male Dupont jumper wires | AliExpress Link | Amazon Link |
| Mini-B USB cable (for the Nano) | AliExpress Link | Amazon Link |
Notes on the parts
- TM1637 vs MAX7219. Both will work. TM1637 modules come pre-wired with two data pins, a colon, and adjustable brightness — great for clocks. MAX7219 modules give you 8 digits and SPI but no colon. For HH:MM display, TM1637 is the easier path.
- DS3231 vs DS1307. Skip the DS1307. It drifts ~minutes per week, the DS3231 has a temperature-compensated crystal and drifts ~minutes per year. Same I²C pins, same library, ~$1 difference. Buy the right one once.
- Battery shipping. Most ZS-042 boards ship without a coin cell because lithium batteries are a pain to ship internationally. Order a CR2032 separately if your kit doesn't include one — without it, the RTC forgets the time every power cycle (which defeats the entire point).
- LIR2032 trap. A few cheap DS3231 boards include a charging circuit designed for the rechargeable LIR2032 (3.6 V) cell. If you put a non-rechargeable CR2032 (3.0 V) in one of those, you're slowly cooking it. Most modern ZS-042 clones have the charging diode removed or a 200 Ω resistor that limits current to a safe trickle, but it's worth a glance — if you see a SOT-23 transistor and a diode marked between VCC and the battery, search the board's silkscreen for "DS3231" + the resistor value before committing.
Wire it up
Eight wires total. The DS3231 talks I²C, so it goes on A4/A5. The TM1637 is bit-banged on any two digital pins.
| TM1637 | Arduino Nano |
|---|---|
| VCC | 5V |
| GND | GND |
| CLK | D2 |
| DIO | D3 |
| DS3231 | Arduino Nano |
|---|---|
| VCC | 5V |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
You can move the TM1637 to any other pair of digital pins — just update the #define in the sketch. The I²C pins on a Uno/Nano are fixed at A4/A5; on an ESP32 or a Mega they're different, so check your board's pinout if you're not on a 328-based Arduino.
Install the libraries
In the Arduino IDE: Tools → Manage Libraries…, then install:
- TM1637Display by Avishay Orpaz
- RTClib by Adafruit
RTClib also pulls in Wire.h (the I²C library, which ships with the IDE) automatically. The TM1637 library is pure bit-bang, no dependencies.
Set the RTC clock once
You only need to do this once per battery. Open this sketch, upload it, and the RTC will sync to your computer's clock at compile time:
#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc;
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
// Sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {}
Upload it, watch the Serial Monitor confirm it found the RTC, then immediately upload the main sketch below. If you leave the rtc.adjust() line and re-upload it later, the clock will jump back to whenever you last compiled — that's a fun ten minutes of debugging the first time it bites you.
The clock sketch
#include <Wire.h>
#include <RTClib.h>
#include <TM1637Display.h>
#define CLK 2
#define DIO 3
RTC_DS3231 rtc;
TM1637Display display(CLK, DIO);
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("RTC not found");
while (1);
}
display.setBrightness(5); // 0 = dim, 7 = max
}
void loop() {
DateTime now = rtc.now();
int hhmm = now.hour() * 100 + now.minute();
// Blink the colon every second
uint8_t dots = (now.second() % 2) ? 0b01000000 : 0b00000000;
display.showNumberDecEx(hhmm, dots, true);
delay(500);
}
That's the whole thing. showNumberDecEx is the TM1637 library's "with-decimal-points" variant; the bit 0b01000000 toggles the centre colon between digits 2 and 3. The true argument forces leading zeros so 09:05 displays as 09:05, not 905.
Common mistakes
- Display is dark or flickers. Your TM1637 is probably under-powered through a long jumper run from VIN. Move it to the Nano's 5V pin, not VIN.
- Time resets every reboot. The CR2032 isn't seated, is dead, or you skipped fitting one. The DS3231 keeps time only while the cell is present.
- Time is one hour off twice a year. The DS3231 has no concept of DST. If you live somewhere that switches, either accept it, add a button to nudge ±1 hour, or look up
TimeLib.h+Timezone.hfor automatic handling. - Display shows
88:88or random garbage. CLK and DIO are swapped. They look identical on the silkscreen but aren't interchangeable. - Setup sketch doesn't compile — "DateTime undefined". You installed Adafruit RTClib but the IDE picked up an older fork. Uninstall any other RTClib and reinstall just Adafruit's.
Where to take it
Once you have the basics working, the obvious upgrades are: a button to set the time without re-uploading; the DS3231's onboard temperature sensor displayed on alternating seconds (rtc.getTemperature() returns °C); a 24-hour vs 12-hour toggle; or an alarm output to a buzzer driven from the DS3231's INT/SQW pin. The display's brightness is also worth tying to an LDR if you sleep in the same room as the clock — at level 7 it lights up like a smoke detector at 3am.
If you want to dress it up physically, a printed enclosure with a smoked-acrylic front panel hides the display when off and looks far more polished than a bare module. The TM1637 board is 42 × 24 mm — design around that.
For a colour-LED variant of the same idea, see the WS2812B LED clock guide; for a weather-aware build that adds outdoor temperature, the BME280 weather station guide pairs nicely with the same RTC.