Instructables

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!
 
Remove these adsRemove these ads by Signing Up

Step 1: 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

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.
 
1--14
2--16
3--13
4--3
5--5
6--11
7--15
8--7
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:


 

1-40 of 49Next »
sacnorth10 days ago
(removed by author or community request)
Jimmacle (author)  sacnorth9 days ago

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

rocarome8 months ago
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)  rocarome8 months ago
Did you use the right program? One just lights up random segments, and the other one is a timer.
rocarome Jimmacle8 months ago
YEs, I am using the timer program. You are using the Arduino uno right?

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

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)

viperML6 months ago
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?
mmbasha8 months ago
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
abeeche128 months ago
how to connect the colon on the display
Thanks
mmbasha9 months ago
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)  mmbasha8 months ago
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).
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.
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. :-) :-) :-)
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-IT1 year ago
Oh, I noticed the brightness changing. Thanks for the tip; I'll make a second version of this including this modification.
I suggest about 220 ohm.
now how to make a simple countdown timer from 30 sec and after it hits zero a buzzer goes off... any ideas?
Jimmacle (author)  Thekiller5781 year ago
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
where dous ground cume from?
Jimmacle (author)  jacobbrunberg1 year ago
On the display? Power comes in through the digit pins, and goes out through the segment pins.
ruthRon1 year ago
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;
to:
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.
ruthRon1 year ago
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)  ruthRon1 year ago
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.
How do I use the pushbutton to pause the counter rather than reset it?
Jimmacle (author)  salmansheikh2 years ago
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]
}
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)  salmansheikh2 years ago
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?
No, I want do different things..one 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.
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.
Jimmacle (author)  OCPik4chu1 year ago
That would probably be a better way to program the button. I would have used shift registers, but I didn't have any on hand and it would require wiring them to transistors (pins used to select segment are negative). Maybe I'll buy the parts and make another version.
KGuy1 year ago
I found this display in a Knex kit, as well as multiple other parts. The kit is pretty cheap, and I reccomend getting it..........http://www.ebay.com/itm/KNEX-Electronic-Arcade-Pinball-Speedball-USED-Knex-Building-Set-/350585893648?pt=LH_DefaultDomain_0&hash=item51a08c3310
Jimmacle (author)  KGuy1 year ago
The only "problem" with that would be finding the datasheet for it, unless it's printed somewhere on the display. Other than that, it seems like a nice buy.
yonch1 year ago
Why not use a decoder?
Jimmacle (author)  yonch1 year ago
I never thought of that. I'll start designing a 2nd version. My decoder might be broken though, I don't remember and I only have one.
Jimmacle (author)  Jimmacle1 year ago
After some testing, I realized that it's impossible because the digit pin needs to be HIGH and the segment pin needs to be LOW for the correct segment to turn on. The decoder outputs HIGH. I guess if I wire up an inverter for each segment it could work.
yonch Jimmacle1 year ago
So you can connect the segments to the decoder and the digit to the arduino.
1-40 of 49Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!