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


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

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.

<p>When I verify the code, it says all the references to sevseg.something are undefined. How do I fix that?</p>
<p>Once I got the pins on the right segments, this worked finest kind! Thanks!</p>
<p>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 </p>
<p>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</p>
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. <br><br>Shouldn't be to hard to fix. I will try to fix it ASAP which might not be until the weekend (school). <br><br>Thanks for informing me of your problems.
<p>I just setup &amp; ran this and I am also having problems with digits 0, 2, &amp; 3. I haven't tried hex mode, so i don't know about it.</p><p>0 lights segments a, b, c, d, e, &amp; g. f is off</p><p>2 lights segments a, b, d, e, &amp; f. c &amp; g are off</p><p>3 lights segments a, b, c, d, &amp; f. e &amp; g are off</p><p>The library &amp; sketch I am using I d/l from github this morning. the files in the ZIP are dated 2/22/17 3:50 AM</p><p>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.</p>
<p>Your segment pins for 'F' and 'G' are swapped.</p><p>Swap the F and G pins numbers that you declare in the segmentPins[] and your display will work. (Alternatively, swap the wires).</p>
<p>worked great, thanks!</p>
<p>&quot;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.&quot;</p><p>I am a little lost when you say &quot;it will show a 0 missing&quot; because there is no 0 in the numbers 2222, 3333, 3141, etc....</p><p>Are you saying that one of the segments are not on?</p><p>If so which segment?</p><p> _</p><p>I _ I</p><p>I _ I</p>
<p>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</p>
<p>and how would i use 2 displays using one arduino?</p>
<p>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. </p>
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?
<p>I don't know</p>
<p>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 &quot;invalid digit &quot;8&quot; in octal constant&quot;. Also, there are largely chances getting incorrect display when set the first digit to &quot;0&quot;. For example, the number 1.037 can be displayed exactly, but 0137 or 0037 can't.</p>
<p>Helloo ! I do not own 330Ohm resistors.. i only have 220Ohm , 1k Ohm and 10k Ohm ! should any of them work? #Beginners_question</p>
<p>220 should be fine, I've used 220 before #I'mAnElectronicEngineer</p>
<p>Yeah I agree, 220&Omega; are fine just brighter i think. </p>
<p>Quick naive question from a beginner, how come there is no GND connection?</p>
<p>Quick naive question from a beginner, how come there is no GND connection?</p>
<p>AWESOME!!!! worked on my first try! </p>
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)?
<p>It's hiden in between pin 2 and 6</p>
<p>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. </p>
<p>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.</p>
<p>Which color wires on the Fritzing picture are you talking about?</p>
<p>Purple and yellow</p>
<p>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.</p>
i wonder how multiple digit able to display when you can give one number at a time ?
<p>im confused about your question, can you clarify?</p>
<p>Happy to help!</p><p>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.</p>
<p>I'm using 7 segment KYX-3461AS<br>Ifm=20mA, Vr=5v</p>
<p>I'm just going crazy ))).</p><p>But it's working.</p>
<p>Tnx for this tutorial :) it was very useful</p>
<p>If 8 320k resistors are used, which pins on the display would the 8 resistors connect to?</p>
<p>Probably the segment pins which are the ones that are not connected to a resistor in my schematic. </p><p>BTW if you connect those 8 resistors you wont need to connect the 4 that are connected in my schematic</p>
<p>Thanks! I've just made it following your tutorial. I can confirm that the tutorial works fine.</p>
<p>Nice.<br>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 &quot;8&quot; digit having all segments ON will share the same current as the &quot;1&quot; digit which only has 2 segments ON. The result will be that the 8 digit will appear dimmer than the 1 digit.<br>To resolve this &quot;issue&quot; 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.</p>
<p>7 segment displays are so helpful and fun to use! Thanks for sharing and welcome to the community! </p>
<p>No Problem.</p><p>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.</p><p>--Chickeneater Out--</p>

About This Instructable



More by chickeneater:Parachute Dropper Inland RFID learning kit Transmitter/Receiver + Arduino 
Add instructable to: