Arduino - TM1637 4-Digit 7-Segment Display | Arduino Tutorial (2024)

Ads by ArduinoGetStarted.com

Arduino - TM1637 4-Digit 7-Segment Display | Arduino Tutorial (1)

A standard 4-digit 7-segment display is needed for clock, timer and counter projects, but it usually requires 12 connections. The TM1637 module makes it easier by only requiring 4 connections: 2 for power and 2 for controlling the segments.

This tutorial will not overload you by deep driving into hardware. Instead, We will learn how to connect the 4-digit 7-segment display to Arduino, how to program it do display what we want.

Arduino - TM1637 4-Digit 7-Segment Display | Arduino Tutorial (2)

This tutorial are going to use the colon-separated 4-digit 7-segment display module. If you want to display the float numbers, please use the 74HC595 4-digit 7-segment Display Module

Hardware Required

1×Arduino UNO or Genuino UNO
1×USB 2.0 cable type A/B
1×TM1637 4-digit 7-segment Display (colon-separated)
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)

Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

About TM1637 4-digit 7-segment Display

A TM1637 module typically consists of four 7-segment LEDs and a colon-shaped LED in the middle: It is ideal for displaying time in hours and minutes, or minutes and seconds, or scores of two teams.

Pinout

TM1637 4-digit 7-segment display module includes 4 pins:

  • CLK pin: is a clock input pin. Connect to any digital pin on Arduino.

  • DIO pin: is a Data I/O pin. Connect to any digital pin on Arduino.

  • VCC pin: pin supplies power to the module. Connect it to the 3.3V to 5V power supply.

  • GND pin: is a ground pin.

Arduino - TM1637 4-Digit 7-Segment Display | Arduino Tutorial (3)

Wiring Diagram

To connect a TM1637 to an Arduino, connect four wires: two for power and two for controlling the display. The module can be powered from the 5-volt output of the Arduino. Connect the CLK and DIO pins to any digital pins of Arduino. For example, 2 and 3 on the Arduino. The pin numbers in the code should be changed if different pins are used.

Arduino - TM1637 4-Digit 7-Segment Display | Arduino Tutorial (4)

This image is created using Fritzing. Click to enlarge image

Library Installation

To program easily for TM1637 4-digit 7-segment Display, we need to install TM1637Display library by Avishay Orpaz. Follow the below steps to install the library:

  • Navigate to the Libraries icon on the left bar of the Arduino IDE.

  • Search “TM1637”, then find the TM1637Display library by Avishay Orpaz

  • Click Install button.

Arduino - TM1637 4-Digit 7-Segment Display | Arduino Tutorial (5)

How To Program For TM1637 4-digit 7-segment using Arduino

  • Include the library

  • Define Arduino's pins that connects to CLK and DIO of the display module. For example, pin D9 and D10

#define CLK 9#define DIO 10

  • Create a display object of type TM1637Display

TM1637Display display = TM1637Display(CLK, DIO);

  • Then you can display number, number with decimal, number with minus sign, or letter. In the case of leter, you need to define the letter form. Let's see one by one.

  • Display number: see below examples, '_' in below description represents for a digit that does not display anything in pratice:

display.showNumberDec(-12); // displayed _-12display.showNumberDec(-999); // displayed -999display.showNumberDec(42); // displayed __42display.showNumberDec(42, false); // displayed __42display.showNumberDec(42, false, 2, 0); // displayed 42__ => display 2 digit at position 0display.showNumberDec(42, true); // displayed 0042 => zero paddingdisplay.showNumberDec(14, false, 2, 1); // displayed _14_display.showNumberDec(-5, false, 3, 0); // displayed _-5_display.showNumberDec(1234); // displayed 1234

  • Display the number with a colon or dot:

// displayed 15:30 in the colon-separated module, or 15.30 in the colon-separated moduledisplay.showNumberDecEx(1530, 0b11100000, false, 4, 0);

You can see more detail in the function references at the end of this tutorial

Arduino Code

/* * 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 */#include <TM1637Display.h>// define the connections pins#define CLK 9#define DIO 10// create a display object of type TM1637DisplayTM1637Display display = TM1637Display(CLK, DIO);// an array that sets individual segments per digit to display the word "dOnE"const uint8_t done[] = { SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O SEG_C | SEG_E | SEG_G, // n SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E};// degree celsius symbolconst uint8_t celsius[] = { SEG_A | SEG_B | SEG_F | SEG_G, // Degree symbol SEG_A | SEG_D | SEG_E | SEG_F // C};void setup() { display.clear(); display.setBrightness(7); // set the brightness to 7 (0:dimmest, 7:brightest)}void loop() { // show counter 0-9 int i; for (i = 0; i < 10; i++) { display.showNumberDec(i); delay(500); display.clear(); } display.showNumberDec(-91); // displayed _-91 delay(2000); display.clear(); display.showNumberDec(-109); // displayed -109 delay(2000); display.clear(); display.showNumberDec(21, false); // displayed __21 delay(2000); display.clear(); display.showNumberDec(21, true); // displayed 0021 delay(2000); display.clear(); display.showNumberDec(28, false, 2, 1); // displayed _28_ delay(2000); display.clear(); display.showNumberDec(-9, false, 3, 0); // displayed _-9_ delay(2000); display.clear(); // displayed 15:30 display.showNumberDecEx(1530, 0b11100000, false, 4, 0); delay(2000); display.clear(); // displayed 23°C int temperature = 23; // or read from temperature sensor display.showNumberDec(temperature, false, 2, 0); display.setSegments(celsius, 2, 2); delay(2000); display.clear(); // displayed letters: dOnE display.setSegments(done); delay(2000); display.clear();}

Quick Steps

  • Copy the above code and open with Arduino IDE

  • Click Upload button on Arduino IDE to upload code to Arduino

  • See the states of the 7-segment display

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

Function References

The below are references for the following functions:

display.clear()

Description

This function clear the display. It turns all LEDs off

display.showNumberDec()

Description

The function is used to display a decimal number on the 7-segment display.

Syntax

void showNumberDec(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);

Parameter

  • num: This is the number to be displayed on the 7-segment display. It should be within the range of -9999 to 9999.

  • leading_zero: This is an optional parameter with a default value of false. If it is set to true, leading zeros will be displayed.

  • length: This is an optional parameter with a default value of 4. It sets the number of digits to be displayed on the 7-segment display.

  • pos: This is an optional parameter with a default value of 0. It sets the position of the most significant digit of the number.

Please note that, if the number is out of range or if the value of length is greater than 4, the function will not display anything.

showNumberDecEx()

Description

The function is used to display a decimal number on the 7-segment display with additional features compared to the showNumberDec() function. It is an advanced version of showNumberDec() that allows you to control the dot or colon segments of each digit individually.

Syntax

void showNumberDecEx(int num, uint8_t dots, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);

Parameter

  • num1: This is the number to be displayed on the 7-segment display. It should be within the range of -9999 to 9999.

  • dots: This parameter is used to specify which segments of the display should be turned on as dots. Each bit of the value corresponds to a digit on the display: Valid value

    • 0b10000000: display the first dot: 0.000

    • 0b01000000: display the second dot: 00.00

    • 0b00100000: display the third dot: 000.0

    • 0b01000000: For displays with just a colon: 00:00

  • leading_zero: This is an optional parameter with a default value of false. If it is set to true, leading zeros will be displayed.

  • length: This is an optional parameter with a default value of 4. It sets the number of digits to be displayed on the 7-segment display.

  • pos: This is an optional parameter with a default value of 0. It sets the position of the most significant digit of the number.

For example, if you call display.showNumberDecEx(1530,0b01000000); it will display the number 15:30 on the 7-segment display.

Please note that, if the number is out of range or if the value of length is greater than 4, the function will not display anything.

setSegments()

Description

The function is used to set the segments of the 7-segment display directly. It can be used to dislay letters, special character, or turn all all LED segment.

Syntax

void setSegments(const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);

Parameter

  • segments: This parameter sets the segments of the 7-segment display, it's an array of bytes, where each byte represents the segments of each digit. Each segment is represented by a bit in the byte.

  • length: This is an optional parameter with a default value of 4. It sets the number of digits to be displayed on the 7-segment display.

  • pos: This is an optional parameter with a default value of 0. It sets the position of the most significant digit of the number.

This function is useful when you want to display characters or symbols that are not included in the basic 7-segment display. By setting the segments directly, you can display any pattern you want.

Please note that, if the number is out of range or if the value of length is greater than 4, the function will not display anything.

setBrightness()

Description

The function is used to set the brightness of the 7-segment display.

Syntax

void setBrightness(uint8_t brightness, bool on = true);

Parameter

  • brightness: This parameter sets the brightness level of the 7-segment display. The value should be in the range of 0 to 7. A higher value results in a brighter display.

  • on: This is an optional parameter with a default value of true. It's used to turn on or off the display. If it's set to false, the display will be turned off.

The Best Arduino Starter Kit

  • See the best Arduino kit for beginner

See Also

  • Arduino - 74HC595 4-Digit 7-Segment Display

  • Arduino - 7-segment Clock

※ OUR MESSAGES

  • We are AVAILABLE for HIRE. See how to hire us to build your project

  • If this tutorial is useful for you, please give us motivation to make more tutorials.

  • You can share the link of this tutorial anywhere. Howerver, please do not copy the content to share on other websites. We took a lot of time and effort to create the content of this tutorial, please respect our work!

PREVIOUS

NEXT

DISCLOSURE

ArduinoGetStarted.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com, Amazon.it, Amazon.fr, Amazon.co.uk, Amazon.ca, Amazon.de, Amazon.es, Amazon.nl, Amazon.pl and Amazon.se

Copyright © 2018 - 2024 ArduinoGetStarted.com. All rights reserved.
Terms and Conditions | Privacy Policy

Email: ArduinoGetStarted@gmail.com

Arduino - TM1637 4-Digit 7-Segment Display | Arduino Tutorial (2024)
Top Articles
Latest Posts
Article information

Author: Madonna Wisozk

Last Updated:

Views: 5401

Rating: 4.8 / 5 (48 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Madonna Wisozk

Birthday: 2001-02-23

Address: 656 Gerhold Summit, Sidneyberg, FL 78179-2512

Phone: +6742282696652

Job: Customer Banking Liaison

Hobby: Flower arranging, Yo-yoing, Tai chi, Rowing, Macrame, Urban exploration, Knife making

Introduction: My name is Madonna Wisozk, I am a attractive, healthy, thoughtful, faithful, open, vivacious, zany person who loves writing and wants to share my knowledge and understanding with you.