In the past, we’ve shown how to control an LED matrix with an Arduino. However, if your project only needs to show numbers, you might be better off with a seven-segment numerical display. These displays look like retro style digital alarm clocks and can display numbers using just seven LEDs. This guide will show you how.
Seven-segment displays feature an array of seven LEDs, in the shape of an 8, that can be individually lit up to display different numbers (or, in some cases, letters). Often there’s an eight LED that can function as a decimal place. Some modules come with multiple seven-segment arrangements. For example, a four-digit seven-segment display could be used as a clock.
To keep things simple, we’ll focus on just one digit for this guide. Seven-segment displays can take one of two forms: either a common anode or common cathode configuration. In a common anode configuration, all LEDs are connected to power, and each individual LED is controlled by selectively connecting them to ground. In the common cathode, this is reversed: each LED is connected to ground, and power is controlled on an individual basis.
The exact configuration of your display may vary, so look for markings on your module and find the specification sheet to confirm which configuration your display is wired for and which pins correspond to which LED. For this guide, we’ll be using a 5611AS, which uses a common cathode configuration.
To make the code work, you’ll also need the SevSeg library, found here on Github. Download the .zip file, then in your IDE, navigate to Sketch > Include library > Add .ZIP library… and select the SevSeg library. Now, you’ll be able to include it in your sketches.
Like the LED matrix, this project will require quite a bit of wiring and resistors. Since each LED needs its own resistor to avoid burning out the LEDs, make sure you have plenty of resistors handy. For the entire project, here’s what you’ll need:
Arduino Uno | ![]() |
Seven-segment LED display | ![]() |
Wires | ![]() |
8x 220 ohm resistor | ![]() |
Breadboard | ![]() |
USB cable | ![]() |
Arduino IDE | ![]() |
Since the cabling here can get a bit bulky, make sure you have enough space on your breadboard for all the wiring and resistors you’ll need. Once you have everything, move onto the next section.
Since we’re using the SevSeg library, the code for this project will be fairly simple. First, here’s the full code you can paste into your IDE and upload:
#include “SevSeg.h”
SevSeg digit;
void setup(){
byte numDigits = 1;
byte digitPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
byte segmentPins[] = {6, 5, 2, 3, 4, 7, 8, 9};
bool resistorsOnSegments = true;
byte hardwareConfig = COMMON_CATHODE;
digit.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
digit.setBrightness(90);
}
void loop(){
for (int i = 0;i < 10;i++){
digit.setNumber(i);
digit.refreshDisplay();
delay(1000);
}
}
Next, let’s go through the parts of the code, starting with the top two lines.
#include “SevSeg.h”
SevSeg digit;
The first line here includes the SevSeg.h library, allowing you to use all the commands included in this library. The second creates an object of the SevSeg type, in this case, called “digit,” that will be used to control your display. For modules with more than one digit, you can add more for each digit and give them unique names.
void setup(){
byte numDigits = 1;
byte digitPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
byte segmentPins[] = {6, 5, 2, 3, 4, 7, 8, 9};
bool resistorsOnSegments = true;
byte hardwareConfig = COMMON_CATHODE;
digit.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
digit.setBrightness(90);
}
In this section, we’ll set up the display. Most of the work here is being done by the digit.begin() function. Per the SevSeg library documentation, this command is used to tell the Arduino what traits your display has, like the number of digits (in this case, one), which Arduino pins you’re using to address the display (pins 2-9), and whether there are resistors on the circuits. The segmentPins array identifies which Arduino pins correspond to which segment, from A through G and ending with the decimal point. Refer to your display’s documentation to determine which segments correspond with which pins.
Each of these are assigned to a variable first—which makes it easier to expand the sketch later—before being passed to the digit.begin function. Finally, digit.setBrightness tells the sketch how bright to light the LED segments.
void loop(){
for (int i = 0;i < 10;i++){
digit.setNumber(i);
digit.refreshDisplay();
delay(1000);
}
}
In the loop() section, we’ll run the display through a loop that will count from 0 to 9 and then start over. For each iteration of the loop, the variable i will be used in the digit.setNumber command to tell the display which number to show. The SevSeg library automatically interprets this to send the correct signal to the correct LED segments (as long as you’ve assigned them correctly in the previous section). Then, digit.refreshDisplay is called to tell the display to update with the new number.
Finally, we add a delay(1000) command to keep each number shown for one second.
Connecting the display here involves a lot of wiring, but it’s not as complex as it looks. Again, we’ll use the 5611AS, but if you’re using a different model, check the specs for your display. Starting on the bottom of the display (the side with the decimal LED), from left to right, the pins are 1 through 5. On the top, the pins from left to right are 10 through 6. You can think of this as starting on the bottom left corner with pin 1 and counting to pin 10 by wrapping around the display counterclockwise.
For this display, you’ll need to run eight circuits from the Arduino to pins on the display, with a 220 ohm resistor in between. Each LED needs a resistor to stop it from burning out. While you could add a single, higher resistance resistor after the common ground pins, this would result in different numbers appearing at different levels of brightness, depending on how many segments are lit up.
For each of the following, use a breadboard to add a resistor in the circuit in between the Arduino and the display, connecting the following pins on the Arduino to their corresponding pins on the display:
● Connect Arduino pin 2 to display pin 4
● Connect Arduino pin 3 to display pin 2
● Connect Arduino pin 4 to display pin 1
● Connect Arduino pin 5 to display pin 6
● Connect Arduino pin 6 to display pin 7
● Connect Arduino pin 7 to display pin 9
● Connect Arduino pin 8 to display pin 10
● Connect Arduino pin 9 to display pin 5
Finally, the two middle pins on each side of the display—pins 3 and 8—should be connected to GND on the Arduino. Once the whole display is wired up, you can upload the code and turn it on. Try changing the code to show different numbers to see your display in action.