7-segment display TM1637 on Arduino

FunduinoLast updated on

Ziffern anzeigen, blinken lassen und einen Timer bauen

Eine vierstellige 7-Segment-Anzeige mit TM1637-Chip braucht nur zwei Datenleitungen – und liefert dafür eine gut ablesbare Zahlenanzeige für Uhren, Zähler oder Messwerte.

In drei Teilen zeigst du zuerst eine einzelne Ziffer an, dann eine vierstellige Zahl im Blinktakt und zum Schluss einen laufenden Timer.

Four-digit 7-segment display with TM1637 on Arduino, one digit lights up
A single digit on the 7-segment display

The module and its colors

In this guide, you’ll use the Arduino to control a four-digit seven-segment display that uses a TM1637 chip. The module is available in several colors.

There is a label on the side of the module that indicates its color:

  • Blue: 5643BB
  • Green: 5643GB
  • Red: 5643BH
  • White: 5643BW
  • Yellow: 5643BY
Four-digit 7-segment display with TM1637 on Arduino, one digit lights up
A single digit on the 7-segment display

Install library

Enter the search term in the Arduino software's Library Manager TM1637 . Several libraries will appear - we'll use “TM1637” by Avishay Orpaz here. Once it's installed, you can start programming.

Part 1: Display a single digit

Wire the display as follows:

  • 5V on the display to 5V on the Arduino
  • GND to GND
  • CLK to pin 4
  • DIO to pin 5

A few explanations of the commands in the sketch:

  • TM1637Display display(CLK, DIO); initializes the display with the pins specified earlier.
  • display.setBrightness(7); sets the brightness to maximum (values from 0 to 7 are possible).
  • display.clear(); clears the display before anything is shown - the LEDs turn off.
  • display.showNumberDec(5, false, 1, 0); displays the digit 5 in the first position. The four values mean: the number to display, no leading zeros, use only one digit, position 0 (that is, the first position).
Part 1: Display a single digit
#include <TM1637Display.h>
// Define the pins for CLK and DIO
#define CLK 4
#define DIO 5

// Create a display object
TM1637Display display(CLK, DIO);

void setup()
{
  // Set the display brightness (0 to 7)
  display.setBrightness(7);

  // Clear the display
  display.clear();

  // Display a digit (5 in this case)
  display.showNumberDec(5, false, 1, 0);
}

void loop()
{
  // Nothing else to do in loop: The display was already set in setup.
}

Part 2: Display four digits and make them blink

You only need to make a few changes to the sketch from Part 1. With display.showNumberDec(5678); you display the whole number, and a delay keeps it on screen for one second.

The sketch then clears the display and waits 500 milliseconds - this makes the number blink.

Four-digit 7-segment display with TM1637 on Arduino, all segments lit
All four places show the number 5678.
Part 2: Display four digits and make them blink
#include <TM1637Display.h>
#define CLK 4
#define DIO 5

TM1637Display display(CLK, DIO);

void setup()
{
  display.setBrightness(7);
  display.clear();
}

void loop()
{
  // Display the number 5678 for one second
  display.showNumberDec(5678);
  delay(1000);

  // Clear the display for 500 milliseconds - this makes it blink
  display.clear();
  delay(500);
}

Part 3: Programming a timer

With one more small change, it becomes a timer. Above setup, create the variable x with an initial value of 0.

In loop, this value is displayed and then increased by one using the simple calculation x = x + 1. Each cycle takes one second in total—800 milliseconds with the display on, 200 without it.

Part 3: Programming a timer
#include <TM1637Display.h>
// Timer starting value
int x = 0;

#define CLK 4
#define DIO 5

TM1637Display display(CLK, DIO);

void setup()
{
  display.setBrightness(7);
  display.clear();
}

void loop()
{
  // Display the current count
  display.showNumberDec(x);
  delay(800);

  // Increment the count by 1
  x = x + 1;

  // Clear briefly so the change is visible
  display.clear();
  delay(200);
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.