Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » How to use TM1637 4-digit 7-segment LED display with Arduino
Arduino Projects

How to use TM1637 4-digit 7-segment LED display with Arduino

Mamtaz AlamBy Mamtaz AlamUpdated:September 27, 20222 Comments7 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
TM1637 Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this tutorial, we will learn how to use the TM1637 4-digit 7-segment LED display with Arduino. These displays are cheaper & best for displaying sensor data, time, stopwatch, random numbers, etc. It is similar to other 4-digit 7-segment displays but has a TM1637 LED Driver IC embedded in it. This removes the extra wiring and using only 2 wires the display can be controlled.

I have explained three TM1637 Arduino example in this tutorial. In the first example, we will look at the basic functions of the TM1637 Display library & display some random numbers and letters. In the second example, we will use TM1637 with Arduino to create a simple temperature display in combination with the DHT11. In the third example, we will use the DS3231 Real Time Clock Module to display the Time on TM1637 Display.


Bill of Materials

We need the following components for this tutorial. You can purchase all these components from Amazon.

S.N.ComponentsQuantityPurchase Links
1Arduino Nano Board1Amazon | AliExpress
2TM1637 4-Digit 7-Segment Display1Amazon | AliExpress
3DS3231 RTC Module1Amazon | AliExpress
4DHT22/11 Sensor1Amazon | AliExpress
5Jumper Wires20Amazon | AliExpress
6Breadboard1Amazon | AliExpress



TM1637 4-digit 7-segment LED display

The Bare 4-digit 7-segment displays usually require 12 connection pins. But the TM1637 IC is mounted on the back of the display module, which reduces the total wire to 4. Two pins are required for the power connections and the other two pins are used to control the segments.

The TM1637 module includes four 0.36″ segment 7-segment displays. The module has a ‘colon’ at the center useed to create clock or time-based projects. At the back of the display, there is an inexpensive serial LED driver from Titan MicroElectronics called TM1637. The TM1637 supports many functions – including ON/OFF and brightness control of the LEDs as well as accessing each of the segments.

The module operates between 3.3V to 5V with a current consumption of 80mA. We can interface TM1637 with Arduino or any other microcontroller using the two data pins. There is multiple TM1637 Library for Arduino that removes the complexities and makes it easier to communicate with the display.


TM1637 Module Pinout

There is a 4-pin male header on the module for making connections.

TM1637 Pinout

1. GND: Ground Pin
2. VCC: 3.3V to 5V power supply Pin
3. DIO: Data Input/Output Pin
4. CLK: Clock Input Pin




Interfacing TM1637 4-digits LED Display with Arduino

Now, let us interface TM1637 4-digits LED Display with Arduino Nano Board. The connection is fairly simple. Make a connection between TM1637 & Arduino Nano Board as shown in image.

TM1637 Arduino

Connect the VCC & GND Pin of TM1637 Module to Arduino 5V & GND Pin. Similarly, connect the Module CLK & DIO Pin to Arduino digital pin 2 & 3 respectively.

Arduino TM1637 Connection


TM1637 Arduino Library Installation

There are several libraries for TM1637 Display. Out of all those libraries, the library from Avishay Orpaz is the most popular one. This library has several built-in functions that make controlling the display simple. We need to specify which number to display and it will handle.

You can download the TM1637 Library from the Github Link.

You can also visit the Library manager and install the library directly. Search by typing ‘tm1637‘ & check for the library by Avishay Orpaz. Click on that and then select Install.

TM1637 Library

This library has several built-in functions that make controlling the display fairly easy.

  • setSegments() – Set the raw value of the segments of each digit
  • showNumberDec() – Display a decimal number
  • showNumberDecEx() – Display a decimal number with decimal points or colon
  • setBrightness() – Set the brightness of the display
  • clear() – Clear the display

Basic TM1637 Arduino Example Code

This is the basic example code taken from the example of TM1637 Library. Copy the following code and paste it on your Arduino IDE. Then you can compile and upload the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <Arduino.h>
#include <TM1637Display.h>
 
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
 
// The amount of time (in milliseconds) between tests
#define TEST_DELAY   2000
 
const uint8_t SEG_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
    };
 
TM1637Display display(CLK, DIO);
 
void setup()
{
}
 
void loop()
{
  int k;
  uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
  display.setBrightness(0x0f);
 
  // All segments on
  display.setSegments(data);
  delay(TEST_DELAY);
 
  // Selectively set different digits
  data[0] = display.encodeDigit(0);
  data[1] = display.encodeDigit(1);
  data[2] = display.encodeDigit(2);
  data[3] = display.encodeDigit(3);
  display.setSegments(data);
  delay(TEST_DELAY);
 
  /*
  for(k = 3; k >= 0; k--) {
    display.setSegments(data, 1, k);
    delay(TEST_DELAY);
    }
  */
 
  display.clear();
  display.setSegments(data+2, 2, 2);
  delay(TEST_DELAY);
 
  display.clear();
  display.setSegments(data+2, 2, 1);
  delay(TEST_DELAY);
 
  display.clear();
  display.setSegments(data+1, 3, 1);
  delay(TEST_DELAY);
 
 
  // Show decimal numbers with/without leading zeros
  display.showNumberDec(0, false); // Expect: ___0
  delay(TEST_DELAY);
  display.showNumberDec(0, true);  // Expect: 0000
  delay(TEST_DELAY);
    display.showNumberDec(1, false); // Expect: ___1
    delay(TEST_DELAY);
  display.showNumberDec(1, true);  // Expect: 0001
  delay(TEST_DELAY);
  display.showNumberDec(301, false); // Expect: _301
  delay(TEST_DELAY);
  display.showNumberDec(301, true); // Expect: 0301
  delay(TEST_DELAY);
  display.clear();
  display.showNumberDec(14, false, 2, 1); // Expect: _14_
  delay(TEST_DELAY);
  display.clear();
  display.showNumberDec(4, true, 2, 2);  // Expect: 04__
  delay(TEST_DELAY);
  display.showNumberDec(-1, false);  // Expect: __-1
  delay(TEST_DELAY);
  display.showNumberDec(-12);        // Expect: _-12
  delay(TEST_DELAY);
  display.showNumberDec(-999);       // Expect: -999
  delay(TEST_DELAY);
  display.clear();
  display.showNumberDec(-5, false, 3, 0); // Expect: _-5_
  delay(TEST_DELAY);
  display.showNumberHexEx(0xf1af);        // Expect: f1Af
  delay(TEST_DELAY);
  display.showNumberHexEx(0x2c);          // Expect: __2C
  delay(TEST_DELAY);
  display.showNumberHexEx(0xd1, 0, true); // Expect: 00d1
  delay(TEST_DELAY);
  display.clear();
  display.showNumberHexEx(0xd1, 0, true, 2); // Expect: d1__
  delay(TEST_DELAY);
  
    // Run through all the dots
    for(k=0; k <= 4; k++) {
        display.showNumberDecEx(0, (0x80 >> k), true);
        delay(TEST_DELAY);
    }
 
  // Brightness Test
  for(k = 0; k < 4; k++)
    data[k] = 0xff;
  for(k = 0; k < 7; k++) {
    display.setBrightness(k);
    display.setSegments(data);
    delay(TEST_DELAY);
  }
  
  // On/Off test
  for(k = 0; k < 4; k++) {
    display.setBrightness(7, false);  // Turn off
    display.setSegments(data);
    delay(TEST_DELAY);
    display.setBrightness(7, true); // Turn on
    display.setSegments(data);
    delay(TEST_DELAY);  
  }
 
  // Done!
  display.setSegments(SEG_DONE);
 
  while(1);
}



The TM1637 Display will immediately turn ON and starts displaying the random numbers and characters as per the code.


Code Explanation

1
2
#include <Arduino.h>
#include <TM1637Display.h>

The code starts with including the library. Install the correct library else you will get an error message while compiling the code.

1
2
#define CLK 2
#define DIO 3

Next we need to specify the connection pins for CLK & DIO.

1
2
3
4
5
6
const uint8_t SEG_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
    };

You can create arrays to spell words. Each segment is separated by a | and digits of the display are separated by a comma. This array will display “done” on LED Display.

1
#define TEST_DELAY   2000

This is the amount of time in milliseconds between the tests. This means the next thing will be displayed after an interval of 200 milliseconds.

1
TM1637Display display(CLK, DIO);

Then we need to create a new instance of the TM1637Display class with the function TM1637Display(). This function requires two parameters, first the CLK pin and the second the DIO pin.

1
2
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };

The first option to set individual segments is to use hexadecimal numbers. Hexadecimal 0xFF translates to 11111111 in binary, and it turns all segments ON while 0x00 will turn OFF all segments.

1
2
    display.setBrightness(7, false);  // Turn off
    display.setBrightness(7, true); // Turn on

This function is used to set the brightness of the display using the syntax setBrightness(brightness,on). You can specify a brightness level from 0 (lowest brightness) to 7 (highest brightness). You can pass it true (display ON) or false (display OFF).

1
2
display.setSegments(data);
display.setSegments(data+2, 2, 2);

This function can be used to set individual segments of a display. The first argument is the array that contains the segment information. The second argument specifies the number of digits to be updated between 0 to 4. The third argument determines the position from which you want to print (0-leftmost, 3-rightmost).


Displaying Temperature Value on TM1637 using DHT11 Sensor

We can make our own Digital Thermometer using DHT22/11 Sensor along with the TM1637 Display & Arduino. The connection diagram is fairly simple. You can use a breadboard to assemble the circuit.

TM1637 Arduino DHT11

The DHT11/22 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and spits out a digital signal on the data pin. To learn more about this sensor follow up the DHT11 Arduino Interfacing tutorial. In this project, I used breadboard to assemble DHT22 Sensor with Arduino & TM1637 Display.



Source Code/Program

This code will simply display the temperature value of the surrounding on TM1637 Display.

Copy the following code and paste it on your Arduino IDE. Before compiling this code, you need to add DHT Library to the library folder.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Include the libraries
#include <TM1637Display.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
 
// Define the connections pins
#define CLK 2
#define DIO 3
#define DHTPIN 5
 
// Create variable
int temperature_celsius;
int temperature_fahrenheit;
 
// Create °C symbol
const uint8_t celsius[] = {
  SEG_A | SEG_B | SEG_F | SEG_G,  // Circle
  SEG_A | SEG_D | SEG_E | SEG_F   // C
};
 
// Create °F symbol
const uint8_t fahrenheit[] = {
  SEG_A | SEG_B | SEG_F | SEG_G,  // Circle
  SEG_A | SEG_E | SEG_F | SEG_G   // F
};
 
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
 
// Create display object of type TM1637Display
TM1637Display display = TM1637Display(CLK, DIO);
 
// Create dht object of type DHT:
DHT dht = DHT(DHTPIN, DHTTYPE);
 
void setup() {
  // Set the display brightness (0-7)
  display.setBrightness(5);
  
  // Clear the display
  display.clear();
  
  // Setup sensor
  dht.begin();
}
 
void loop() {
  // Read the temperature as Celsius and Fahrenheit
  temperature_celsius = dht.readTemperature();
  temperature_fahrenheit = dht.readTemperature(true);
 
  // Display the temperature in celsius format
  display.showNumberDec(temperature_celsius, false, 2, 0);
  display.setSegments(celsius, 2, 2);
  delay(1000);
 
  // Display the temperature in fahrenheit format
  display.showNumberDec(temperature_fahrenheit, false, 2, 0);
  display.setSegments(fahrenheit, 2, 2);
  delay(1000);
}

The display will start displaying the temperature both in degrees Celcius and Fahrenheit.


Creating a Clock with TM1637 and DS3231 RTC Module

We can use the TM1637 Display & DS3231 RTC Module with Arduino to create a Real Time Clock as well. The connection diagram is given below.

TM1637 Arduino DS3231

The DS3231 RTC module Precise Real-Time Clock Module is a low-cost, extremely accurate I²C real-time clock (RTC) with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The module can be interfaced with Arduino & any other controller to design a Real-Time Clock. Check our previous DS3231 & Arduino Interfacing tutorial.


Source Code/Program

This code will display the time in minute and hour on TM1637 Display.

Copy the following code and upload it to the Arduino Board. But before that add the DS3231 RTC Library to the Library Folder.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Include the libraries
#include "RTClib.h"
#include <TM1637Display.h>
 
// Define the connections pins
#define CLK 2
#define DIO 3
 
// Create rtc and display object
RTC_DS3231 rtc;
TM1637Display display = TM1637Display(CLK, DIO);
 
void setup() {
  // Begin serial communication
  Serial.begin(9600);
 
  // Check if RTC is connected correctly
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  // Check if the RTC lost power and if so, set the time
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // The following line sets the RTC to the date & time this sketch was compiled:
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
 
  // Set the display brightness (0-7)
  display.setBrightness(5);
  
  // Clear the display
  display.clear();
}
 
void loop() {
  // Get current date and time
  DateTime now = rtc.now();
 
  // Create time format to display
  int displaytime = (now.hour() * 100) + now.minute();
 
  // Display the current time in 24 hour format with leading zeros and a center colon enabled
  display.showNumberDecEx(displaytime, 0b11100000, true);
 
  delay(1000);
}


The TM1637 Display will start showing the Time immediately after you load the code.


Video Tutorial & Guide

How to use TM1637 4-digit 7-segment LED display with Arduino | Quick & Brief Tutorial
Watch this video on YouTube.

You can also use TM1637 with MicroPython Code on Raspberry Pi Pico Board.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleIndoor Environment Monitoring with ESP32 & LCD Screen
Next Article ESP32 CAM Based Face & Eyes Recognition System

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 2 Comments

2 Comments

  1. Murat on September 4, 2021 11:25 AM

    Hello, first of all congratulations for the article. I have a problem with my project.

    I am using arduino, tm1637 and DFPlayer in my project.

    The problem is that if I play music while displaying a number on the display, I get excessive noise from the speaker.

    When I dim the display (display is connected but I don’t show numbers – display.clear() )

    I can play music from the speaker just fine.

    Do you have an idea for solving the problem?

    Reply
  2. Juan on November 1, 2022 7:35 AM

    Comprate un JBL estupido del orto

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use INA219 DC Current Sensor Module with Arduino
    How to use INA219 DC Current Sensor Module with Arduino
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • Interfacing PN532 NFC RFID Module with Arduino
    Interfacing PN532 NFC RFID Module with Arduino
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.