Problem with a IC ShiftRegister

Hello Everyone,

I an a total beginner in both Arduino and electronics, and this is my first question here.

I was following a series of tutorial which came along a beginner kit (from Smraza)

It’s about connecting 8 LED to a Shift Register. I have done and redone the connections from this tutorial, and from others in the net - including the one on Arduino web site here https://www.arduino.cc/en/Tutorial/ShiftOut

But I couldn’t achieve anything. Nothing seems to come out from the IC. No LED turn on.

So my questions are :

  • Is there something strange in my connections
  • Is the code OK
  • How can I test if there isn’t a problem with the Shift Register itself ?

Attached is a photo of my setup, and below a copy of the code (which is actually a copy of the tutorial code)

The Shift Register is a TI SN74HC595 http://www.ti.com/lit/gpn/sn74hc595

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
byte leds = 0;
void setup()
{
   pinMode(latchPin, OUTPUT);
   pinMode(dataPin, OUTPUT);
   pinMode(clockPin, OUTPUT);
}
void loop()
{
   leds = 0;
   updateShiftRegister();
   delay(500);
   for (int i = 0; i < 8; i++)
   {
      bitSet(leds, i);
      updateShiftRegister();
      delay(500);
   }
}
void updateShiftRegister()
      {
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, leds);
      digitalWrite(latchPin, HIGH);
}

Any help will be appreciated !

Best

Jerome

Hint

leds = 0;

Karma for your first post having code in code tags and providing a clear photo of what you have made.

PerryBebbington:
Hint

leds = 0;

I don't think that's wrong?

Both the code and the connections seem correct to me.

Pieter

I don't think that's wrong?

Unless I missed something that means only 0s are sent to the LEDs so none of them will ever light. Did I miss somewhere that some of the outputs are set to 1?

PerryBebbington:
Unless I missed something that means only 0s are sent to the LEDs so none of them will ever light. Did I miss somewhere that some of the outputs are set to 1?

You are right, I’m sorry, I was under the impression that bitSet would alter the variable, obviously, it does not. Edit: it does.
But then what did the OP mean?
> JeromeBoulbes:
> and below a copy of the code (which is actually a copy of the tutorial code)

But then what did the OP mean?

I don't know. I read it quickly, noticed the 0, couldn't see anywhere that set the LEDs to anything other than 0, couldn't see anything wrong with the wiring so make the comment and hoped someone else might pick up something I missed.

bitSet is supposed to write a 1 to the nth bit of variable x, so that does look right:
bitSet(x, n);

Try doing a Serial.println with the value of leds whenever you do a shiftOut, then you can see if that value is correct.
If it is, you have probably connected something wrong. If it's not, you have probably coded something wrong.

Check that the wire to the SRCLR_ input is actually making contact. It looks like it might be short.

I think you may have RCLK and SRCLK mixed up. Try this and see what happens (it will not hurt the circuit if I'm wrong):

int latchPin = 6;
int clockPin = 5;

GalFisk:
bitSet is supposed to write a 1 to the nth bit of variable x, so that does look right:
bitSet(x, n);

bitSet doesn't change the variable, it returns the new value.
So it should be:
~~ ~~leds = bitSet(leds, i);~~ ~~

Edit: I was wrong.

PieterP:
bitSet doesn't change the variable, it returns the new value.

So it should be:

leds = bitSet(leds, i);

Not according to the Arduino reference. Is the reference incorrect? I do agree that the syntax is a bit odd.
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitset/

Description
Syntax

bitSet(x, n)

Parameters

x

: the numeric variable whose bit to set

n

: which bit to set, starting at 0 for the least-significant (rightmost) bit
Returns
Nothing

You're right, I got confused :slight_smile:

Warning, the LED at the top of your image is wired wrong! !
You may be damaging your Arduino.

Add a .1µf ceramic capacitor from pin 16 to GND

Confirm pin 10 of the I.C. is connected to +5V.

Confirm LED cathodes are connected to GND/0V.

Make some voltage measurements to confirm jumpers are powering the I.C.

Remove I.C. from breadboard, confirm no legs are bent underneath.

Kind of hard to see your connections to the Uno

but it looks like you are using pins 3,4,5 not 4,5,6 as in your sketch.

but it looks like you are using pins 3,4,5 not 4,5,6 as in your sketch.

There are 4 open pins visible D0-D3.

The OP needs to check some voltages.

The wiring seems okay except for the LED at the top of the image.

The code looks okay.

Either the OP has fried the chip, bent the leads or screwed up the Arduino.

Blame thy self . . .

Hello Everyone . Thankyou for all the suggestions. Even if it doesnt works, it still good study !

  • For the leds variable hint, I changed the loop code to the following. Am I right to assume that if all connections are right, this would light all LEDs ?
void loop()
{
   leds = 255;
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
 
}

I have double checked all the suggested points , but nothing worked

  • Check that the wire to the SRCLR_ input is actually making contact. It looks like it might be short.

  • I think you may have RCLK and SRCLK mixed up.

check OK

  • Confirm pin 10 of the I.C. is connected to +5V.

check OK

  • Confirm LED cathodes are connected to GND/0V.

check OK

  • Remove I.C. from breadboard, confirm no legs are bent underneath.

check OK


Then I learned that I need some more equipment …

  • Add a .1µf ceramic capacitor from pin 16 to GND
  • Make some voltage measurements to confirm jumpers are powering the I.C.

I did put a voltmeter and this capacitor on top of my buying list

but I guess at the end the correct diagnostic is from Larry ::slight_smile:

larryd:
Either the OP has fried the chip…

Thanks eveyone for your time and patience

Jerome

JeromeBoulbes:
Then I learned that I need some more equipment ... I did put a voltmeter and this capacitor on top of my buying list

Lacking a voltmeter you could still use one of the LEDs as a poor man's logic probe.

GND --> LED cathode --> resistor --> use a jumper wire to touch various points to test for +5V.