# Middle LED in 7-segment display randomly turns on and off

I'm currently driving a common-cathode 4 digit display using a 74595. Unfortunately, since this chip can't source enough current for driving all the LEDs, I will have to get a common-anode model however right now I am using 7 transistors to provide enough current.

For a test, I'm only lighting one digit at a time. Using the numerous tutorials I've found around the web, my code looks like this:

``````//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;

int i;
byte digitOne[10] = {0x3F, 0x6, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x7, 0x7F, 0x6F};

void setup()
{
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop()
{
for(int i=0; i<10; i++)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digitOne[i]);
digitalWrite(latchPin, HIGH);
delay(500);
}
}
``````

With LED A connected to output A and so on. The problem is, every so often LED G (the middle one) will go out. The 2 and 3 will look weird, and yet the 5 and 6 work perfectly fine.

I've encoded the numbers so that LED A represents bit 2^0, LED B is bit 2^1, and so on. For example, 7 would be 2^0 + 2^1 +2^2, or 7 (which is still 0x7 in hex). Could it be an issue with that? I've swapped that digit's wires so it's not a physical issue.

Edit: Now more LEDs are doing it. Here's a GIF example:

Cosmonaut:
I'm currently driving a common-cathode 4 digit display using a 74595. Unfortunately, since this chip can't source enough current for driving all the LEDs, I will have to get a common-anode model however right now I am using 7 transistors to provide enough current.

Whatever makes you imagine that swapping common-cathode to common-anode will improve matters?

I was rather alarmed when you mentioned a "74595" as the original TTL chips really have no place in designs - if I have important devices using them I go to the trouble of replacing them with HCMOS. But your code references 74HC595 and I presume that is what you are actually using.

Frankly, I consider this exercise rather futile, something along the lines of the "gives you a warm feeling but no-one notices" jokes. Just get a proper display using a MAX7219.

Common anode with TPIC6B595 would work well.
But one has to control the digits so that one digit is enabled (common anode high) at a time.

Common cathode with MIC5891 to source current, and 4 somethings to sink the common cathode current, (4 NPNs, 4 channels of TPIC6B595) would also work, one digit at a time.

Don't forget current limit resister per segment (a,b,c,d,e,f,g)

Paul__B:
Frankly, I consider this exercise rather futile, something along the lines of the "gives you a warm feeling but no-one notices" jokes. Just get a proper display using a MAX7219.

My bad. You are correct in that it is the HC. You are similarly correct in saying that it might not help at all, because I found out after looking through the datasheets that it can supply enough, in fact I got it to.

See, I'd like to use a MAX7219 driver and everything because it would be so simple, however I've already looked into those and they're about \$10 just for the chip. This is getting put into a little clock kit on a single PCB, where everything is controlled from an ATmega/similar chip running the Arduino sketch and I don't want it to be a \$30 project. I'm thinking half that.

Cosmonaut:
See, I'd like to use a MAX7219 driver and everything because it would be so simple, however I've already looked into those and they're about \$10 just for the chip.

Come on!

Click on the image of the display I gave you!

(forum may have added some extra to the start of the link)

...common-cathode 4 digit display using a 74595... chip can't source enough current for driving all the LEDs... using 7 transistors to provide enough current... found out after looking through the datasheets that it can supply enough, in fact I got it to... little clock kit on a single PCB, where everything is controlled from an ATmega/similar chip running the Arduino sketch

This will sounds very confused! You can drive this display with 11 or 12 Arduino/ATmega pins and 4 transistors. No 74hc595 or max7219 needed, although the max chip makes life much easier, as pointed out.

For a bedside clock, driving the display with Arduino pins or 74hc595 will be bright enough. With 74hc595, you could get 2.5mA average current per led, which isn't too bad.

You will need an RTC module, at least a couple of buttons to set the clock, and perhaps an ldr to dim the display, and also a buzzer for the alarm, I guess?

Anyway, back to your original question.

``````byte digitOne[10] = {0x3F, 0x6, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x7, 0x7F, 0x6F};
``````

It would be much easier to spot any errors if you use binary notation rather than hex. Then you can see the bits that control each segment:

``````byte digitOne[10] = {
// aaa
//f   b
// ggg
//e   c
// ddd
//
//pgfedcba
0b00111111, //0 (0x3F)
0b00000110, //1 (0x6)
0b01011011, //2 (0x5B)
0b01001111, //3 (0x4F)
0b01100110, //4 (0x66)
0b01101101, //5 (0x6D)
0b01111101, //6 (0x7D)
0b00000111, //7 (0x7)
0b01111111, //8 (0x7F)
0b01101111  //9 (0x6F)
};
``````

I can't see any errors...

I see a breadboard in the GIf. Is it working properly?