The TK51 is a simple 4-digit LED display module based on the TM1637 chip. It's great for showing numbers, clocks, or custom patterns on your projects.
The TK51 comes in two variants: one for clock display with a colon (:) in the middle, and another for number display with a decimal point (.) after each digit.
We'll use the TM1637 library from [https://github.com/avishorp/TM1637](https://github.com/avishorp/TM1637) to make it easy.
We'll cover:
- Installing the library
- Connecting the hardware
- A simple example to display a number with dots (like 1.2.3.4)
- A simple example to display a clock with a colon (like 12:34)
## Step 1: What You'll Need
- An Arduino board (e.g., Uno, Nano, or ESP32)
- TK51 4-Digit Display Module
- Jumper wires
- Arduino IDE installed on your computer (free from arduino.cc)
## Step 2: Install the TM1637 Library
1. Download the library from [https://github.com/avishorp/TM1637](https://github.com/avishorp/TM1637) (click the green "Code" button and select "Download ZIP").
2. Open the Arduino IDE.
3. Go to **Sketch > Include Library > Add .ZIP Library...**
4. Select the downloaded ZIP file and click OK.
5. Restart the Arduino IDE if needed. The library should now be available.
## Step 3: Connect the Hardware
The TK51 module has 4 pins: VCC, GND, CLK, and DIO.
- Connect VCC to 5V on your Arduino.
- Connect GND to GND on your Arduino.
- Connect CLK to any digital pin, e.g., pin 2.
- Connect DIO to any digital pin, e.g., pin 3.
Make sure the connections are secure to avoid issues.
## Step 4: Basic Code Structure
In all examples, start with this basic setup in your Arduino sketch:
``` cpp
#include <TM1637Display.h> // Include the library
#define CLK 2 // CLK pin connected to Arduino pin 2
#define DIO 3 // DIO pin connected to Arduino pin 3
TM1637Display display(CLK, DIO); // Create the display object
void setup() {
display.setBrightness(0x0f); // Set brightness (0x00 to 0x0f, 0x0f is max)
}
void loop() {
// Your display code goes here
}
```
## Example 1: Display a Number with Dots After Each Digit
This shows something like "1234"。

In the loop() function, add:
``` cpp
void loop() {
display.showNumberDecEx(1234, 0, false); // Display 1234 with dots after each digit
delay(1000); // Wait 1 second
}
```
- showNumberDecEx(number, dots, leading_zeros):
- number: The number to show (1234 here).
- false: No leading zeros (don't pad with 0s).
Upload and run. It should show "1234" steadily.
Note: For dots after each, the binary 0b01010101 sets dots on positions 1,3,5,7 (but since it's 4 digits, adjust as needed). Experiment with the binary value:
- Bit 0 (rightmost): Colon (for clock).
- Bits 1-4: Decimal points for digits 3,2,1,0 (from left to right).
## Example 2: Display a Clock with Colon
This shows something like "12:34" (with the colon in the middle).
In the loop() function, add:
``` cpp
void loop() {
display.showNumberDecEx(1234, 0b10000000, true); // Display 1234 as 12:34 with colon
delay(1000); // Wait 1 second
}
```
- showNumberDecEx(number, dots, leading_zeros):
- number: 1234 becomes 12:34.
- dots: 0b10000000 turns on the colon (bit 7 for colon).
- true: Add leading zeros if needed (e.g., for 9:05 as 09:05).
Upload and run. It should show "12:34" with the colon blinking or steady (depending on module). To make a real clock, you'd use Arduino's time functions, but this is a simple static example.