I followed the tutorial on controlling 8 LEDs using a SIPO SN74HC595N shift register on both Adafruit and Last Minute Engineer. I used a Sparkfun Pro Micro (Arduino Leonardo equivalent).
The problem is the LEDs are not lighting up in the way that I'm expecting it do it. Both guides said each LED will light up one after another. After all 8 are lit, all of them will turn off. Here is my result. Other LEDs will either dim up or down as the target LED turn on. I used the code provided from the guide and only changed the pinout number. The resistor values are the same for each color so it can't be the resistor. Anyone have any idea what's going on here?
/*
Test code for 74HC595N SIPO shift register. Used with Pro Micro
*/
int latchPin = 16;
int clockPin = 15;
int dataPin = 14;
int outputEnablePin = 10;
byte leds = 0; // Variable to hold the pattern of which LEDs are currently turned on or off
void setup()
{
// Set all the pins of 74HC595 as OUTPUT
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(outputEnablePin, OUTPUT);
outputEnablePin = LOW;
}
/*
* loop() - this function runs over and over again
*/
void loop()
{
leds = 0; // Initially turns all the LEDs off, by giving the variable 'leds' the value 0
updateShiftRegister();
delay(500);
for (int i = 0; i < 8; i++) // Turn all the LEDs ON one by one.
{
bitSet(leds, i); // Set the bit that controls that LED in the variable 'leds'
updateShiftRegister();
delay(500);
}
}
/*
* updateShiftRegister() - This function sets the latchPin to low, then calls the Arduino function 'shiftOut' to shift out contents of variable 'leds' in the shift register before putting the 'latchPin' high again.
*/
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
Schematics:
1 Answer 1
The dimming problem was found to be the shift register IC not connected to Ground (dumb me).
However, there is still problem with LED's on and off pattern. Sometimes two LEDs turn on at the same time and all previous LEDS turning off before the last or second last LED is turned on. It turns out Pin 10 (SRCLR Bar) needs to be pulled to high to solve that pattern discrepancy.
-
Yes. You can't leave important pins, like SRCLR, floating. Signals that matter must be intentionally set. True with any chip.lurker– lurker2021年04月18日 18:08:44 +00:00Commented Apr 18, 2021 at 18:08
The resistor values are the same for each color so it can't be the resistor.
What makes you think that? The current through the LED is dictated by the resistor value and the LED's forward voltage. The LED's forward voltage is dictated by the colour. Thus you need to size the resistor correctly for each colour of LED.