4-Digit 7 Segment Display Arduino Code
Introduction
A 4-digit 7-segment display is a common type of display that can be used to display numeric information in electronic projects. This display consists of four individual 7-segment LEDs, each of which can display numbers from 0 to 9. By lighting up the different segments in various combinations, it’s possible to display any number from 0000 to 9999. In this article, we’ll be discussing how to code an Arduino to display numbers on a 4-digit 7-segment display.
Arduino Code
Today We’ll learn how to create a countdown timer using a 4 Digit 7-Segment Display that can be reset with a push button. In this tutorial we listed the required materials, the wiring diagram, and source code that was used to program the 4 Digit 7-Segment Display.
To follow this tutorial you will require the following materials:
- 4 Digit 7-Segment Display (In our case 5641AS)
- Connecting Wires
- Connecting wires are used to connect the 4 Digit 7-Segment Display to the Arduino and to connect the Push Button to the Arduino
- 1 wire for the option to include decimal points on your 4 Digit 7-Segment Display
- Arduino Uno and its USB Cable
- Push Button
In order to wire 4 Digit 7-Segment Display we first need to identify pins of the 4 Digit 7-Segment Display and their function.

After identifying the pins of the 4 Digit 7-Segment Display, we can summarize the function of each pin and their function in the form of a table. First column shows the pin number on the 4 Digit 7-Segment Display the second column shows the light variable and the third column shows the pin number on the Arduino to which respective pin is going to connect. place the 4 Digit 7-Segement and the Push Button on breadboard and wire the 4 different digit pins to the first four pins to the Arduino as shown by the chart.
7 segment Pin Number | 7 segment Light Variable | Arduino Pin Number |
Pin 11 | A | 12 |
Pin 7 | B | 10 |
Pin 4 | C | 8 |
Pin 2 | D | 7 |
Pin 1 | E | 6 |
Pin 10 | F | 11 |
Pin 5 | G | 9 |
Pin 9 | Digit 1 | 1 |
Pin 8 | Digit 2 | 2 |
Pin 6 | Digit 3 | 3 |
Pin 12 | Digit 4 | 4 |
Next we need to wire other pins of the 4 Digit 7-Segment Display to Arduino according to the chart. Next, the remaining pins of the Arduino (13 and 5) will be connected to the Push Button. These wires will be on the same side as the push button.
Here is the source code for the 4 Digit 7-Segment Display.
This code shows the different pins their function and how they should be wired to the Arduino. It also shows the lines of the code which you can change and customize for example the starting time of the count down and the time at which the timer is reset after the reset button is pressed.
Note: time is mentioned in milliseconds. In order to achieve 1 second, you need to mention 1000 in the code.
1 second = 1000 ms
If you followed the guidelines the timer should work as charm. When the reset button is pressed, all four digits will display digit 0.
Conclusion
In conclusion, using a 4-digit 7-segment display with an Arduino is a great way to add visual feedback to your electronic projects. By following the steps outlined in this article, you can create your own code to display numbers on the display. With a little bit of creativity, you can use this display to create a variety of different visual effects and animations. We hope that this article has been helpful and has inspired you to start experimenting with 4-digit 7-segment displays in your own projects.