In this tutorial, I am going to show you guys how to control the TM1637 4-Digit 7-Segment displays using an Arduino. If you want to displays sensor data, temperature and humidity, or want to design a clock, timer or counter, you will need this 4-Digit Seven-Segment Display.
--------------------------------------------------------------------- Thanks again for checking my post. I hope it helps you. If you want to support me subscribe to my YouTube Channel: https://www.youtube.com/user/tarantula3
In my hand is a 4-digit 7-segment display module. The heart of this module is an inexpensive serial
LED driver from Titan Micro Electronics called the TM1637. In this tutorial, I'm going to show
you guys how to control the TM1637 4-digit 7-segment display using an Arduino. If you
want to display sensor data, temperature and humidity or want to design a clock,
timer or a counter, you will need this 4-digit 7-segment display.
This video is sponsored by PCBWay. PCBWay specializes in manufacturing of very high
quality, low volume, colored PCBs at a very budgetary price. In addition to standard PCBs,
you can order advanced PCBs, aluminum PCBs, rigid flex PCBs. They also provide PCB assembly and
other related services which can meet your need at the greatest extent. In this tutorial, we are
going to talk about the basics of the 7-segment display, hardware overview and pinouts of TM1637
module, TM1637 library installation, interfacing TM1637 module with an Arduino, loading the basic
Arduino code that comes with the TM1637 library. Then we'll have a look at some of these quick
examples, displaying string and a number, displaying scrolling and a blinking text,
creating a 4-digit counter, displaying temperature and humidity using DHT11 or DHT22 sensor,
creating an Arduino-based digital clock. And finally, we'll have a look at some of the common
errors. A 7-segment display consists of 7 LEDs making the shape of decimal number 8. These LEDs
are called segments because when they light up, each segment contributes in the formation of part
of a decimal or hex digit. These individual segments are labeled from A to G, representing
each individual LED. By setting a particular segment high or low, a desired character pattern
can be generated. The module comes with four right-angle male pin headers. I find it a bit
annoying to have the pin headers on the top side of the board. However, you can always unsolder and
put them at the bottom of the board. Now, let's have a look at the GPIO pins. CLK is the clock
input pin. You can connect it to any digital pin of the Arduino. DIO is the data input-output pin.
This can also be connected to any digital pin of Arduino. VCC connects to 3.3 to 5-volt power
supply. GND is the ground pin. CLK and DIO pins can be connected to any digital pin of an Arduino.
This gives us an opportunity to hook up a lot of these modules to Arduino as long as each instance
has a pair of its own. When writing the code, we just need to specify the pin pair and then
just go ahead and use them in our code. If you run out of pins on your Arduino board, you can
use a GPIO pin extender like the PCF8574. Please check out my tutorial on this extender module.
The link is in the description below. The module has 4.36 segment, 7 segment display and a colon
at the center for creating clock or time-based projects. A bare 4-digit 7-segment display usually
requires 12 connection pins, but TM1637 LED driver removes the need of the extra wiring
for the 7-segment and the entire setup can be controlled using 2 wires and 2 more for power,
reducing the total wires to 4. These modules communicate with the processor using I2C-like
protocol. The implementation is pure software emulation and does not make use of any special
hardware other than the GPIO pins. The modules operate between 3.3V to 5V with a current
consumption of 80mA and allows adjusting the brightness of the LED at the software level.
These modules are available in few different colors.
There are many libraries available for this TM1637 module. For this tutorial, we are going
to use the TM1637 display library written by Avishai Opaz. You can download the library
using the library manager or from GitHub. The link is in the description below.
To install the library using the library manager, navigate to Sketch, Include Library,
Manage Libraries. Search for TM1637 and look for the one by Avishai Opaz.
Hit the Install button to install the library on your device.
Hooking up TM1637 module to an Arduino is very easy. You just need to connect 4 wires,
2 for power and the other 2 for controlling the display. So connect CLK to pin number 2 of Arduino,
DIO to pin number 3, VCC to 5V or 3.3V pin of Arduino and the GND to GND.
As previously advised, you can use any pin combination for the CLK and DIO on the Arduino
board. Just make sure you change the pin number in your code to reflect the change of wiring.
Before going ahead, let's have a look at the example that comes with the TM1637 library.
Navigate to File, Examples, TM1637 and load the TM1637 test example.
The sketch starts by including the TM1637 display.h library. Then it defines the CLK
and the DIO pins that will be used to connect the TM1637 display. In this example,
pin number 2 of Arduino is used for CLK and pin number 3 for DIO. Next, you need to create a new
instance of the TM1637 display class by passing the CLK and the DIO pin values to it. Then the
code shows us 2 ways of displaying data on the individual segments by creating arrays of text.
First by passing hexadecimal numbers to individual displays. Passing hex FF to all
the 4 displays will turn them all on and passing hex 00 will turn them all off.
Using the display.encodeDigit function, you can display digits between 1 and 15.
Second by individually specifying the segments that you want to turn on.
This creates an array that sets the individual segment values and displays done on the display.
Now to display these character arrays, we pass them to the display.setSegment function.
The setSegment function accepts 3 arguments. First one is the data and the other two are
optional arguments such as the length and the position. Remember, the LEDs once turned on
stays on until they are turned off. So you always have to clear the previous value before displaying
the new one. This can be done by passing 4 lots of hex FF to the display.setSegment function
or by using the display.clear function. The brightness of the display can be adjusted
using the setBrightness function. The function accepts value between 0 and 7.
The display.showNumberDec function is the function that you are going to use the most
to display numbers on the module. The first argument is a number that you want to display
on the screen and the rest of the arguments are all optional. For the rest of the examples,
I am going to use this template to write the code. I will only show you guys that bit which
In this example, you can see the letter test and a randomly generated number
is alternating and getting displayed on the screen. To display the letter test,
I am first clearing the screen and then lighting up individual segments to display the characters.
To display a number, I am first generating a random number between 0 and 9999 and then
displaying it using the display.showNumberDec function. Now to display a scrolling text,
I am incrementing the position of the text by 1 and then displaying it from the new position.
You need to pad the back and the front of the text with any character or you will end up showing
random characters on the display. Blinking a text is super easy. All you have to do is display the
text, add a delay, clear the screen and then again add a delay before displaying the text again.
To display a counter, I am looping from 0 to 9999 and then displaying the incremented value
every time on the 7 segments. You can also add a push button switch to start and stop the counter.
Connect the out pin of the DHT11 or DHT22 sensor to pin number 5 of Arduino. Then in the code,
include the DHT.h library and define the DHT pin and the DHT type. Next, create a DHT object
and in the setup section, initialize the DHT sensor using the DHT.begin function. Next,
in the loop section, read the sensor data using the DHT.read temperature function
and display it on the 7 segments. You can also create an alarm clock using the DS3231 or DS1302
RTC module and display the data using the TM1637 module. I will cover that in full details in my
next video. Now, let's have a look at some common errors. Display showing part of the previous data.
You always have to clear the previous value before displaying the new one. Display data
going out of the display or showing partially. Check the position of your display data. These
are the few issues that I came across while playing around with these displays. Do comment
and let me know if you have any more to add to the list. Thanks again for watching this video. I
hope it helps you. If you want to support me, you can subscribe to my channel and watch my
other videos. Thanks. See you again in my next video. Bye now.