Arduino - TM1637 4-Digit 7-Segment Display

This tutorial instructs you how to use a TM1637 4-digit 7-segment display module with Arduino. In detail, we will learn:

Arduino TM1637 4-Digit 7-Segment Display

About the TM1637 4-Digit 7-Segment Display Module

The TM1637 is a driver IC for 7-segment LED displays. The module uses only two data pins (CLK and DIO) to communicate with the microcontroller, making wiring simple. It has built-in display memory, so once you write data to it, the display stays on without any refresh loop. The module also includes a colon separator between digit 1 and digit 2, which is useful for clock displays.

Key features of the module:

  • 4 digits, each with 7 segments plus a decimal point
  • Colon separator between the second and third digit
  • 8 brightness levels (0-7)
  • 2-wire interface (CLK + DIO)
  • Built-in display memory - no refresh needed
  • Operating voltage: 3.3V to 5V

Pin Mapping

Function Pin
CLK Clock signal input
DIO Data input/output
VCC Power supply (3.3V or 5V)
GND Ground

The CLK and DIO pins can be connected to any digital pins on the Arduino.

Wiring Diagram

Connect the TM1637 module to the Arduino as follows:

  • CLK to Arduino pin 9
  • DIO to Arduino pin 10
  • VCC to 5V
  • GND to GND
Arduino TM1637 4-Digit 7-Segment Display wiring diagram

This image is created using Fritzing. Click to enlarge image

Library Installation

  • Connect the Arduino board to your computer with a USB cable.
  • Open Arduino IDE, select the right board and port.
  • Navigate to the Libraries icon on the left bar of the Arduino IDE.
  • Search "DIYables_4Digit7Segment_TM1637", then find the DIYables_4Digit7Segment_TM1637 library by DIYables.
  • Click Install button to install the latest version of the library.
Arduino TM1637 4-Digit 7-Segment Display library

Note: This library is self-contained with no external dependencies.

Basic Structure

Every sketch using the DIYables_4Digit7Segment_TM1637 library follows this basic structure:

#include <DIYables_4Digit7Segment_TM1637.h> #define CLK_PIN 9 #define DIO_PIN 10 DIYables_4Digit7Segment_TM1637 display(CLK_PIN, DIO_PIN); void setup() { display.begin(); // Display something display.print(1234); } void loop() { // Your code here }

You create the display object with the CLK and DIO pin numbers, then call begin() in setup(). After that, use methods like print(), printTemperature(), or printTime() to show data on the display.

Arduino Code - Display Integer Numbers

This example shows how to display various integer values, including negative numbers and zero-padded output.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-tm1637-4-digit-7-segment-display */ /* * DIYables_4Digit7Segment_TM1637 - Integer Example * * Displays various integer values on a 4-digit 7-segment display * with TM1637 driver, including zero-padded numbers. * * Tutorial: https://diyables.io/products/4-digit-7-segment-display-led-tm1637-with-colon * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4B Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables Nano R3: https://diyables.io/nano-board * - DIYables ESP32 Board: https://diyables.io/esp32-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_4Digit7Segment_TM1637.h> // Pin configuration - change to match your wiring #define CLK_PIN 9 // The Arduino pin connected to the CLK pin of TM1637 4-digit 7-segment display #define DIO_PIN 10 // The Arduino pin connected to the DIO pin of TM1637 4-digit 7-segment display DIYables_4Digit7Segment_TM1637 display(CLK_PIN, DIO_PIN); void setup() { Serial.begin(9600); display.begin(); Serial.println("TM1637 Integer Example"); } void loop() { // Display various integers int numbers[] = {0, 42, 1234, -5, -123, 9999}; int count = sizeof(numbers) / sizeof(numbers[0]); for (int i = 0; i < count; i++) { display.print(numbers[i]); Serial.print("Displaying: "); Serial.println(numbers[i]); delay(2000); } // Display with zero padding display.print(42, true); // Shows "0042" Serial.println("Displaying: 0042 (zero-padded)"); delay(2000); }

Quick Steps

  • Wire the TM1637 module to your Arduino as shown in the wiring diagram above.
  • Connect the Arduino board to your computer with a USB cable.
  • Open Arduino IDE, select the right board and port.
  • Copy the above code and paste it to the editor of Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.
  • Open the Serial Monitor to see the output.

The display will cycle through the numbers 0, 42, 1234, -5, -123, 9999, and then show 42 with zero-padding as "0042".

API Summary

Method Description Example
print(int) Display an integer (-999 to 9999) display.print(1234)
print(int, true) Display with leading zeros display.print(42, true)
clear() Clear the display display.clear()

Arduino Code - Display Text and Temperature

This example shows how to display text strings and temperature with the degree symbol.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-tm1637-4-digit-7-segment-display */ /* * DIYables_4Digit7Segment_TM1637 - TextAndDegree Example * * Displays text strings, special characters, and temperature * on a 4-digit 7-segment display with TM1637 driver. * * Tutorial: https://diyables.io/products/4-digit-7-segment-display-led-tm1637-with-colon * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4B Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables Nano R3: https://diyables.io/nano-board * - DIYables ESP32 Board: https://diyables.io/esp32-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_4Digit7Segment_TM1637.h> // Pin configuration - change to match your wiring #define CLK_PIN 9 // The Arduino pin connected to the CLK pin of TM1637 4-digit 7-segment display #define DIO_PIN 10 // The Arduino pin connected to the DIO pin of TM1637 4-digit 7-segment display DIYables_4Digit7Segment_TM1637 display(CLK_PIN, DIO_PIN); void setup() { Serial.begin(9600); display.begin(); Serial.println("TM1637 Text and Degree Example"); } void loop() { // Display text strings const char* texts[] = {"HELP", "Hi", "COOL", "done"}; for (int i = 0; i < 4; i++) { display.print(texts[i]); Serial.print("Displaying: "); Serial.println(texts[i]); delay(2000); } // Display temperature with degree symbol display.printTemperature(25, 'C'); // Shows "25°C" Serial.println("Displaying: 25 degrees C"); delay(2000); display.printTemperature(72, 'F'); // Shows "72°F" Serial.println("Displaying: 72 degrees F"); delay(2000); // Display string with degree constant char buf[5]; buf[0] = '2'; buf[1] = '5'; buf[2] = DIYables_4Digit7Segment_TM1637::DEGREE; buf[3] = 'C'; buf[4] = '\0'; display.print(buf); // Same as printTemperature(25, 'C') Serial.println("Displaying: 25 degrees C (via print)"); delay(2000); }

Quick Steps

  • Wire the TM1637 module to your Arduino as shown in the wiring diagram above.
  • Copy the above code and paste it to the editor of Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.
  • Open the Serial Monitor.

The display will cycle through text strings "HELP", "Hi", "COOL", "done", then show temperatures "25°C" and "72°F".

API Summary

Method Description Example
print(const char*) Display a text string (up to 4 chars) display.print("HELP")
printTemperature(int, char) Display temperature with degree and unit display.printTemperature(25, 'C')
DEGREE Degree symbol constant for use in strings display.DEGREE

Arduino Code - Display Time with Blinking Colon

This example displays a clock-like time with a colon that blinks every 500 milliseconds.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-tm1637-4-digit-7-segment-display */ /* * DIYables_4Digit7Segment_TM1637 - Time Example * * Displays time in HH:MM format with blinking colon separator * on a 4-digit 7-segment display with TM1637 driver. * * Tutorial: https://diyables.io/products/4-digit-7-segment-display-led-tm1637-with-colon * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4B Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables Nano R3: https://diyables.io/nano-board * - DIYables ESP32 Board: https://diyables.io/esp32-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_4Digit7Segment_TM1637.h> // Pin configuration - change to match your wiring #define CLK_PIN 9 // The Arduino pin connected to the CLK pin of TM1637 4-digit 7-segment display #define DIO_PIN 10 // The Arduino pin connected to the DIO pin of TM1637 4-digit 7-segment display DIYables_4Digit7Segment_TM1637 display(CLK_PIN, DIO_PIN); int hours = 12; int minutes = 30; bool colonOn = true; void setup() { Serial.begin(9600); display.begin(); Serial.println("TM1637 Time Example"); Serial.println("Displaying 12:30 with blinking colon"); } void loop() { display.printTime(hours, minutes, colonOn); delay(500); // Toggle colon every 500ms for blinking effect colonOn = !colonOn; }

Quick Steps

  • Wire the TM1637 module to your Arduino as shown in the wiring diagram above.
  • Copy the above code and paste it to the editor of Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.

The display will show "12:30" with the colon blinking on and off every half second.

API Summary

Method Description Example
printTime(int, int) Display time HHMM with colon display.printTime(12, 30)
printTime(int, int, bool) Display time, control colon on/off display.printTime(12, 30, false)

Arduino Code - Individual Digit Control

This example shows how to set each digit separately using numbers, characters, and the colon.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-tm1637-4-digit-7-segment-display */ /* * DIYables_4Digit7Segment_TM1637 - IndividualDigits Example * * Sets individual digits, characters, and colon on a 4-digit * 7-segment display with TM1637 driver. * * Tutorial: https://diyables.io/products/4-digit-7-segment-display-led-tm1637-with-colon * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4B Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables Nano R3: https://diyables.io/nano-board * - DIYables ESP32 Board: https://diyables.io/esp32-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_4Digit7Segment_TM1637.h> // Pin configuration - change to match your wiring #define CLK_PIN 9 // The Arduino pin connected to the CLK pin of TM1637 4-digit 7-segment display #define DIO_PIN 10 // The Arduino pin connected to the DIO pin of TM1637 4-digit 7-segment display DIYables_4Digit7Segment_TM1637 display(CLK_PIN, DIO_PIN); void setup() { Serial.begin(9600); display.begin(); Serial.println("TM1637 Individual Digits Example"); } void loop() { // Set individual numbers on each digit position display.clear(); display.setNumber(0, 1); display.setNumber(1, 2); display.setNumber(2, 3); display.setNumber(3, 4); Serial.println("Displaying: 1234"); delay(2000); // Turn colon on display.setColon(true); Serial.println("Displaying: 12:34"); delay(2000); // Turn colon off display.setColon(false); Serial.println("Displaying: 1234"); delay(2000); // Set individual characters display.clear(); display.setChar(0, 'H'); display.setChar(1, 'E'); display.setChar(2, 'L'); display.setChar(3, 'P'); Serial.println("Displaying: HELP"); delay(2000); // Mix characters and numbers with colon display.clear(); display.setChar(0, 'A'); display.setNumber(1, 3); display.setChar(2, 'b'); display.setNumber(3, 7); display.setColon(true); Serial.println("Displaying: A3:b7"); delay(2000); // Blinking colon effect display.clear(); display.setNumber(0, 1); display.setNumber(1, 2); display.setNumber(2, 3); display.setNumber(3, 0); Serial.println("Blinking colon: 12:30"); for (int i = 0; i < 5; i++) { display.setColon(true); delay(500); display.setColon(false); delay(500); } delay(1000); }

Quick Steps

  • Wire the TM1637 module to your Arduino as shown in the wiring diagram above.
  • Copy the above code and paste it to the editor of Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.
  • Open the Serial Monitor.

The display will show various combinations of numbers and characters with colon control.

API Summary

Method Description Example
setNumber(int, int) Set a digit (0-9) at position 0-3 display.setNumber(0, 1)
setChar(int, char) Set a character at position 0-3 display.setChar(0, 'H')
setColon(bool) Turn colon on or off display.setColon(true)
setSegments(int, uint8_t) Set raw segments at position 0-3 display.setSegments(0, 0x76)

Troubleshoot

If the code is not working, there are some common issues you can troubleshoot:

  • Display shows nothing: Check the wiring connections. Make sure CLK and DIO are connected to the correct Arduino pins. Verify the VCC is connected to 5V or 3.3V and GND to GND.
  • Display shows wrong digits: Double-check that the CLK_PIN and DIO_PIN values in your code match the actual wiring. Swapping CLK and DIO is a common mistake.
  • Display is too dim or too bright: Use setBrightness(level) with a value from 0 (dimmest) to 7 (brightest) to adjust.
  • Compile error about missing library: Make sure you installed the DIYables_4Digit7Segment_TM1637 library through the Arduino Library Manager.

Platform Support

The library uses only Arduino standard APIs (pinMode, digitalWrite, digitalRead, delayMicroseconds) and supports all Arduino platforms (architectures=*).

The Best Arduino Starter Kit

※ OUR MESSAGES