8 Seven Segment LED Display with Keys and LEDs using TM1638.

The sketch and library can be downloaded from my GitHub page here

Using the library available from here this board is easy to operate. Connecting the board to an Arduino requires five connections, Vcc to Arduino 5 volts, Gnd to Gnd. STB, CLK and DIO on the display board connect to 7, 9 and 8 on the Arduino.

The library contains a number of examples, but the pins used for Clock, Strobe and Digital Input varies in each example, so I have defined these at the start.


TM1638 8 x Seven Segment Display with Keys and LEDs
Tests some functions
No key pressed displays decimal number
Key 1 pressed displays HEX value
Key 2 pressed displays binary value
Key 3 pressed clears displayed
Key 4 pressed displays a text string

Vcc to Arduino 5 volts
Gnd to Arduino Gnd
Strobe, Digital I/O and clock are defined in the sketch

#include <TM1638.h>
const int strobe = 7;
const int clock = 9;
const int data = 8;
int dots = 0x0; // display all decimal points, value in hexadecimal
int leds = 0xFF; // mask to display LEDS
byte keys; // key value
double number; // number to display
// define a module
TM1638 module(data, clock, strobe);

void setup() {
module.clearDisplay(); // clear the display
number = 12345678; // decimal number

void loop() {
// display a number
case 0:
module.setDisplayToDecNumber(number, dots);

case 1:
module.setDisplayToHexNumber(number, dots);

case 2:
module.setDisplayToBinNumber(number, dots);

case 4:
module.clearDisplay(); // clear the display

case 8:
module.setDisplayToString("testing ");

case 16:


case 32:


case 64:


case 128:




// get a key press

void getKeyPressed(){
keys = module.getButtons();
// light the LED
module.setLEDs(keys & leds);


One thought on “8 Seven Segment LED Display with Keys and LEDs using TM1638.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: