Introduction: 4-Digit 7-Segment LED Display + Arduino

Picture of 4-Digit 7-Segment LED Display + Arduino

I recently got a 4-Digit 7-Segment LED Display from Sparkfun, and couldn't wait to use it. Here, I will show you how to wire it, and some sample programs to use with it!

Step 1: Display Info

Picture of Display Info

This is the way the display works. It's multiplexed, so you select the digit by setting its pin (we'll get into pins later) HIGH, and you select the segment by setting its pin LOW. You display multiple digits at once by rapidly cycling through them.
The Pins (digits are numbered from the left):
Digit 1: 1
Digit 2: 2
Digit 3: 6
Digit 4: 8
Segment A: 14
Segment B: 16
Segment C: 13
Segment D: 3
Segment E: 5
Segment F: 11
Segment G: 15
Decimal Point: 7

Step 2: Wiring the Display and Button

Picture of Wiring the Display and Button

Now, to wiring! To make it easier for you, I am going to put the Arduino pin number first, then the display's pin number.
9--1 (resistor)
10--2 (resistor)
11--6 (resistor)
12--8 (resistor)

If this is too confusing, say so in the comments, and I'll rewrite it.
Connect the button to Arduino pin 13 and 5V.
I used 1K resistors, but you could get away with less.

Step 3: Programming

I'm pretty much just putting refrence links and files here.
Display Datasheet

Timer Program (I modeled my timer after this)

Attatched Files:

_4segTimer: Timer program

_4digitAni1: Animations

The programs still need some tweaking/additions, so I'll be updating them once in a while.

Update History:



gasper1 (author)2017-07-07

hello again,still no success in getting the sketch to start counting.I am using a UNO v3 with a 5461A5 type readout.12 pin

Im sure it must be something simple that is causing it to non start.

gasper1 (author)2017-07-06

Can you give me some idea's why I can't get the digits to start counting. I am sure i am working with the correct code, as the other code works well.but I cannot get this start counting.All my connections are correct.

please help make an old happy !!.

Please help

blackburdtx (author)2016-10-22

There are only 12 pins on the display but your connecting pin 1 on the Ard to pin 14 on the display.... very confusing.

run7 (author)blackburdtx2017-04-02

same here

robertje (author)run72017-04-08

some down in the comments:

1--10 (a)
2--7 (b)
3--4 (c)
4--2 (d)
5--1 (e)
6--11 (f)
7--5 (g)
8--3 (dot)
9--12 (resistor) (d1)
10--9 (resistor) (d2)
11--8 (resistor) (d3)
12--6 (resistor) (d4)

10 and 11 reversed for me

Tip: If you have 12-pin segment display your scheme will be like this:

1--10 (a)
2--7 (b)
3--4 (c)
4--2 (d)
5--1 (e)
6--11 (f)
7--5 (g)
8--3 (dot)
9--12 (resistor) (d1)
10--9 (resistor) (d2)
11--8 (resistor) (d3)
12--6 (resistor) (d4)

Used the same, except of 10 and 11, I reversed it. Using (sh)5461as panels.

tmahundrah (author)2016-12-30

i got it working, it is a 4 digit seven segment i got from an old DSTV Decorder, and controlling it over the serial monitor

abolfazl fakour (author)2016-12-27

thank you

aseppermana (author)2016-10-25

i has download it,but cant open in arduino IDE because that file is not pde

KarissaA1 (author)2016-08-03

Does the 4 digit file is the part one of the Segment?

EligijusJ (author)2016-03-09

I dont get it how to wiring ?! Can anyone sent schematics or smth ? Thank You :)

DavidB552 (author)EligijusJ2016-07-18

yeah could we get a digram ?

ArcAiN6 (author)2016-07-15

People should also be aware that there are differences when wiring CC (Common Cathode) and CA (Common Anode) 7-Segment displays, as well as addressing them with the code, or using shift registers / led drivers.

PaulW106 (author)2015-12-02

To get the timer to work do I just copy and paste the file into the Arduino program?

ndi francesco (author)2015-08-28

please can you post the circuit diagram ?

npegnato (author)2015-04-02

Could I possibly get a list of comments for what's happening in either the timer or animation program? I'm using a 4 digit display for a heart rate monitor and I want to know how I can display the BMP from my Arduino.

kittekaak1 (author)2014-09-05

It runs also with an ULN 2803 instad of the 4 transistors. where can i buy in europe the sma420564 ? I have only one in my arduino kit. mfg CK

Tohydromx (author)2014-07-27

I am using an Arduino Mega 2560, and I am using analogWrite intead of digitalWrite because I don't have low value resistors at the moment :(

1: the button doesn't work, maybe pin13 is cursed on my board + i like using the LED for error reporting. if you used other pins it won't work without a pull-down resistor, or reversing the code and using the internal pull-up. I suggest:

in setup(). add: pinMode(xx, INPUT_PULLUP)

in loop(). change: if (digitalRead(13) == HIGH) to: if (digitalRead(xx) == LOW)

and the button connects between pin and ground. (xx any pin other than 13 ).

2: the digits were reversed ie: it was counting from left to right. I suggest:

int d1 = 9; int d2 = 10; int d3 = 11; int d4 = 12;

instead of: int d4 = 9; int d3 = 10; int d2 = 11; int d1 = 12;

3: Thank you for the instructable :)

Jimmacle (author)2014-07-13

I smell spam, or you're just someone who doesn't understand the differences between my project and the one you linked.

rocarome (author)2013-10-27

I wasn't able to get the program to count, all it did was light up all the segments. Do I need to add a certain library in order for it to work?

Jimmacle (author)rocarome2013-10-28

Did you use the right program? One just lights up random segments, and the other one is a timer.

rocarome (author)Jimmacle2013-10-28

YEs, I am using the timer program. You are using the Arduino uno right?

white_phox (author)rocarome2014-06-12

Actually he appears to be using a duemilanove, will test on my UNO later

viperML (author)2014-01-08

Could you help me please?
My LED display hasn't got the [ : ] (those two dots) so it has got less pins, only 12 (6 in each side). How do I do the connections?

mmbasha (author)2013-10-28

Hello can anyone please help me with codes for
a counter down timer of 10min and 59 sec which will be running on a seven segment led
with two button for (stop/resume) also one for reset
it will count down until it reaches 00:00 when it reaches zero it has to gives a buzzer sound for just three second

abeeche12 (author)2013-10-28

how to connect the colon on the display

mmbasha (author)2013-10-16

can you help me to understand how you noted the pin out from the arduino board ?
there is no 14, 15 ,16, tell us the pin name as mentioned on the arduino board
thanks i am stuck to continue

Jimmacle (author)mmbasha2013-10-28

The numbers in the left column are the pins on the Arduino itself. The numbers in the right column correspond to the pins on the display (which will be different if you have a different display).

SuperTech-IT (author)2013-04-20

The resistors should be on the SEGMENTS, not the DIGITS (IE: pins 3,5,7,11,13,14,15,16). The way this is wired, there would be 3.5 X the current through a resistor when displaying an 8 as when displaying a 1, and this will result in brightness fluctuations. Thanks for the rest of the information though.

RadekH (author)SuperTech-IT2013-07-06

There is no need to put the resistors on the segments instead on the common contacts!

You can choose whenever you like to put your resistors to. The point is to change appropriately your algorithm. Just imagine that you chose segment first an then choose a digits it should shine. Then continue with next segment.

Actually I did it today cause I forgot my 1k resistors, having only 2 of them I was able to test two 14 segments displays.

General rule is. If it do not work, turn world upside down. If it still do not work, turn world inside out. :-) :-) :-)

SuperTech-IT (author)RadekH2013-07-06

If you are lighting more than one segment at a time (IE: if you are turning on all 7 segments to make an 8) and not DRAWING the 8 by rapidly sequencing each segment (lighting only one segment at a time in rapid succession, so that persistence of vision makes you see the whole digit 8) then the resistors need to be on the segments, otherwise the 1 resistor gets more current through it the more segments are lit - and your display is much dimmer making an 8 than a 1. Since this instructable makes the whole digit, you need the resistors on each segment. If the code were changed so that it was "drawing" each digit, then yes, you could get away with 1 resistor per digit without suffering brightness loss - however this method takes much more programming and processor resources.

I'll draw an analogy. Lets say you have a 2 inch water pipe, and it has to feed the 8 taps in the house. The taps need a restricted water flow though, or the washers will blow out. What we do, is we reduce the 2 inch pipe to ¼ inch right before each tap. This ensures the tap get maximum water flow without danger. We can turn on all the taps without problem since all 8 are being fed by the 2 inch pipe before the flow is reduced at each tap.

Now lets imagine a rookie plumber shows up, and he doesn't have eight ¼ inch reducers - so he decides to just reduce the 2 inch pipe to ¼ inch with one reducer, and then feed the 8 taps. Well, it works fine when 1 tap is on - it gets the most water you can put through the pipe and everything is fine.
But then the whole family comes home from camping and they all need to wash - so all 8 taps are opened at once. Well, now we are trying to feed 8 taps with only a ¼ inch feed - and all the taps suffer and only get 1/8 of the water that they can handle. Yes, there's still water at all the taps - so technically "it works" - but it doesn't work well, because it wasn't done right!

To further this explanation - lets say that a 2 inch pipe allows a maximum flow of 8 gallons a minute. The taps can only handle 1 gallon a minute, or they blow a gasket. We need to reduce the flow from 8 gallons a minute to only 1. This means we have to divide the flow by 8. 2 inches divided by 8 is ¼. so a one quarter inch pipe will allow only one gallon per minute to flow. This is perfect for a single tap. With all 8 taps on, since the 2 inch pipe can allow 8 gallons a minute, and each tap is restricted to 1 gallon a minute, this is perfect, even with all taps on. If we reduce the flow to 1 gallon a minute first, and then feed that to all 8 taps, since the maximum flow for all 8 taps is a total of 1 gallon a minute, the 8 taps now have to share this, and each tap only gets one eighth of a gallon per minute. I hope that clears it up.

Jimmacle (author)SuperTech-IT2013-04-22

Oh, I noticed the brightness changing. Thanks for the tip; I'll make a second version of this including this modification.

SuperTech-IT (author)2013-04-22

I suggest about 220 ohm.

Thekiller578 (author)2012-12-24

now how to make a simple countdown timer from 30 sec and after it hits zero a buzzer goes off... any ideas?

Jimmacle (author)Thekiller5782012-12-29

You could probably write a program where you set a variable and it subtracts 1 every second, then *if* it equals zero, *then* sound a buzzer. You would need to call a separate function that deals with displaying the variable's value on the display.

you could make a timer count down and then you can have a piezo buzzer go off

jacobbrunberg (author)2012-12-29

where dous ground cume from?

Jimmacle (author)jacobbrunberg2012-12-29

On the display? Power comes in through the digit pins, and goes out through the segment pins.

ruthRon (author)2012-12-04

thank you- i got it working for the blue color with 110 ohm resistors.
for the counter code, to get the right side digit to display the second i flipped the DIGITs order from your code:
//int d4 = 9; int d3 = 10; int d2 = 11; int d1 = 12;
int d4 = 12; int d3 = 11; int d2 = 10; int d1 = 9;
now it displays correctly with the fast counting digit to the right side, decimal second to the left etc.

ruthRon (author)2012-12-04

thanks for the tutorial! I see resistors in the pictures but not on your pin connection list. where should i put resistors and what value? thanks a lot

Jimmacle (author)ruthRon2012-12-04

Sorry, use the resistors instead of jumpers on pins 1, 2, 7, and 8 (the display selection pins). I used 1K resistors, but you could get away with something less.

salmansheikh (author)2012-05-16

How do I use the pushbutton to pause the counter rather than reset it?

Jimmacle (author)salmansheikh2012-05-16

That is not currently in the program. You could have it set up where it only counts if the button is not pressed, for example:

void loop() {
buttonState = digitalRead(13)
if (buttonState == LOW) {
[insert counting program here]

salmansheikh (author)Jimmacle2012-05-16

Thanks. I was thinking of making a basketball game timer and also need to use the ":" that could count to 30:00 minutes or down from 30:00 to zero and pause for fouls with a push of the button. I have another display for the score but not sure one Arduino could program both displays...

Jimmacle (author)salmansheikh2012-05-16

So you'd definitely want to replace the button with a switch, so you don't have to hold the button down. If both displays show the same thing and have the same pin configuration, it shouldn't be a problem as long as they don't draw too much current (probably not, since they're cycling through and not constantly on). Would you like me to make a program that counts down from a settable time?

salmansheikh (author)Jimmacle2012-05-17

No, I want do different will be an game elapsed timer, the other display, two scores, one teams on left of : and one on the right. Games only go to double digits. That may require 2 more buttons and another Arduino unless I can multiplex the control signals somehow, perhaps with a 4th button.

OCPik4chu (author)salmansheikh2012-10-03

I'm by all means not an expert on the Arduino at all but do have some working programming knowledge. I would think if you instead used the button state to set a variable to 1 or 0 rather than pole the button directly you can put that in the clock loop to freeze the time if its been set. Id recommend just to Google 'Arduino stopwatch' as it should be right in line with what you want, IMO. Additionally, using shift registers would allow you to control several displays with just one Arduino. It will get more complicated if you nest registers but you can still do quite a bit. You should be able to, without it being too complicated get at least 2 7-segment digits per 1 shift register as long as you use the right one. And it would only require 2-3 pins on the Arduino for each one.

About This Instructable




Bio: I love electronics, computers, and everything DIY!
More by Jimmacle:4-Digit 7-Segment LED Display + ArduinoLEGO Mindstorms NXT: Roadster PSP-NX SuperchargedMy Bluetooth Range Extender
Add instructable to: