Shift Register not lighting LEDs as expected

I am 6th grader and started learning arduino. Check out my website www.aaravpatel.com

I learned basic things and now I am trying to learn shift register. I think I understand it correctly and my circuit is also correct. I have attached 8 leds to all 8 outputs of the shift register.

if I give input as 0b10101010, all odd leds will lit.
if I give input as 0b01010101, all even leds will lit.

but if I give both with delay of 1 second, only odd leds lit.

I tried to give different input and I confirm that all led individually works fine as per input but it does not work as expected when I try to change input after delay. Below is my program.

byte leds1 = 0b01010101;
byte leds2 = 0b10101010;

void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop()
{

delay(1000);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds1);
digitalWrite(latchPin, HIGH);

delay(2000);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds2);
digitalWrite(latchPin, HIGH);

}

What shift register are you using? It may be that your shift register clocks data on the rising edge of the clock and you have to take care of that as referenced in the documentation for shiftOut() here

Here is my updated program. I am using 74HC595.

Now all my leds remain lit.

byte leds1 = 0b01010101;
byte leds2 = 0b10101010;

void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop()
{

delay(1000);
digitalWrite(latchPin, LOW);
digitalWrite(clockPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds1);
digitalWrite(clockPin, HIGH);
digitalWrite(latchPin, HIGH);

delay(1000);
digitalWrite(latchPin, LOW);
digitalWrite(clockPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds2);
digitalWrite(clockPin, HIGH);
digitalWrite(latchPin, HIGH);

}

The shiftOut example code (shiftOut() - Arduino Reference) should work fine with the 74HC595, so I would expect a hardware problem. Did you double-check the connections?

Pieter

I don't think so. Some code works, some does not. For example, If I try code from below link, only pingpong function works but not other. I have ordered new shift registers and now I will order new arduino board. I am really confused at the moment.

https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-14-using-a-shift-register

I got new arduino board. no luck. now waiting for new shift register.

Can anyone explain why my LEDs would blink with below code??

byte leds1 = 0b10101010;

void loop()
{

delay(500);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds1);
digitalWrite(latchPin, HIGH);
}

if I try below code (all on) then they don't blink.

byte leds1 = 0b11111111;

void loop()
{

delay(500);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds1);
digitalWrite(latchPin, HIGH);
}

Please stop wasting our time. If you are serious about wanting help, read the forum guide in the sticky post. That will tell you that you should post a schematic so we can see what components you are using and how they are connected. And that you should post complete code, using code tags.

Oh hmm. Sorry, I am new to programming/arduino/forum and what not. I am just 6th grader. I got this circuit working now but for future questions, I will follow guidelines going forward.

aaravpatel0124:
I got this circuit working now

Could you post your solution, so other people stumbling across this thread can learn from it?