Using Two More TM1637 4-Digit LED Displays with Arduino
Have you ever needed to show two different values at the same time in your Arduino project? Perhaps you're building a weather station that needs to display both temperature and humidity, or a power supply monitor that shows voltage and current simultaneously. Using two TM1637 4-digit LED displays is a straightforward and cost-effective solution. This guide will show you how to connect and program two of these popular displays using a single Arduino board, giving you the ability to display independent information on each screen. You can use this technique for a variety of projects, such as:
- Building a dual-channel voltmeter to monitor two separate power rails.
- Creating a countdown timer and a lap counter for your next racing project.
- Displaying the current time on one display and the ambient temperature on the other.
- Making a scoreboard for two-player games.
In this tutorial, we will wire two TM1637 modules to an Arduino Uno and run a demonstration sketch that shows different values on each display. The TM1637 uses a two-wire interface (CLK and DIO), which means adding a second display only requires two additional digital pins on your Arduino. Let's get started! (in video at 00:00)
Hardware Required
- Arduino Uno (or any compatible board)
- 2x TM1637 4-digit 7-segment LED display modules
- Jumper wires
- Breadboard (optional, but helpful for prototyping)
Wiring Guide
Connecting the displays is simple. The TM1637 module has four pins: VCC, GND, DIO (data), and CLK (clock). Both displays share the 5V and GND connections from the Arduino, but each needs its own dedicated pins for DIO and CLK. This allows the Arduino to control them independently. (in video at 01:26)
Here is the wiring diagram for the project:
For the first display (the larger blue module in the video), make the following connections:
- VCC to Arduino 5V
- GND to Arduino GND
- DIO to Arduino digital pin 11
- CLK to Arduino digital pin 10
For the second display (the smaller module), connect it as follows:
- VCC to Arduino 5V
- GND to Arduino GND
- DIO to Arduino digital pin 6
- CLK to Arduino digital pin 5
Remember, the code and library work the same for both the larger and smaller TM1637 modules. (in video at 01:00)
Code Explanation
The code uses the TM1637Display library, which you will need to install. You can do this by going to Sketch > Include Library > Manage Libraries in the Arduino IDE and searching for "TM1637". The code defines the pins for each display and creates two objects to control them. Let's look at the key parts you will need to configure for your own use. (in video at 02:31)
First, the pin definitions for each display module. You will need to change these to match your wiring:
// Module 1 connection pins (Digital Pins)
#define CLK1 5
#define DIO1 6
// Module 2 connection pins (Digital Pins)
#define CLK2 10
#define DIO2 11
Next, the TEST_DELAY variable controls how long each test sequence is displayed. You can adjust this to speed up or slow down the demonstration:
// The amount of time (in milliseconds) between tests
#define TEST_DELAY 5000
The main part of the code uses the showNumberDec() function. This function has four arguments: the number to display, whether to fill empty leading digits with zeros, how many digits to use, and the starting position of the number on the display. For example, display1.showNumberDec(23, false, 2, 0) will display the number "23" starting at position 0. By changing the last argument to 1, 2, or 3, you can shift the number across the display. (in video at 05:23)
To add a third display, you would simply copy the code block for a display, change all the "2"s to "3"s, and assign two new pins for the new module's CLK and DIO connections. (in video at 03:58)
Live Project Demonstration
Once you have uploaded the code, you will see the two displays power on and clear their screens. The demonstration then runs through a series of tests to show how each display can be controlled independently. First, it will show the numbers "23" and "34" on the two displays. The code then cycles through placing these numbers at different positions on the 4-digit display (position 0, 1, 2, and 3). After that, it displays the larger numbers "741" and "1562". Finally, it runs a count-up loop from 0 to 1273 on both displays simultaneously. This demonstrates the full functionality of using two displays in a single project. (in video at 05:01)
Chapters
- [00:00] Introduction to using two TM1637 displays
- [01:26] Wiring the displays to the Arduino
- [02:31] Explaining the code
- [05:01] Demonstration of the displays in action
/*
* Original code from https://github.com/avishorp/TM1637
* Modified for Robojax video on October 28, 2018 at 15:05
* This is an Arduino sketch to use two or more TM1637 seven-segment LED displays
*
* Watch video instruction for this code:https://youtu.be/27KjMfPH1dk
*
* by Ahmad Shamshiri, in Ajax, Ontario, Canada
*
* display2.showNumberDec(23, true, 2,1);
* showNumberDec(arg1, arg2, arg3, arg4);
* arg1 is the number to be displayed
* arg2 can be 'true' or 'false' and if true it fills empty spots with data[]
* arg4 position of starting number on the display can be either 0, 1, 2 or 3
*/
#include <Arduino.h>
#include <TM1637Display.h>
// Module 1 connection pins (Digital Pins)
#define CLK1 5
#define DIO1 6
// Module 2 connection pins (Digital Pins)
#define CLK2 10
#define DIO2 11
// The amount of time (in milliseconds) between tests
#define TEST_DELAY 5000
TM1637Display display1(CLK1, DIO1);// define display 1 object
TM1637Display display2(CLK2, DIO2);// define display 1 object
uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 }; // all segments clear
void setup()
{
// Robojax.com two or more TM1637 Display 20181029
display1.setBrightness(0x0f);// set brightness of display 1
display2.setBrightness(0x0f);// set brightness of display 1
display1.setSegments(data);// fill display 1 with whatever data[] array has
display2.setSegments(data);// // fill display 2 with whatever data[] array has
// Robojax.com two or more TM1637 Display 20181029
}
void loop()
{
// Robojax.com two or more TM1637 Display 20181029
/////////////////////////////////////////////////
display1.setSegments(data); // fill(clear) display with data[] array
display1.showNumberDec(23, false, 2,0);
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(34, false, 2,0);
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
/////////////////////////////////////////////////
display1.setSegments(data); // fill(clear) display with data[] array
display1.showNumberDec(23, false, 2,1);
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(34, false, 2,1);
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
/////////////////////////////////////////////////
display1.setSegments(data); // fill(clear) display with data[] array
display1.showNumberDec(23, false, 2,2);
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(34, false, 2,2);
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
/////////////////////////////////////////////////
display1.setSegments(data); // fill(clear) display with data[] array
display1.showNumberDec(23, false, 2,3);
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(34, false, 2,3);
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
/////////////////////////////////////////////////
display1.setSegments(data);// fill(clear) display with data[] array
display1.showNumberDec(741);// display 1
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(1562);// display 2
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
// Robojax.com two or more TM1637 Display 20181029
/////////////////////////////////////////////////
display1.setSegments(data);// fill(clear) display 1 with data[] array
display2.setSegments(data);// fill(clear) display 2 with data[] array
for(int i=0; i<=1273; i++)
{
display1.showNumberDec(i);// display from 0 to 1273 to display 1
display2.showNumberDec(i);// display from 0 to 1273 to display 2
}
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
// Robojax.com two or more TM1637 Display 20181029
}// loop end
Things you might need
-
Amazon
-
eBay
-
AliExpressTM1637 4-digit 7-segment display on AliExpresss.click.aliexpress.com
Resources & references
-
ExternalTM1637 library (from GitHub)github.com
-
Internal
Files📁
Arduino Libraries (zip)
-
TM1637 Arduino Library
TM1637_library.zip1.36 MB
Fritzing File
-
TM1637 Seven Segment module
TM1637.fzpz0.01 MB -
TM1637 4 digit seven segment display
TM1637-1.fzpz0.01 MB
User’s Manual
-
TM1637 Display Manual
robojax-TM1637_display_manual.pdf0.31 MB