Introduction: 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

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

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...

***IMPORTANT NOTE***

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.

https://github.com/DeanIsMe/SevSeg

Step 4: 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);

sevseg.setBrightness(90);

}

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); "

2. Change "COMMON CATHODE" to "COMMON ANODE"

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.

Comments

author
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

author
glenzac (author)GeorgeB2372017-07-23

https://www.instructables.com/id/Simple-Seven-Segment-Temperature-Display-Using-Ard/

author
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?

author
PradeepT17 (author)JacquesL302017-05-14

Read step 3 again. You have to download library file from the link "https://github.com/DeanIsMe/SevSeg" and place it into your arduino library folder. The details are mentioned in step 3..

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

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

Seven_seg.jpg
author
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

author

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

SAM_0049.JPGSAM_0050.JPGSAM_0051.JPGSAM_0052.JPG
author

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.

author

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.

author
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).

author
Deina Underhill (author)DeanR462017-04-05

worked great, thanks!

author
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

author
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

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

and how would i use 2 displays using one arduino?

author
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.

author
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?

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

I don't know

author
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.

author
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

author

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

author

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

author
smarduino (author)2016-11-02

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

author
genuino (author)2016-11-02

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

author
SebbithecoolH (author)2016-08-28

AWESOME!!!! worked on my first try!

author
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)?

author
Floxyf (author)Floxyf2016-06-13

It's hiden in between pin 2 and 6

author
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.

author
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.

author
chickeneater (author)cliptwings2016-06-11

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

author
cliptwings (author)chickeneater2016-06-11

Purple and yellow

author
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.

author
arunk63 (author)2016-05-06

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

author
chickeneater (author)arunk632016-05-07

im confused about your question, can you clarify?

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

Thanks!

IMG_20160401_110656[1].jpg
author

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.

author

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

author

I'm just going crazy ))).

But it's working.

author
chickeneater (author)2015-12-26

np

author
GroundZero (author)2015-11-29

Tnx for this tutorial :) it was very useful

author
julowsky (author)2015-07-25

If 8 320k resistors are used, which pins on the display would the 8 resistors connect to?

author
chickeneater (author)julowsky2015-08-03

Probably the segment pins which are the ones that are not connected to a resistor in my schematic.

BTW if you connect those 8 resistors you wont need to connect the 4 that are connected in my schematic

author
curiosul made it! (author)2015-07-26

Thanks! I've just made it following your tutorial. I can confirm that the tutorial works fine.

20150727_000603[1].jpg
author
chickeneater (author)2015-07-09

not aware, sorry.

author
mat_fr (author)2015-07-08

Nice.
Note that with only 4 resistors on the common anode/cathode you limit the current flowing through the whole digit, not the single segment. This means that the "8" digit having all segments ON will share the same current as the "1" digit which only has 2 segments ON. The result will be that the 8 digit will appear dimmer than the 1 digit.
To resolve this "issue" you have to use a resistor on each segment, not each digit. This means using 7 or 8 (if you have a dot on the display) resistors, but it will make the digits evenly bright.

author
tomatoskins (author)2015-07-07

7 segment displays are so helpful and fun to use! Thanks for sharing and welcome to the community!

author
chickeneater (author)tomatoskins2015-07-07

No Problem.

If you or anyone else have any questions about this display, single digit displays, or Arduino and electronics in general, feel free to ask me.

--Chickeneater Out--