Problems with 74HC595 and ULN2003 to drive 12V 7 segment

Hi Folks,

I have a problem driving a 12v 7 segment with an ULN2003.
I do have a weird problem which is as follows:
when instead the 12v ill supply only 5v on the commnon anode of the leds I am able to see my code working just fine, as soon as I do up the voltage a little bit the led strips which should not light at all are lightning in a dimmed mode sort to speak.

I don't know what I'm doing wrong, It would be nice if somebody could direct me to a working implementation of a sn74hc595 and uln2003. I am using an Arduino Uno to control the entire circuit.
ill attach the schematic I'm using with the visible problem of the leds.

Please post your code

Untitled.png
Expand

7SegDisplayWrong.jpg
Expand

You show an "Arduino ground" and a "12 V ground". I trust you realise they are always connected together. :roll_eyes:

If they are connected together and you have a problem, it is in your code as Bob points out. :grinning:

If your LED segments require less than 150 mA, a TPIC6B595 does the job of both ICs - and has only one ground terminal. :sunglasses:

please find the code attached. its a simple counter code which I've found online.

/* SevenSegmentLEDdisplay102a.ino

  • 2017-02-20
  • Mel Lester Jr.
  • Simple example of using Shift Register with a
  • Single Digit Seven Segment LED Display
    */
    // Globals
    const int dataPin = 4; // blue wire to 74HC595 pin 14
    const int latchPin = 7; // green to 74HC595 pin 12
    const int clockPin = 8; // yellow to 74HC595 pin 11

/* uncomment one of the following lines that describes your display

  • and comment out the line that does not describe your display */
    const char common = 'a'; // common anode
    //const char common = 'c'; // common cathode

bool decPt = true; // decimal point display flag

void setup() {
// initialize I/O pins
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop() {
decPt = !decPt; // display decimal point every other pass through loop

// generate characters to display for hexidecimal numbers 0 to F
for (int i = 0; i <= 15; i++) {
byte bits = myfnNumToBits(i) ;
if (decPt) {
bits = bits | B00000001; // add decimal point if needed
}
myfnUpdateDisplay(bits); // display alphanumeric digit
delay(5000); // pause for 1/2 second
}
}

void myfnUpdateDisplay(byte eightBits) {
if (common == 'a') { // using a common anonde display?
eightBits = eightBits ^ B11111111; // then flip all bits using XOR
}
digitalWrite(latchPin, LOW); // prepare shift register for data
shiftOut(dataPin, clockPin, LSBFIRST, eightBits); // send data
digitalWrite(latchPin, HIGH); // update display
}

byte myfnNumToBits(int someNumber) {
switch (someNumber) {
case 0:
return B11111100;
break;
case 1:
return B01100000;
break;
case 2:
return B11011010;
break;
case 3:
return B11110010;
break;
case 4:
return B01100110;
break;
case 5:
return B10110110;
break;
case 6:
return B10111110;
break;
case 7:
return B11100000;
break;
case 8:
return B11111110;
break;
case 9:
return B11110110;
break;
case 10:
return B11101110; // Hexidecimal A
break;
case 11:
return B00111110; // Hexidecimal B
break;
case 12:
return B10011100; // Hexidecimal C or use for Centigrade
break;
case 13:
return B01111010; // Hexidecimal D
break;
case 14:
return B10011110; // Hexidecimal E
break;
case 15:
return B10001110; // Hexidecimal F or use for Fahrenheit
break;
default:
return B10010010; // Error condition, displays three vertical bars
break;
}
}

Paul__B thanks for the tip. I have connected the two grounds together and now its all up to understanding how the shift register works because what is for whatever reason displayed is a mambo jumbo. Ill thank you again for the quick reply and ill update the thread as soon as I have a working counter.

Code updated accordingly and it works as wanted.
0 0 0 0 0 0 1 0

128 64 32 16 8 4 2 1

A B C D E F G

00100100
1101101

3

0000110

4

10011000

5

01001000

6

01000000

7

00011110

const int latchPin = 7; // Pin connected to Pin 12 of 74HC
const int dataPin = 4; // Pin connected to Pin 14 of 74HC
const int clockPin = 8; // Pin connected to Pin 11 of 74HC
// 0,1,2,3,4,5,6,7,8,9
int dec[10] = {63,6,91,79,102,109,125,7,127,111};

int count;
int display_number;
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
for (count = 0; count<10; count++){
display_number = dec[count];
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, display_number);
digitalWrite(latchPin, HIGH);
delay(1000);
}
}