0

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:

enter image description here

12
  • 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.
    – Majenko
    Mar 23 '20 at 14:42
  • That said, the fact that some turn part way on when they shouldn't really is a concern.
    – Majenko
    Mar 23 '20 at 14:43
  • 1
    It would really help if you add a schematic of how you actually built the circuit, instead of me trying to debug your circuit from a low resolution, animated GIF. Your code looks fine at first glance, btw.
    – StarCat
    Mar 23 '20 at 15:17
  • 2
    @Agriculex - Please answer your own question then accept that answer in 48 hours.
    – VE7JRO
    Mar 23 '20 at 19:15
  • 1
    StackExchange is not a forum. You don't edit the question's title with "Solved" if you have an answer. Instead you write an answer and (later, when you're allowed to) you mark it. Please correct that. People coming here don't look for "Solved", they look for marked answers. Mar 23 '20 at 20:31
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.

1
  • Yes. You can't leave important pins, like SRCLR, floating. Signals that matter must be intentionally set. True with any chip.
    – lurker
    Apr 18 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.