Arduino TM1637 4-Digit Display: Wiring, Code and Simulator
To build this Arduino TM1637 4-Digit Display project you need an Arduino Uno and a TM1637 4-digit display. A TM1637 counter on two wires, with the start, stop and acknowledge bits written by hand. Make the 4 connections in the wiring table, upload the Arduino C++ code, and open the logic analyzer on CLK and DIO to see each byte and its ACK.
Open this circuit in the free Arduino Uno simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | TM1637 4-digit display | Four digits on two wires, CLK and DIO (LSB first, ACK after each byte). 0x40, then 0xC0 and four segment bytes, then 0x8F to switch on. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno pin 2 | TM1637 4-digit display CLK |
| 2 | Arduino Uno pin 3 | TM1637 4-digit display DIO |
| 3 | Arduino Uno 5V | TM1637 4-digit display VCC |
| 4 | Arduino Uno GND | TM1637 4-digit display GND |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add a TM1637 4-digit display from the parts palette.
- Wire 1. Connect Arduino Uno pin 2 to TM1637 4-digit display CLK.
- Wire 2. Connect Arduino Uno pin 3 to TM1637 4-digit display DIO.
- Wire 3. Connect Arduino Uno 5V to TM1637 4-digit display VCC.
- Wire 4. Connect Arduino Uno GND to TM1637 4-digit display GND.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Open the logic analyzer on CLK and DIO to see each byte and its ACK.
Arduino C++ code
// 4-digit display: a TM1637 on two wires (CLK 2, DIO 3), bit-banged by hand.
// Like I2C without an address, and least significant bit first.
const int CLK = 2, DIO = 3;
const byte DIGITS[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
void pinLow(int p) { pinMode(p, OUTPUT); digitalWrite(p, LOW); }
void pinHigh(int p) { pinMode(p, INPUT_PULLUP); } // released: the pull-up raises it
void start() { pinHigh(DIO); pinHigh(CLK); delayMicroseconds(5); pinLow(DIO); delayMicroseconds(5); }
void stop() { pinLow(CLK); pinLow(DIO); delayMicroseconds(5); pinHigh(CLK); delayMicroseconds(5); pinHigh(DIO); }
void writeByte(byte b) {
for (int i = 0; i < 8; i++) {
pinLow(CLK);
if (b & 1) pinHigh(DIO); else pinLow(DIO);
delayMicroseconds(5);
pinHigh(CLK);
delayMicroseconds(5);
b >>= 1;
}
pinLow(CLK); // ninth clock: the chip pulls DIO low to acknowledge
pinHigh(DIO);
delayMicroseconds(5);
pinHigh(CLK);
delayMicroseconds(5);
pinLow(CLK);
}
void show(int n) {
start(); writeByte(0x40); stop(); // write data, auto-increment
start(); writeByte(0xC0); // from digit 0
writeByte(DIGITS[(n / 1000) % 10]);
writeByte(DIGITS[(n / 100) % 10]);
writeByte(DIGITS[(n / 10) % 10]);
writeByte(DIGITS[n % 10]);
stop();
start(); writeByte(0x8F); stop(); // display on, full brightness
}
void setup() {}
void loop() {
static int n = 0;
show(n);
n = (n + 1) % 10000;
delay(200);
}
What to try
Open the logic analyzer on CLK and DIO to see each byte and its ACK.
Frequently asked questions
How do I wire the TM1637 4-Digit Display project on an Arduino Uno?
Make 4 connections: Arduino Uno pin 2 to TM1637 4-digit display CLK; Arduino Uno pin 3 to TM1637 4-digit display DIO; Arduino Uno 5V to TM1637 4-digit display VCC; Arduino Uno GND to TM1637 4-digit display GND.
What parts do I need for this Arduino project?
An Arduino Uno and a TM1637 4-digit display.
Can I simulate this Arduino project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.
What does the code do?
A TM1637 counter on two wires, with the start, stop and acknowledge bits written by hand.
More Arduino Uno projects
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator