Display Two Digit Number On 7 Segment Using Arduino » PIJA Ed
Maybe your like
Table of Contents
- TABLE : DISPLAY SEGMENT MATRIX WITHOUT DP ON
- CIRCUIT DIAGRAM – TWO DIGIT NUMBER ON 7 SEGMENT USING ARDUINO
- PROGRAMMING CODE
HOW TO DISPLAY TWO DIGIT NUMBER ON 7 SEGMENT using Arduino (RECOMMENDED METHOD)
To display two digit number on 7 segment using arduino we need 2 seven segments and 2 shift registers IC 74HC595. Connect pin 9 of 74HC595 (which receives data from arduino) to pin 14 of second shift register. Now we are able to send 2 bytes of data, the first to control the second shift register and second to first shift register. For example number is 82 (see table)
In the previous tutorial working of Shift Register IC 74HC595, includes LSB first and MSB first concept is already discussed. It is important to read this to understand its working.
TABLE : DISPLAY SEGMENT MATRIX WITHOUT DP ON
| Q0 | Q1 | Q2 | Q3 | Q4 | Q5 | Q6 | Q7 | ||
| Segment | A | B | C | D | E | F | G | DP | DECIMAL |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 252 |
| 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 96 |
| 2 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 218 |
| 3 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 242 |
| 4 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 102 |
| 5 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 182 |
| 6 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 190 |
| 7 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 224 |
| 8 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 254 |
| 9 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 246 |
| A | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 238 |
| B | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 62 |
| C | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 156 |
| D | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 122 |
| E | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 158 |
| F | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 142 |
CIRCUIT DIAGRAM – TWO DIGIT NUMBER ON 7 SEGMENT USING ARDUINO

Note that the shift registers latch and clock pins are connected to each other and then to the Arduino. Arduino digital pin 6 connected to shift register ‘1’, and then a ‘pin 9 of shift register 1’ connected to ‘pin 14 of shift register 2’.
To display two digit number on 7 segment using arduino we need 2 seven segments and 2 shift registers IC 74HC595
- If a number is less than 10, then we can just send the number followed by a 0, as the right digit displays the number and the left digit displays 0.
- However, if the number is greater than 9, then we need to determine each digit of the two digit number and send them separately to the shift registers.
To do this, we’ll use the mathematical function modulo. Modulus (%), as 10 / 2 = 5 but 10 % 2 = 0, modulus gives us remainder one more example is 10 % 3 = 1 etc.
PROGRAMMING CODE
#define DATA 6 // connect to pin 14 on the 74HC595 #define LATCH 8 // connect to pin 12 on the 74HC595 #define CLOCK 10 // connect to pin 11 on the 74HC595 // set up the array with the segments for 0 to 9, A to F (from Table 6-2) int data [] = {252, 96, 218, 242, 102, 182, 190, 224, 254, 246, 238, 62, 156, 122, 158, 142}; void setup() { pinMode(LATCH, OUTPUT); pinMode(CLOCK, OUTPUT); pinMode(DATA, OUTPUT); } void loop() { int j; for ( j = 0 ; j < 100 ; j++ ) { displayNumber(j); delay(100); } } void displayNumber(int n) { int left, right = 0; if (n < 10) { digitalWrite(LATCH, LOW); shiftOut(DATA, CLOCK, LSBFIRST, data [n]); shiftOut(DATA, CLOCK, LSBFIRST, 0); digitalWrite(LATCH, HIGH); } else if (n >= 10) { right = n % 10; // remainder of dividing the number to display by 10 left = n / 10; // quotient of dividing the number to display by 10 digitalWrite(LATCH, LOW); shiftOut(DATA, CLOCK, LSBFIRST, data [right]); shiftOut(DATA, CLOCK, LSBFIRST, data [left]); digitalWrite(LATCH, HIGH); } }In void loop() we set up and call the function to display the numbers from 0 to 99.
In the function void displayNumber(int n) it checks if the number to be displayed is less than or greater than 10.
- If less than 10, it sends the data for the number and a blank digit to the shift registers.
However, if the number is greater than 10, then the function uses modulo and division to separate the digits and then sends them to the shift registers separately.
READ NEXT 4X3 KEYPAD WITH ARDUINO
4.5 4 votes Article RatingTag » Arduino 74hc595 7 Segment 2 Digit
-
74HC595 Seven Segment 2 Digits LED Display With Decimal Points ...
-
Help With - 2 Digit 7 Segment Display And 2 74hc595 - Arduino Forum
-
Controlling 10-pin 2-digit 7-segment Display With Shift Register.
-
How To Use 74HC595 Shift Register With Arduino. Building Custom ...
-
Arduino Powered 7 Seg LED Display Using Shift Registers
-
How To Use 2 Digit LED Display With Arduino Using 74HC595
-
Control 7-Segment Display With 74HC595 Shift Register - MathWorks
-
Arduino And 2-Digit Seven Segment Module
-
Driving 7 Segments Using Arduino Shift And Register 74HC595
-
How To Interface74HC595 IC With 7- Segment & Arduino
-
Display Module 7-Segment 2 Digit With 74HC595 - GRobotronics
-
Robojax 74HC595 Driving 2 Digit 0.5in Seven Segment Display For ...
-
4 Digits, 7 Segment Display Module Using The 74HC595 Shift Register ...