Example Code for Arduino-Display Numbers via Serial
Last revision 2025/12/16
This article provides example code and step-by-step instructions for using Arduino to display numbers on a 3-Wire LED module via serial communication, including hardware setup, wiring diagrams, and software preparation.
Hardware Preparation
- 3-Wire LED Module 8 Digital (DFR0090): 1 piece, Purchase Link
- Interface Shield For Arduino (SKU: DFR0074): 1 piece, Purchase Link
- IDC6 cables: 1 piece (for linking the module to the interface shield)
Software Preparation
- Arduino IDE: Download Link (version 1.8.x or later)
Wiring Diagram
This module is linked to interface shield via IDC6 cables. Make sure that the first input is plugged onto "Input" socket of the module. The "Output" socket is linked to the second module "Input socket".

Other Preparation Work
Upload the sketch above.
Link "Input" socket for LED Module to "shiftout" socket of interface shield.
Sample Code
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 3;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 9;
byte Tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
Serial.println("reset");
}
void loop() {
if (Serial.available() > 0) {
// ASCII '0' through '9' characters are
// represented by the values 48 through 57.
// so if the user types a number from 0 through 9 in ASCII,
// you can subtract 48 to get the actual value:
int bitToSet = Serial.read() - 48;
// write to the shift register with the correct bit set high:
digitalWrite(latchPin, LOW);
// shift the bits out:
shiftOut(dataPin, clockPin, MSBFIRST, Tab[bitToSet]);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}
}
Result
Open serial monitor, and type "12345678". The LED module should display "87654321".
Additional Information
The Arrays Tab contain numbers encoded as HEX which tells the LED Module which segments to light.
For example the first element of Tab =0xC0 which is the number 0.
0=0xC0
0xC0=11000000
The zeros and ones represent the light(0's) segments and the off(1's) segments from the 7 segment display.
P G F E D C B A
A
--
F|__|B
E|G |C
-- .P
D
So in this case P and G will be off. which makes 0.
Seven Segment display Wiki Pattern tables are used to reference display patterns.
Ascii tables are used to see the equivalence. You can see on this table:
DEC CHR
48 0 //This is why we subtract 48 for the first element in the number array
Was this article helpful?
