How to wire a TM1637 display to an Arduino Mega
To wire a TM1637 display to an Arduino Mega, connect VCC to 5V, GND to GND, CLK to pin 2 and DIO to pin 3. The module runs from 5 V and its CLK and DIO lines idle at 5 V through the module’s pull-ups, the Arduino Mega’s own level. The sketch below uses the TM1637Display (TM1637Display.h) library. It counts up on the four digits of the display.
- 5 V logic
- Library: TM1637Display.h
- 4 wires
TM1637 display to Arduino Mega wiring table
Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.
| TM1637 display pin | Arduino Mega pin | Wire color | Why |
|---|---|---|---|
| VCC | 5V | red | The TM1637 runs from 3.3 to 5 V; brighter at 5 V. |
| GND | GND | blue | Common ground. |
| CLK | pin 2 | cyan | Clock. Any digital pin: it is not I2C, despite looking like it. |
| DIO | pin 3 | violet | Data, both directions. |
Power and logic levels for TM1637 display and Arduino Mega
Logic level
The Arduino Mega’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.
Supply
The TM1637 display takes 5 V from 5V. That is the Arduino Mega’s 5 V rail, so the part shares the current the board can supply.
This pair
The module runs from 5V and its CLK and DIO lines idle at 5 V through the module’s pull-ups, the Arduino Mega’s own level.
Pins to leave alone
Pins 14 to 19 are the three extra serial ports and 20 and 21 are I2C, so keep them free if you will need those. An Uno shield’s I2C on A4 and A5 is not connected to anything on a Mega.
The working code for the Arduino Mega
Library: TM1637Display (TM1637Display.h). This is the sketch the circuit above runs.
#include <TM1637Display.h>
const int CLK_PIN = 2; // pin 2
const int DIO_PIN = 3; // pin 3
TM1637Display display(CLK_PIN, DIO_PIN);
void setup() {
Serial.begin(9600);
display.setBrightness(4); // 0 to 7
Serial.println("Counting");
}
void loop() {
// Minutes and seconds since reset, with the colon on.
unsigned long s = millis() / 1000;
int mmss = (s / 60) % 100 * 100 + s % 60;
display.showNumberDecEx(mmss, 0b01000000, true);
delay(200);
}
What you should see
The four digits count up. The serial monitor, at 9600 baud, prints Counting once. The module takes two data pins, CLK and DIO, and these are not I2C even though there are two of them.
A dark display with the supply connected usually means CLK and DIO are swapped or on pins other than the ones the sketch names.
The serial monitor prints this, recorded from the circuit above running:
CountingCommon mistakes wiring a TM1637 display to an Arduino Mega
Wiring CLK and DIO to the I2C pins
The protocol looks like I2C but is not; it has no address and the Wire library cannot talk to it. Any two digital pins work, and leaving pin 20 and pin 21 free keeps them for a real I2C part.
Expecting decimal points
Most TM1637 clock modules wire only the colon, not the dots under each digit. The dots argument lights them on modules that have them, and the colon on these.
Taking the serial or I2C pins
Pins 0 and 1 are the USB serial port, 14 to 19 are Serial1 to Serial3 and 20 and 21 are I2C. CLK or DIO works on any of them until the sketch needs that port, so start on pin 2 and up.
Build your own TM1637 display project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.