Arduino and TM1638 LED Display Modules


The purpose of this article is to demonstrate the use of some interesting LED display modules I discovered on the dealextreme website, for example:

They contain eight 7-segment red LED digits, eight red/green LEDs and also eight buttons for user input. You can get red or green display models. The units can also be daisy-chained, allowing up to five at once, and a short cable is included with each module, as well as some short spacers and bolts, such as:

The spaces are just long enough to raise the PCB above a surface, however to mount the boards anywhere useful you would need longer ones. You may also want to remove the IDC sockets if you want to mount the module close to the surface of a panel. This would be a simple desoldering task as they are through-hole sockets:

The board is controlled by a TM1638 IC:

This part seems to be a domestic Chinese product from “Titan Micro Electronics“. After a quick search the TM1638 isn’t available from Digikey, Mouser or the element14 group… so if anyone has a lead on a low-volume, reliable supplier for these – please leave a comment below. However here is a link to the data sheet – thanks Marc!.

Getting Started

Now to make things happen…

Hardware – Connection to an Arduino-compatible board (or other MCU) is quite simple. The pinouts are shown on the rear of the PCB, and match the fitting on the ribbon cable. If you look at the end of the cable as such:

The top-right hole is pin one, with the top-left being pin two, the bottom-right pin nine and bottom-left pin ten. Therefore the pinouts are:

  1. Vcc (5V)
  2. GND
  3. CLK
  4. DIO
  5. STB1
  6. STB2
  7. STB3
  8. STB4
  9. STB5
  10. not connected

For Arduino use, pins 1~4 are the minimum necessary to use one module. Each additional module will require another digital pin connected to STB2, STB3, etc. More on this later. Please note that each module set to full brightness with every LED on consumes 127mA, so it would be wise to use external power with more than one module and other connections with Arduino boards. After spending some time with the module, I made a quick shield with an IDC header to make connection somewhat easier:

Software –  download and install the T1638 library from here. Thanks and kudos to rjbatista at gmail dot com for the library. Initialising modules in the sketch is simple. Include the library with:

then use one of the following for each module:

x is  the Arduino digital pin connected to the module cable pin 4, y is the Arduino digital pin connected to the module cable pin 3, and z is the strobe pin. So if you had one module with data, clock and strobe connected to pins 8, 7,  and 6 you would use:

If you had two modules, with module one’s strobe connected to Arduino digital 6, and module two’s strobe connected to digital 5, you would use:

and so on for more modules.  Now to control the display…

The bi-colour LEDs

Controlling the red/green LEDs is easy. For reference they are numbered zero to seven from left to right. To turn on or off a single LED, use the following:

Using the method above may be simple it is somewhat inefficient. A better way is to address all of the LEDs in one statement. To do this we send two bytes of data in hexadecimal to the display. The MSB (most significant byte) consists of eight bits, each representing one green LED being on (1) or off (0). The LSB (least significant byte) represents the red LEDs.

An easy way to determine the hexadecimal value to control the LEDs is simple, image you have one row of LEDs – the first eight being green and the second eight being red.  Set each digit to 1 for on and 0 for off. The convert the two binary numbers to hexadecimal and use this function:

Where green is the hexadecimal number for the green LEDs and red is the hexadecimal number for the red LEDs. For example, to turn on the first three LEDs as red, and the last three as green, the binary representation will be:

00000111 11100000 which in hexadecimal is E007. So we would use:

which produces the following:

The 7-segment display

To clear the numeric display (but not the LEDs below), simply use:

or to turn on every segment AND all the LEDs, use the following

To display decimal numbers, use the function:

where a is the integer, b is the position for the decimal point (0 for none, 1 for digit 8, 2, for digit 7, 4 for digit 6, 8 for digit 4, etc), and the last parameter (true/false) turns on or off leading zeros. The following sketch demonstrates the use of this function:

and the results:

One of the most interesting features is the ability to scroll text across one or more displays. To do so doesn’t really need an explanation as the included demonstration sketch:

included with the TM1638 library is easily followed. Just insert your text in the const char string[], ensure that the module(s) are wired according to the module definition at the start of the sketch and you’re set. To see the available characters, visit the function page. Note that the display is only seven-segments, so some characters may not look perfect, but in context will give you a good idea – for example:

Finally, you can also individually address each segment of each digit. Consider the contents of this array:

each element represents digits 1~8. The value of each element determines which segment of the digit turns on. For segments a~f, dp the values are 1,2,4,6,16,32,64,128. So the results of using the array above in the following function:

will be:

Naturally you can combine values for each digit to create your own characters, symbols, etcetera. For example, using the following values:

we created:

The buttons

The values of the buttons are returned as a byte value from the function:

As there are eight buttons, each one represents one bit of a binary number that is returned as a byte. The button on the left returns decimal one, and the right returns 128. It can also return simultaneous presses, so pressing buttons one and eight returns 129. Consider the following sketch, which returns the values of the button presses in decimal form, then displays the value:

and the results:

Update – 21/05/2012

A reader from Brazil has used one of the modules as part of a racing simulator – read more about it here, and view his demonstration below.

Update – 08/02/2013

Great tutorial on using these with a Raspberry Pi.

These display boards were a random, successful find. When ordering from dealextreme, do so knowing that your order may take several weeks to arrive as they are not the fastest of online retailers; and your order may be coming from mainland China which can slow things down somewhat. Otherwise the modules work well and considering the minimal I/O and code requirements, are a very good deal.

Have fun and keep checking into Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

The following two tabs change content below.

John Boxall

Person. Founder and original author for VK3FJBX

34 thoughts on “Arduino and TM1638 LED Display Modules

  1. Richard

    The IDC placement is something that really baffles me with these displays, as does the lack of allignment of the LEDs and buttons.

    But as a readable alternative to a 16×2 LCD and some basic input in a cheap device they are great.

    I tried desoldering the header and putting one on the back, but then the pin order was totally messed up and I seemed to toast my display.

      1. John Boxall

        Mmm gadgets…
        Note to Australians – importation and use of GSM boosters or jamming devices is illegal and under the Radiocommunications Act 1992, the regulator ACMA can take action against those that use jammers. Penalties include up to two years imprisonment or a fine of up to $165,000. Telstra and the ACMA can and do track down users of GSM boosters.

    1. John Boxall

      Yes the sockets are a puzzle. Will be removing them from one board for a forthcoming project. Thanks for pointing out that other device – I will now order some. Thanks!

  2. hlantz

    Excellent timing; my three modules finally arrived after what seemed forever (but probably only was about a month) last week and I was hoping to get a look at them soon!

  3. Steve

    Thanks for the heads up John. I bought 5 of these modules thanks to this post for a project where I’ll have them display the pressures from 5 off 0 – 5V pressure sensors ( 0.5V – 4.5V) (4.5V short circuit fault monitoring).Delivery wasn’t too bad for me, 18 calendar days from payment to delivery.

    One of Ricardo’s libraries that could come in handy is the inverse one. For mounting displays vertically on a panel. I took a screen shot.

    1. John Boxall

      Very well done Steve, kudos. Stuff from DX is taking a little longer that usual due to the fact they sell mobile phone jammers… so I think customs is pulling almost all of their parcels at the moment. Waiting for my 16-digit and matrix displays…

  4. studzin

    I ordered tm1640 and tm1638 from zizhenfu at, and they work great. I paid by paypal tm1638 $1.66 and tm1640 $1.7 with shipping.

  5. alex

    good all
    e-bay has them on offer for app, one dollar american +postage, p.s anybody got English data sheet . having problems downloading one

  6. alex

    good day all
    update found board schematic sheet for 1638.can studzin supply information on supplier for 1638

    thanks alex

  7. sandy

    studzin has actually left the paypal acc. name her e-Bay address is whymin_hvw5726pj

    [email protected]

    should this link go down, all i done was just e-mail some Chinese suppliers from e-bay and told them the part i required, and the rest is history
    sandy. (ps. great site keep up good work john)

  8. sandy

    hell0 folks re tm1638 studzin has actually left the pay- pal ref. the e-mail address

    [email protected]
    if this link should be broken all i done was e-mail several Chinese websites with the relevant question, ( part No) and the rest is history as they say. ps. great site john keep up good work.


  9. BrunoG

    Hi, I want to make a binary counter with the leds but I have problems with the “0x…” can anybody help me?

      1. djdance

        Hello once again. This guy made a scheme on the TM1638, but can I use the dealextreme’s LED Display Module, described in this article? I have this one, but it will not sustain current \ voltage of Big Digits. So what I have to solder to the Led Display, it will withstand? 🙂

  10. Sebastian Schaffrath

    I tested this at the same way and it worked not properly.

    I hooked it up to an Breadboard Power Supply that Outputs +5v DC.
    VCC and GND to the Power Supply and DIO, CLK, STB0 to the Arduino.
    When i power the Module from the Arduino himself it works fine…

    But when i use the VCC and GND from the Power Supply it will not work. The 7-digit display lights then in a curious way up.

    What is when i connect the Power Supply GND and the Arduino GND on the GND Pin of the Module?

    Thanks for the help 🙂

  11. Michael Cosgrove

    Hey John, thanks for the tutorial. I just started playing with the Arduino and this got my jy-lkm1638 up and running on my Mega R3 in just a few minutes. The only thing that slowed me down a tad is the line “For Arduino use, pins 1~4 are the minimum necessary to use one module”. I don’t know if it’s just me, but my jy-lkm1638 was dead until I hooked up pin 5 (STB1) as well. If this is some kind of “chip select” for this board it makes sense that STB1 has to be hooked up. But other than a minor quibble I was glad to find your tutorial. I’m also glad Ricardo posted his library for everyone to use. I think it’s great the community is coming together to share what they figure out and help everyone that wants to learn this stuff. –Michael


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.