Strange behaviour from 74HC595 Shift Register

So this is the first time I am trying to use a shift register, specifically the 74HC595, but I am encountering some problems.

I am following the tutorial that is linked here, and I have summarized it in a schematic here. I have tentatively cut down the number of LEDs, for simplicity of testing.

To the best of my knowledge, the wiring looks correct. I have an image here, and a short gif of the problematic behaviour I am encountering here. I followed the schematic from the linked site, and added an additional 0.1 uF decoupling capacitor between Vcc and GND of the shift register (though this may not be entirely necessary).


Briefly:
Q0-3: connected to LEDs with 1kOhm current limiting resistor (orange)
VCC: connected to 5V (red)
SRCLR (shift register clear): connected to 5V (red)
GND: connected to GND (black)
OE (output enable): connected to GND (black)
SER (serial input): connected to Nano D4 pin (white)
RCLK (register clock/latch): connected to Nano D5 pin (blue)
SRCLK (shift register clock): connected to Nano D6 pin (brown)


Using the code from the site (pasted here and also at the bottom of this thread for your convenience), the LEDs should turn on one by one. For troubleshooting purposes, let’s assume that the coding is correct (for clarity: I have tried code from tutorials on other sites as well, which should either turn on a series of LEDs one by one, or count upwards in a binary fashion, but all have displayed similar abnormal behaviour, leading me to suspect a hardware level problem).

Does anyone have any ideas that I can troubleshoot? I have checked LED orientation, and they are all correct (e.g. output of shift register going to anode of each LED, and all cathodes sharing a common ground). I have also checked my wiring multiple times (pulling them all out, and restarting each time, over the course of several days to ensure I have ‘fresh eyes’ when looking at this problem). I suspect it must be something very basic I must have missed…

int latchPin = 5;  // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 6; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 4;  // Data pin of 74HC595 is connected to Digital pin 4
 
byte leds = 0;    // Variable to hold the pattern of which LEDs are currently turned on or off
 
/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup() 
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
}
 
/*
 * 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);
}


Expand

Can’t spot the problem.

Paul__B:

Expand

Can't spot the problem.

Thanks for the response, Paul__B. I'm pretty sure the schematic is correct, and I'm fairly confident that my actual breadboarding is correct. I've checked my wiring multiple times, and just to make sure I wasn't doing something incorrectly, I've ripped everything out, and then started afresh after getting a night's rest. However, the strange behaviour still persists.
I've been trying to figure out what should be a simple circuit for the last few days, and starting to pull my hair out!

“Question: where is the GND wire for the LEDs?”

Erik_Baas:
Question: where is the GND wire for the LEDs?

Thank you for taking a look. I've tried to edit my image with a zoomed in inset that explains my wiring for the LEDs.

The cathodes (short lead) of the LEDs all go into the ground bus on the left, and are connected back to main ground via the black wire at the bottom.

Full image resolution here

With regard to the LED circumference/s, the flat (almost without exception) indicates the cathode/s.
Maybe it's the resolution of your pic - is that how you have it?

but all have displayed similar abnormal behaviour, leading me to suspect a hardware level problem).

But what is this behaviour?

The ceramic capacitor across the power of the shift register is too far away from the chip pins. It must be as close as possible and the leads on the capacitor should be as short as possible.

runaway_pancake:
With regard to the LED circumference/s, the flat (almost without exception) indicates the cathode/s.
Maybe it's the resolution of your pic - is that how you have it?

This is actually something that drove me crazy for awhile.


Full resolution here
You can see that the long lead is on the right, and based on the internals, would imagine the right hand side is the positive anode.

However, if you look at the second image below, you'll see that the long lead is still on the right, but the flat of the LED is also on the right (flat is usually cathode, as you mentioned).


Full resolution here

To ensure that it wasn't me being stupid (e.g. putting the LEDs the wrong way around), I took them and flipped them on the breadboard (consequently, the first LED did not light up). I also verified using a button cell battery (long lead on the positive side of the coin cell, short lead on the negative side == LED lights up. It did not light up when flipped around).

Grumpy_Mike:
But what is this behaviour?

The ceramic capacitor across the power of the shift register is too far away from the chip pins. It must be as close as possible and the leads on the capacitor should be as short as possible.

According to the tutorial that I followed, the LEDs should come on one-by-one, until they are all on. Then they will all turn off, and this process should repeat.

However, the behaviour I am getting is the first LED being lit (brightly, corresponding to it being turned on as the first LED in sequence), while subsequent LEDs are not lit at all. The first LED also blinks dimly, which I found unusual.

As for the decoupling cap, I currently have it pictured as shown below (e.g. between VCC and the ground bus of the breadboard). I can try connecting it directly between VCC and GND of the shift register (as indicated by the red line) and shortening the leads, though I am not sure if it will solve my problem (though it cannot hurt to try)

You photograph does not show the marking on the IC which shows which way up it should be. There is normally a notch or / and small circle which indicate pin 1.

Also the part number doesn’t show up, can you see it?

As for the decoupling cap, I currently have it pictured as shown below (e.g. between VCC and the ground bus of the breadboard).

Yes I can see it. The problem is that the route to the chip is long, and the longer it is the less effective it is because that length acts as an inductor and the inductance lowers the maximum effective frequency it can block. It might not cure the problem but it will make it better.

Grumpy_Mike:
You photograph does not show the marking on the IC which shows which way up it should be. There is normally a notch or / and small circle which indicate pin 1.

Also the part number doesn’t show up, can you see it?
Yes I can see it. The problem is that the route to the chip is long, and the longer it is the less effective it is because that length acts as an inductor and the inductance lowers the maximum effective frequency it can block. It might not cure the problem but it will make it better.

Thanks for getting back to me. This definitely is a head scratcher. I have double checked my breadboard, and the IC is oriented correctly (e.g. notch is facing upwards, from the image I linked previously). Following the pinout schematic, this means pin 1 is on the upper left, counting downwards to pin 8, then across to the right is pin 9, and finally following the pins upwards to pin 16 (upper right hand corner).

As for the part number, it is labelled SN74HC595N.

I will give the shortened decoupling cap leads a try --- I spent the night poring over the datasheet for this IC, and tried rebuilding the circuit on another breadboard, but it still has the same buggy behaviour as I previously described.

I also did some probing with a multimeter, and I can see that the Q0 output definitely goes from ~0V up to 5V (which makes sense, as the program sets each Q0-7 output HIGH, before resetting). However, when I check Q1-7, I see only an increase to 0.2-0.3V, which is very bizarre. I currently do not have access to an oscilloscope (though I am hoping to borrow one from a friend if the situation allows); perhaps probing all the inputs/outputs may provide a hint as to exactly what is going on.

Sounds like the shift register could be faulty. Did you try replacing it?

Also don't trust those dupont wires. Check 'em all with your multimeter on resistance/continuity mode.

PaulRB:
Sounds like the shift register could be faulty. Did you try replacing it?

Also don't trust those dupont wires. Check 'em all with your multimeter on resistance/continuity mode.

I need to scrounge up another shift register for testing, unfortunately.

It's too bad that the IC might have gone belly up; I guess I'll have to see if I have more stuff to order to take advantage of Mouser/Digikey's free shipping

I'll go back and check the wire connections as well; they should all be connected, but I can double check with a multimeter for continuity

Tip - test the continuity from chip pin to chip pin. That way you keep from wiggling the connections. They can be intermittent.

Assuming it is not a simple wiring error with LEDs connected to Qb, Qc and Qd which can anyway be easily tested by swapping the these systematically with the connections at Qa, I cannot imagine either a simple coding error or another simple wiring error which could explain this phenomenon.

After the LED at Qa does a full blink, it then does a shadow blink during the time it and the other LEDs should be on.

A short pin 1 ( Qb ) of the SN74HC595N to ground (possibly an internal short) could maybe explain it.

6v6gt:
Assuming it is not a simple wiring error with LEDs connected to Qb, Qc and Qd which can anyway be easily tested by swapping the these systematically with the connections at Qa, I cannot imagine either a simple coding error or another simple wiring error which could explain this phenomenon.

After the LED at Qa does a full blink, it then does a shadow blink during the time it and the other LEDs should be on.

A short pin 1 ( Qb ) of the SN74HC595N to ground (possibly an internal short) could maybe explain it.

I have tried swapping the LEDs and connections from Qa/Qb/Qc, with the same behaviour (e.g. output Qa goes to the 2nd LED, while Qb goes to the first LED. Now, the second LED turns on, but the other LEDs do not).
This truly is puzzling behaviour to me; perhaps I just got a bad chip. I still haven't gotten my hands on a scope to test all the outputs, so this puzzle will remain unsolved until I do. In the meantime, it's off to source replacement chips