Introduction: Using a 4 Digit, 7 Segment Display, With Arduino

Picture of Using a 4 Digit, 7 Segment Display, With Arduino

In this tutorial I will be showing you how to use a 7 segment display with 4 digits using arduino. Some basic things I would like to point out is that this takes up almost all of the digital pins on the arduino uno, leonardo, the boards with 13 digital pins. Most displays have 12 breakout pins that connect either directly to the arduino, or through a resistor. Also, I would like to point out that these displays have no need for Ground, 5V, or 3.3V to be connected. So, let's get started...

Step 1: Materials

Picture of Materials

Using a display of this kind requires almost no materials.

- 4 x 330Ω resistors

- 12 x Male to male jumper wires

- 1 x Arduino

- 1 x breadboard of any size (they don't need the power rails)

No tools are required in order to make a prototype of this design. However, a soldering iron and a pcb board would be needed for a more permanent use.

Step 2: Breadboard Layout

Picture of Breadboard Layout

Just to give you some context i will explain the usage of each pin. 8 out of the 12 pins on the display are used for the 8 segments. There are 7 segments used to form any digit while one controls the decimal point. The other 4 out of the 12 pins control each of the 4 digits on the display. Any pin that has a resistor on it is one of the 4 digit pins, otherwise they are the segment pins.

The above design I created from fritzing in order to show the connection between the display and the arduino. Note the placement of where the resistors are because if you connect the resistor to the wrong pin on the display, either that digit will not work or that segment will not work, FOREVER...


When setting up the circuit switch the yellow and the purple wires (I messed up my circuit diagram).

Step 3: Installing the Library

The library linked below is from the arduino website for easily controlling a display. The link goes to github. If you have never been on github listen carefully, if you have read the next paragraph. When you get onto the website look at the right side of the window and look down until you see, "Download Zip". Click that button and watch it appear in your downloads.

Now you have to load the previously installed library into your libraries folder. If you now how to do this then skip to the next step, otherwise keep on reading. First go into finder and locate the "documents" folder, and open it. Then, locate the "arduino" folder, and open it. Then, locate the libraries folder, and open it. Finally drag and drop the installed library into the just opened libraries folder.

IMPORTANT. If your arduino application was opened and running while you where putting the library into the libraries folder, the arduino won't recognize the library. You just have to quit the application and open it again.

Step 4: The Code

Picture of The Code

The code for actually displaying something is listed below.

#include "SevSeg.h"

SevSeg sevseg; //Initiate a seven segment controller object

void setup() {

byte numDigits = 4;

byte digitPins[] = {2, 3, 4, 5};

byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};

sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);



void loop() {

sevseg.setNumber(3141, 3);

sevseg.refreshDisplay(); // Must run repeatedly


Step 5: The Result

If you connected the display correctly, uploaded the code correctly, and copied the coded just right, then your display should be displaying pi (only 3.141).

If not then, read step six for whatever is happening wrong.

If you did get it right, then I suggest reading going further in step seven.

Step 6: Troubleshooting

Here i have listed two possible things that could have happend to your display that could have messed it up. Sadly only one of the two is fixable.

- Your display is displaying 8888

Do not worry this is the problem that is fixable, just follow these steps

1. Locate in the code " sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins); "


3. Upload the code again

- Your display is displaying 3. 41 or .141 or 3.1 1 or 3.14 without the other 1

Sadly, this problem can either be fixable or not :.(... (thats my crying face)

1. Check your connections and make sure everything IS plugged in and not hanging out

2. Check the schematic again, because you most likely plugged it in wrong

3. Locate the line in void loop where it says to display (3.141, 3) and change 3.141 to 8888 and see if one of the 8 are missing

4. If so one of the wires might have not had a resistor when it should have had one meaning that one of the digits had burned out. You can check this by looking at the back of the display. If you see any black near one of the pins you did overpower one of the digit places. Sadly this IS NOT fixable and you would want to buy another display.

5. If you do not see a black mark anywhere than you switched up wires that can't get overpowered so check the schematic and plug then in correctly and change the code back from 8888 to 3.141.

Step 7: Going Further

One method of using a few pins on the arduino to control multiple LEDs that would otherwise require alot of pin is a tri-state 8 pin shift-register. So instead of directly connecting the 8 segment pins to arduino you can plug them into the shift register and figure out how to do that.

It is just an idea that I came up with but I do not know how to do or if it is even possible with the arduino and the display's library, but hey, food for thought for the curious.

Have fun with your display and i hope you liked this instructable because it is the first that i have actually finished out of the many i have in my drafts.


FritsBee made it! (author)2017-10-21

I made it but there is a simple problem

The middel and the topleft LED's are switched.

I replaced the text 3141 to 0000

And the answer is at the picture.

What did I do wrong?

I doubble checked all the wires.

FritsBee (author)FritsBee2017-10-21

I change the text the the standard 3141 and this what I get.

I seems that only the 0 has problems.. :-(

CésarC129 (author)2017-10-15

Hey man! Cheers from Brazil!

Have someone reported you about some issue with the "A" segment in the first digit?

The digit 2, 3 and 4 are all working properly, but that little A stays always turned on.

Sorry for my bad english, i'm working on this hahaha

rconnard made it! (author)2017-10-12

Great tutorial, after a little wire switching I got it to work.

I also discovered using hex conversion you can display combinations of letters and numbers.

From the ReadMe

"Enter 'true' as the third agument to display the number in hexadecimal representation."


Happy halloween :D

phase1228 (author)rconnard2017-10-14

Hey I assume you too are making ricks portal gun? any chance I could use your code? cheers :)

smarduino (author)2016-11-02

Quick naive question from a beginner, how come there is no GND connection?

because it is magic. Not really. It just pulls certain pins to low and uses them as a cathode, or in the case of common anode, it pulls a certain pin/pins to high and uses it as power. So really, all of the pins are ground and power, and alternate between the two. I think it's called a 'matrix setup'. Damn matrices. Why can't things be simple?

miguelmota made it! (author)2017-09-22

It's alive!!

engej3 (author)2017-09-19

How can I add buttons to change what is shown?

FlorentP4 (author)2017-09-12

Hello and thank you! I would like to know if it's possible to show letters with it (I don't know if it is the same library). Thank you!

voltronsif made it! (author)2017-09-04

I made it! Thanks a lot!

GeorgeB237 (author)2017-06-03

I have it working, thanks. How do i get it to display a variable, like a changing temperature. At the moment it will only display discrete numbers that I have to manually input

MikeNid (author)GeorgeB2372017-09-02

When you have acquired the temperature value you wish to display say called GotTemp and you want to display 2 decimal places then simply sevseg.setNumber(GotTemp, 2). The library will take the value in GotTemp and display it with 2 dec places. you must call sevseg.refreshDisplay() every time in the main loop as this displays 1 digit every call showing dig1 then dig2 etc. and must run frequently enough to give a steady display.


glenzac (author)GeorgeB2372017-07-23

JacquesL30 (author)2017-04-06

When I verify the code, it says all the references to sevseg.something are undefined. How do I fix that?

PradeepT17 (author)JacquesL302017-05-14

Read step 3 again. You have to download library file from the link "" and place it into your arduino library folder. The details are mentioned in step 3..

Deina Underhill made it! (author)2017-04-06

Once I got the pins on the right segments, this worked finest kind! Thanks!

SantiagoS42 (author)2016-11-15

It prints 8888 perfectly, but it has problems showing the 2 and the 3. If i type 2222, 3333, 3141, 2141, 2888, 3888 etc wherever i put the 3 or the 2 it will show a 0 missing the lower left segment

Confirm the problem all digits except 2 and 3 is working fine. Instead 3 showing breaking 0 (see the photo). Maybe this is a problem with library or this model of display not supported by library? Note: i'm using not original Arduino, but chinese copy of this from Aliexpress. Model is: E40361-I-BL-O-W 1043 9

It isn't a problem with the library but it is a problem with the code because when I first got this I had to match the segments to the way that the libraries turned on each segment for each number. So I had to try a whole bunch of variations until I found what I THOUGHT was the right variation. Because you guys are having this problem I am guessing that I found the wrong one.

Shouldn't be to hard to fix. I will try to fix it ASAP which might not be until the weekend (school).

Thanks for informing me of your problems.

I just setup & ran this and I am also having problems with digits 0, 2, & 3. I haven't tried hex mode, so i don't know about it.

0 lights segments a, b, c, d, e, & g. f is off

2 lights segments a, b, d, e, & f. c & g are off

3 lights segments a, b, c, d, & f. e & g are off

The library & sketch I am using I d/l from github this morning. the files in the ZIP are dated 2/22/17 3:50 AM

Since all the other numbers appear correctly I think it points to a software issue, but I don't know enough to give a solution.

DeanR46 (author)Deina Underhill2017-04-05

Your segment pins for 'F' and 'G' are swapped.

Swap the F and G pins numbers that you declare in the segmentPins[] and your display will work. (Alternatively, swap the wires).

Deina Underhill (author)DeanR462017-04-05

worked great, thanks!

chickeneater (author)SantiagoS422016-11-15

"If i type 2222, 3333, 3141, 2141, 2888, 3888 etc wherever i put the 3 or the 2 it will show a 0 missing the lower left segment."

I am a little lost when you say "it will show a 0 missing" because there is no 0 in the numbers 2222, 3333, 3141, etc....

Are you saying that one of the segments are not on?

If so which segment?


I _ I

I _ I

Geocrafter. (author)2017-01-26

Any idea why the decimal poitns wont work for me? tried on multiple displays. Pin #3 is DP and even if i puill it nothing happens. Just dosent light up

Geocrafter. (author)Geocrafter.2017-01-26

and how would i use 2 displays using one arduino?

chickeneater (author)Geocrafter.2017-01-26

Might be something wrong with your arduino board. You can determine if this is the case my light a single led with the pin on the arduino that lights up the decimal point. Use a simple LED blink sketch and if the LED does not light up that means your arduino is broken. If this is the case you can just change the code and the schematic so that it uses a different pin. If it does work then double check the code. Otherwise I have no idea.

Geocrafter. (author)chickeneater2017-01-26

Experimented, only my third decimal point on all my displays work, tried on both my arduinos. Also how would I use multiple displays on my mega?

TimC211 (author)Geocrafter.2017-01-26

I don't know

notapremium (author)2017-01-22

It seems there are some problems with the library. I'm just guessing since I have no related experience. Having tested a few number combinations in which either 3.141or 8888 was presented as expected, however, any combinations in term of 008X wouldn't be verified by IDE(windows), the error message is "invalid digit "8" in octal constant". Also, there are largely chances getting incorrect display when set the first digit to "0". For example, the number 1.037 can be displayed exactly, but 0137 or 0037 can't.

GiannisK20 (author)2016-11-06

Helloo ! I do not own 330Ohm resistors.. i only have 220Ohm , 1k Ohm and 10k Ohm ! should any of them work? #Beginners_question

220 should be fine, I've used 220 before #I'mAnElectronicEngineer

Yeah I agree, 220Ω are fine just brighter i think.

genuino (author)2016-11-02

Quick naive question from a beginner, how come there is no GND connection?

SebbithecoolH (author)2016-08-28

AWESOME!!!! worked on my first try!

Floxyf (author)2016-06-13

In the 2nd step (Breadboard Layout) i noticed you have used 5 resistors now in 1st step (Materials) you told us that we will need 4x 330ohm resistors did you make a mistake in the 1st step (Materials) or in the 2nd step (Breadboard Layout)?

Floxyf (author)Floxyf2016-06-13

It's hiden in between pin 2 and 6

chickeneater (author)Floxyf2016-06-13

oh no. I didn't even see that there. I must have put it there and forgot to take it out. There are only supposed to be the 4 resistors. Thanks for telling me.

cliptwings (author)2016-06-10

Thank you for the excellent demonstration. However, when I used the fritzing schematic to set up my breadboard layout, the display showed one segment out of place. I discovered that the display's number 5 pin (segment g) and number 10 pin (segment f) were switched. When I connected the number 5 pin to arduino's number 12 pin, and attached the number 10 pin to arduiono's number 11 pin, the display worked perfectly. You might want to check your fritzing setup.

chickeneater (author)cliptwings2016-06-11

Which color wires on the Fritzing picture are you talking about?

cliptwings (author)chickeneater2016-06-11

Purple and yellow

chickeneater (author)cliptwings2016-06-12

ok that makes sense because what I ended up doing was switching the pin placement of everything for the number segments until they worked for every number, but I guess that I messed up. Nice catch and thank you for telling me.

arunk63 (author)2016-05-06

i wonder how multiple digit able to display when you can give one number at a time ?

chickeneater (author)arunk632016-05-07

im confused about your question, can you clarify?

ВиталийЗ2 made it! (author)2016-03-31


Happy to help!

But one question, from your picture it doesn't look like you are using any resistors, am I correct or just going crazy? Because usually that burns out the LEDs within the display.

I'm using 7 segment KYX-3461AS
Ifm=20mA, Vr=5v

I'm just going crazy ))).

But it's working.

chickeneater (author)2015-12-26


GroundZero (author)2015-11-29

Tnx for this tutorial :) it was very useful