374_TM1637. 6-DIGIT 7-SEGMENT DISPLAY AND 16-KEY KEYPAD.
Quote from Defran on November 17, 2026, 9:19 pm
The TM1637 is an integrated circuit designed to simultaneously control a 7-segment LED display (up to 6 digits, including decimal points) and a matrix keypad (up to 16 buttons). It communicates with a microcontroller using only two signals: CLK and DIO. The TM1637 internally handles both display multiplexing and keypad scanning, offloading these tasks from the microcontroller (MCU). It is highly popular in projects using Arduino UNO, Nano, and ESP32, as it allows for the control of multiple digits using only two digital signals.
The TM1637 features two sets of outputs:
1. GRID1–GRID6: These select which of the six digits is active.
2. SG1–SG8: These control the seven segments and the decimal point for each digit.
The digits are illuminated sequentially at a speed high enough that they appear to remain lit simultaneously.Each digit has an 8-bit register. The controller receives the segment patterns, stores them, and maintains the display. The TM1637 allows for the direct connection of up to 16 buttons, without the need for an additional keypad controller.
The operation is as follows:
1. The TM1637 internally scans the SG1–SG8 lines.
2. It checks the K1 and K2 inputs to detect if a button has been pressed (closed).
3. It encodes the detected key.
4. The Arduino requests the code via the CLK and DIO signals.
5. The TM1637 returns the value corresponding to the pressed key.Main Commands:
0x40 Data write with automatic address increment
0x44 Write to a fixed address
0x42 Read keypad
0xC0–0xC5 Addresses for the six digits
0x80 Turn off display
0x88–0x8F Turn on display and adjust brightness
0x42 When the Arduino sends this command, the TM1637 returns a byte containing information about the detected key press. If no key is pressed, it returns 0xFF. Communication is bidirectional via the DIO pin, but it is not standard I²C.SCHEMATIC.
Here, we use a 6-digit, 7-segment display and a 16-key keypad. This device allows for data control and visualization in any Arduino project. A group of 6 LEDs indicates which displays are active. Pressing keys will show the number of the pressed key; the cycle repeats, or everything is cleared when the RESET button is pressed. SimulIDE version 1.2 or higher. Select ONE as "Main MCU" if it does not start up correctly.
SOFTWARE:
Here, we provide the TM1637 the "as" code and the Arduino program "ino" code.
// TM1637 6 DIGITS AND KEYBOARD. DEFRAN26A // USE AS MAIN MCU AND RELOAD UNO IF NEEDED. #define CLK 9 #define DIO 8 #define RESET 3 byte teclaAnterior = 0xFF; byte teclaEstable = 0xFF; byte posicion = 0; bool resetAnterior = false; unsigned long tiempoTecla = 0; const byte leds[6] = {11, 12, 13, 14, 15, 16}; // LEDs D11-D16 const byte codigos[16] = // Codigos del teclado TM1637s { 0xF7, 0xEF, 0xF6, 0xEE, 0xF5, 0xED, 0xF4, 0xEC, 0xF3, 0xEB, 0xF2, 0xEA, 0xF1, 0xE9, 0xF0, 0xE8 }; const char teclas[17] = "041526378C9DAEBF"; // Correspondencia byte datos[6] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40}; // Guiones iniciales void setup() { pinMode(CLK, OUTPUT); digitalWrite(CLK, HIGH); dioHigh(); pinMode(RESET, INPUT_PULLUP); // RESET activo en LOW for (byte i=0; i<6; i++) { digitalWrite(leds[i], LOW); // LEDs apagados al inicio pinMode(leds[i], OUTPUT); } mostrarGuiones(); // Display inicial ------ } void loop() { bool resetActual = digitalRead(RESET) == LOW; if (resetActual) { if (!resetAnterior) { mostrarGuiones(); // Borrar displays y apagar LEDs teclaAnterior = 0xFF; teclaEstable = 0xFF; } resetAnterior = true; return; // Bloquear teclado durante RESET } resetAnterior = false; byte codigo = leerTecla(); if (codigo != teclaAnterior) { teclaAnterior = codigo; tiempoTecla = millis(); // Inicio antirrebote } if (millis() - tiempoTecla >= 30 && codigo != teclaEstable) { teclaEstable = codigo; if (codigo != 0xFF) { for (byte i=0; i<16; i++) { if (codigo == codigos[i]) {escribir(teclas[i]); break;} // Siguiente caracter } } } delay(5); } byte segmento(char c) { switch (c) { case '0': return 0x3F; case '1': return 0x06; case '2': return 0x5B; case '3': return 0x4F; case '4': return 0x66; case '5': return 0x6D; case '6': return 0x7D; case '7': return 0x27; case '8': return 0x7F; case '9': return 0x6F; case 'A': return 0x77; case 'B': return 0x7C; case 'C': return 0x39; case 'D': return 0x5E; case 'E': return 0x79; case 'F': return 0x71; default: return 0x40; // Guion } } void dioLow() { digitalWrite(DIO, LOW); pinMode(DIO, OUTPUT); } void dioHigh() { pinMode(DIO, INPUT_PULLUP); } void inicio() { dioHigh(); digitalWrite(CLK, HIGH); delayMicroseconds(5); dioLow(); delayMicroseconds(5); digitalWrite(CLK, LOW); } void fin() { digitalWrite(CLK, LOW); dioLow(); delayMicroseconds(5); digitalWrite(CLK, HIGH); delayMicroseconds(5); dioHigh(); } void enviar(byte dato) { for (byte i=0; i<8; i++) { digitalWrite(CLK, LOW); if (dato & 1) dioHigh(); // Bit a 1 else dioLow(); // Bit a 0 delayMicroseconds(5); digitalWrite(CLK, HIGH); delayMicroseconds(5); dato >>= 1; } digitalWrite(CLK, LOW); dioHigh(); // Liberar DIO para ACK delayMicroseconds(5); digitalWrite(CLK, HIGH); delayMicroseconds(5); digitalWrite(CLK, LOW); } byte recibir() { byte dato = 0; dioHigh(); for (byte i=0; i<8; i++) { digitalWrite(CLK, LOW); delayMicroseconds(5); digitalWrite(CLK, HIGH); delayMicroseconds(5); if (digitalRead(DIO)) dato |= (1 << i); // Leer bit } digitalWrite(CLK, LOW); dioHigh(); delayMicroseconds(5); digitalWrite(CLK, HIGH); delayMicroseconds(5); digitalWrite(CLK, LOW); return dato; } void actualizarDisplay() { inicio(); enviar(0x40); // Escritura automatica fin(); inicio(); enviar(0xC0); // Primera posicion for (byte i=0; i<6; i++) enviar(datos[i]); // Seis digitos fin(); inicio(); enviar(0x8D); // Display encendido: 88-8F fin(); } void actualizarLeds() { for (byte i=0; i<6; i++) digitalWrite(leds[i], datos[i] == 0x40 ? LOW : HIGH); // Guion=OFF } void mostrarGuiones() { for (byte i=0; i<6; i++) datos[i] = 0x40; // Seis guiones posicion = 0; actualizarDisplay(); actualizarLeds(); } void escribir(char caracter) { if (posicion >= 6) mostrarGuiones(); // Reinicio en septima tecla datos[posicion] = segmento(caracter); // Escribir caracter posicion++; actualizarDisplay(); actualizarLeds(); } byte leerTecla() { inicio(); enviar(0x42); // Lectura del teclado byte dato = recibir(); fin(); return dato; }PROVIDED FILES:
The following ZIP file includes: the schematic, the "ino" program, the "exe" file, and all subcircuits used (located in the 'data' directory).P. de Francisco.

The TM1637 is an integrated circuit designed to simultaneously control a 7-segment LED display (up to 6 digits, including decimal points) and a matrix keypad (up to 16 buttons). It communicates with a microcontroller using only two signals: CLK and DIO. The TM1637 internally handles both display multiplexing and keypad scanning, offloading these tasks from the microcontroller (MCU). It is highly popular in projects using Arduino UNO, Nano, and ESP32, as it allows for the control of multiple digits using only two digital signals.
The TM1637 features two sets of outputs:
1. GRID1–GRID6: These select which of the six digits is active.
2. SG1–SG8: These control the seven segments and the decimal point for each digit.
The digits are illuminated sequentially at a speed high enough that they appear to remain lit simultaneously.
Each digit has an 8-bit register. The controller receives the segment patterns, stores them, and maintains the display. The TM1637 allows for the direct connection of up to 16 buttons, without the need for an additional keypad controller.
The operation is as follows:
1. The TM1637 internally scans the SG1–SG8 lines.
2. It checks the K1 and K2 inputs to detect if a button has been pressed (closed).
3. It encodes the detected key.
4. The Arduino requests the code via the CLK and DIO signals.
5. The TM1637 returns the value corresponding to the pressed key.
Main Commands:
0x40 Data write with automatic address increment
0x44 Write to a fixed address
0x42 Read keypad
0xC0–0xC5 Addresses for the six digits
0x80 Turn off display
0x88–0x8F Turn on display and adjust brightness
0x42 When the Arduino sends this command, the TM1637 returns a byte containing information about the detected key press. If no key is pressed, it returns 0xFF. Communication is bidirectional via the DIO pin, but it is not standard I²C.
SCHEMATIC.
Here, we use a 6-digit, 7-segment display and a 16-key keypad. This device allows for data control and visualization in any Arduino project. A group of 6 LEDs indicates which displays are active. Pressing keys will show the number of the pressed key; the cycle repeats, or everything is cleared when the RESET button is pressed. SimulIDE version 1.2 or higher. Select ONE as "Main MCU" if it does not start up correctly.
SOFTWARE:
Here, we provide the TM1637 the "as" code and the Arduino program "ino" code.
// TM1637 6 DIGITS AND KEYBOARD. DEFRAN26A
// USE AS MAIN MCU AND RELOAD UNO IF NEEDED.
#define CLK 9
#define DIO 8
#define RESET 3
byte teclaAnterior = 0xFF;
byte teclaEstable = 0xFF;
byte posicion = 0;
bool resetAnterior = false;
unsigned long tiempoTecla = 0;
const byte leds[6] = {11, 12, 13, 14, 15, 16}; // LEDs D11-D16
const byte codigos[16] = // Codigos del teclado TM1637s
{
0xF7, 0xEF, 0xF6, 0xEE,
0xF5, 0xED, 0xF4, 0xEC,
0xF3, 0xEB, 0xF2, 0xEA,
0xF1, 0xE9, 0xF0, 0xE8
};
const char teclas[17] = "041526378C9DAEBF"; // Correspondencia
byte datos[6] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40}; // Guiones iniciales
void setup()
{
pinMode(CLK, OUTPUT);
digitalWrite(CLK, HIGH);
dioHigh();
pinMode(RESET, INPUT_PULLUP); // RESET activo en LOW
for (byte i=0; i<6; i++)
{
digitalWrite(leds[i], LOW); // LEDs apagados al inicio
pinMode(leds[i], OUTPUT);
}
mostrarGuiones(); // Display inicial ------
}
void loop()
{
bool resetActual = digitalRead(RESET) == LOW;
if (resetActual)
{
if (!resetAnterior)
{
mostrarGuiones(); // Borrar displays y apagar LEDs
teclaAnterior = 0xFF;
teclaEstable = 0xFF;
}
resetAnterior = true;
return; // Bloquear teclado durante RESET
}
resetAnterior = false;
byte codigo = leerTecla();
if (codigo != teclaAnterior)
{
teclaAnterior = codigo;
tiempoTecla = millis(); // Inicio antirrebote
}
if (millis() - tiempoTecla >= 30 && codigo != teclaEstable)
{
teclaEstable = codigo;
if (codigo != 0xFF)
{
for (byte i=0; i<16; i++)
{
if (codigo == codigos[i]) {escribir(teclas[i]); break;} // Siguiente caracter
}
}
}
delay(5);
}
byte segmento(char c)
{
switch (c)
{
case '0': return 0x3F;
case '1': return 0x06;
case '2': return 0x5B;
case '3': return 0x4F;
case '4': return 0x66;
case '5': return 0x6D;
case '6': return 0x7D;
case '7': return 0x27;
case '8': return 0x7F;
case '9': return 0x6F;
case 'A': return 0x77;
case 'B': return 0x7C;
case 'C': return 0x39;
case 'D': return 0x5E;
case 'E': return 0x79;
case 'F': return 0x71;
default: return 0x40; // Guion
}
}
void dioLow()
{
digitalWrite(DIO, LOW);
pinMode(DIO, OUTPUT);
}
void dioHigh()
{
pinMode(DIO, INPUT_PULLUP);
}
void inicio()
{
dioHigh();
digitalWrite(CLK, HIGH);
delayMicroseconds(5);
dioLow();
delayMicroseconds(5);
digitalWrite(CLK, LOW);
}
void fin()
{
digitalWrite(CLK, LOW);
dioLow();
delayMicroseconds(5);
digitalWrite(CLK, HIGH);
delayMicroseconds(5);
dioHigh();
}
void enviar(byte dato)
{
for (byte i=0; i<8; i++)
{
digitalWrite(CLK, LOW);
if (dato & 1) dioHigh(); // Bit a 1
else dioLow(); // Bit a 0
delayMicroseconds(5);
digitalWrite(CLK, HIGH);
delayMicroseconds(5);
dato >>= 1;
}
digitalWrite(CLK, LOW);
dioHigh(); // Liberar DIO para ACK
delayMicroseconds(5);
digitalWrite(CLK, HIGH);
delayMicroseconds(5);
digitalWrite(CLK, LOW);
}
byte recibir()
{
byte dato = 0;
dioHigh();
for (byte i=0; i<8; i++)
{
digitalWrite(CLK, LOW);
delayMicroseconds(5);
digitalWrite(CLK, HIGH);
delayMicroseconds(5);
if (digitalRead(DIO)) dato |= (1 << i); // Leer bit
}
digitalWrite(CLK, LOW);
dioHigh();
delayMicroseconds(5);
digitalWrite(CLK, HIGH);
delayMicroseconds(5);
digitalWrite(CLK, LOW);
return dato;
}
void actualizarDisplay()
{
inicio();
enviar(0x40); // Escritura automatica
fin();
inicio();
enviar(0xC0); // Primera posicion
for (byte i=0; i<6; i++) enviar(datos[i]); // Seis digitos
fin();
inicio();
enviar(0x8D); // Display encendido: 88-8F
fin();
}
void actualizarLeds()
{
for (byte i=0; i<6; i++)
digitalWrite(leds[i], datos[i] == 0x40 ? LOW : HIGH); // Guion=OFF
}
void mostrarGuiones()
{
for (byte i=0; i<6; i++) datos[i] = 0x40; // Seis guiones
posicion = 0;
actualizarDisplay();
actualizarLeds();
}
void escribir(char caracter)
{
if (posicion >= 6) mostrarGuiones(); // Reinicio en septima tecla
datos[posicion] = segmento(caracter); // Escribir caracter
posicion++;
actualizarDisplay();
actualizarLeds();
}
byte leerTecla()
{
inicio();
enviar(0x42); // Lectura del teclado
byte dato = recibir();
fin();
return dato;
}
PROVIDED FILES:
The following ZIP file includes: the schematic, the "ino" program, the "exe" file, and all subcircuits used (located in the 'data' directory).
P. de Francisco.
