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 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
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};