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 kit:

1×DIYables Sensor Kit 30 types, 69 units

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)

FAQs

How to display numbers on 7-segment display using Arduino? ›

Using byte digitPins[] = {10, 11, 12, 13} on line 6 sets Arduino pin 10 as the first digit pin, Arduino pin 11 to the second digit pin, and so on. To print numbers with a decimal point, we set the second parameter in sevseg. setNumber(4999, 3) to three, which puts it three decimal places from the right most digit.

What is a 4-digit 7-segment display layout? ›

4-Digit 7-segment display consists of four 7- segment displays working together. The 4-digtal 7-segment display works independently. It uses the principle of human visual persistence to quickly display the characters of each 7-segment in a loop to form continuous strings.

How do you use a 4 digit 7-segment LED display? ›

We first set the segments of the first digit and turn the D1 input ON. Then we repeat by turning the appropriate segments for the number 2 in the second digit by turning the D1 OFF (because that would make the first digit to also display the number 2) and turning the D2 ON.

What is TM1637 4 digit 7-segment LED display? ›

The TM1637 Driver Chip controls the 4 digits on this 7-segment LED Display. This TM1637 4 Bits Digital Tube LED Display Module can be controlled with only two connections. You can also power it with just two wires thanks to the I2C Bus, which frees up more pins on your Micro Controller to attach other stuff.

What is the voltage of 4 digit 7-segment display? ›

3.7 to 5.3 V

How can a 7-segment LED be connected to an Arduino? ›

Connect either of the common pins (seven-segment pin 3 or 8) to the ground. And connect the rest of the pins to D2 to D9 of the Arduino through a current limiting resistor, as per the connection diagram. Just like driving an LED, it is preferable to use these current limiting resistors to increase the display life.

How to display numbers on 7-segment display? ›

For instance, to display the numerical digit 0, we will need to light up six of the LED segments corresponding to a, b, c, d, e and f. Thus the various digits from 0 through 9 can be displayed using a 7-segment display as shown.

How many digits are displayed on 7-segment? ›

In addition to the ten digits, seven-segment displays can be used to show most letters of the Latin, Cyrillic and Greek alphabets including punctuation. One such special case is the display of the letters A–F when denoting the hexadecimal values (digits) 10–15.

What maximum digit can be displayed in seven-segment display? ›

Each LED is called a segment that maps to one of the terminals A through G. By giving the proper binary-digit inputs to segments A through G, you can control the illumination of the segments, which allows you to display decimal numbers from 0 to 9 and letters from A to F.

What does DP stand for in 7-segment display? ›

The individual segments are referred to by the letters "a" to "g", and an optional decimal point (an "eighth segment", referred to as DP) is sometimes used for the display of non-integer numbers. A single byte can encode the full state of a seven-segment display, including the decimal point.

Which code is used in 7-segment display? ›

Arduino Code for Seven Segment Display

The pins are listed in the order a, b, c, d, e, f, g, and the decimal point. The segmentCode array defines the binary pattern needed to turn on each segment for the digits 0-9 and the decimal point. Each row represents a digit, and each column represents a segment.

What is an example of a 7-segment display? ›

Common Uses of the Seven Segment Display

Examples include simple calculators, digital clocks, microwave ovens, refrigerators, and plenty of other devices that display numerals. With the express expansion of IoT, segmented displays have also followed suit, as they can be utilized in numerous ways.

Top Articles
Latest Posts
Article information

Author: Carlyn Walter

Last Updated:

Views: 6063

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.