# Strange Results With a 3x7 Segment LEDs

I'm trying to get a CPS03631BR 3 digit 7 segments LEDs to work. I've wired it to my Arduino UNO like this:

And I'm using this code, which should light all the LEDs digit-by-digit, then light everything:

// Diagram: http://search.alkon.net/cgi-bin/pdf.pl?pdfname=13600.pdf
const int digit[] = { 9, 10, 11 };
const int led[]   = { 2, 3, 4, 5, 6, 7, 8, 12 };
//  a  b  c  d  e  f  g  dp

void setup() {
for (int i = 0; i < 3; i++) {
pinMode(digit[i], OUTPUT);
}

for (int i = 0; i < 8; i++) {
pinMode(led[i], OUTPUT);
}
}

void lights_off() {
for (int i = 0; i < 3; i++) {
digitalWrite(digit[i], LOW);
}

for (int j = 0; j < 8; j++) {
digitalWrite(led[j], HIGH);
}
}

void light_digit(int number) {
switch (number) {
case 0:
digitalWrite(digit[0], HIGH);
digitalWrite(digit[1], LOW);
digitalWrite(digit[2], LOW);
break;
case 1:
digitalWrite(digit[0], LOW);
digitalWrite(digit[1], HIGH);
digitalWrite(digit[2], LOW);
break;
case 2:
digitalWrite(digit[0], LOW);
digitalWrite(digit[1], LOW);
digitalWrite(digit[2], HIGH);
break;
}
}

void light_num(int number) {
switch (number) {
case 0:
digitalWrite(led[0], LOW);
digitalWrite(led[1], LOW);
digitalWrite(led[2], LOW);
digitalWrite(led[3], LOW);
digitalWrite(led[4], LOW);
digitalWrite(led[5], LOW);
digitalWrite(led[6], HIGH);
digitalWrite(led[7], HIGH);
break;
case 1:
digitalWrite(led[0], HIGH);
digitalWrite(led[1], LOW);
digitalWrite(led[2], LOW);
digitalWrite(led[3], HIGH);
digitalWrite(led[4], HIGH);
digitalWrite(led[5], HIGH);
digitalWrite(led[6], HIGH);
digitalWrite(led[7], HIGH);
break;
case 2:
digitalWrite(led[0], HIGH);
digitalWrite(led[1], HIGH);
digitalWrite(led[2], HIGH);
digitalWrite(led[3], HIGH);
digitalWrite(led[4], HIGH);
digitalWrite(led[5], HIGH);
digitalWrite(led[6], HIGH);
digitalWrite(led[7], HIGH);
break;
}
}

void loop() {
digitalWrite(led[0], LOW);
digitalWrite(led[1], LOW);
digitalWrite(led[2], LOW);
digitalWrite(led[3], LOW);
digitalWrite(led[4], LOW);
digitalWrite(led[5], LOW);
digitalWrite(led[6], LOW);
digitalWrite(led[7], LOW);

digitalWrite(digit[0], HIGH);
digitalWrite(digit[1], LOW);
digitalWrite(digit[2], LOW);
delay(500);
digitalWrite(digit[0], LOW);
digitalWrite(digit[1], HIGH);
digitalWrite(digit[2], LOW);
delay(500);
digitalWrite(digit[0], LOW);
digitalWrite(digit[1], LOW);
digitalWrite(digit[2], HIGH);
delay(500);
digitalWrite(digit[0], HIGH);
digitalWrite(digit[1], HIGH);
digitalWrite(digit[2], HIGH);
delay(500);
}


But instead what I'm getting is this:

When it should be lighting all the digit it's doing a 9 with a dot. When it reaches the third digit nothing happens. When all the LEDs should be ON it's displaying 33 and the third digit is completely OFF. I've tested each LED individually and they all work.

Any ideas?

• Where are your current-limiting resistors? Each segment pin should have a series resistor of at least 150 ohms in order to limit the current to 20 mA @ Vf = 2.0V. As it is, you are seriously overloading the Arduino outputs and over-driving the display. Dec 16 '12 at 13:43
• After adding the current limiting resistors, I would seriously look into cleaning up the wiring diagram. Part of the power of using a microcontroller is that you can use any pin to drive any LED. Get rid of all those crossovers in the wiring and change the 2nd and 3rd line in your code instead. Dec 16 '12 at 14:20