Flickering LEDs with shift register 74hc595

Hi, so I'm pretty new to Arduino and electronics in overall, I did some simpler projects and now I wanted something more sophistocated. So I run out of pins, so I decided to use shift register. And here my problem begun...

14 lipca 2021 - YouTube - this is how it looks like, in real life it isnt't that noticable, for long time I was wondering if it's really flickering or it's just delusion.

As far as I read max is 70mA, I'm using 1.2k resistors, so with yellow LEDs it's around 2mA for single LED, so 16mA for all LEDs, it should be ok. Please correct me if I'm wrong, never before had I do such calculations. I was using tutorials most of the time, so I didn't need to think about voltage, ohms, etc... :smiley:

https://i.imgur.com/pekC6yb.png - that's my schematic.

And that's my code. I know it can be much simpler, but so far I took it from net tutorial.

#include <Arduino.h>

byte SER = 11; 
byte RCLK = 12;
byte SRCLK = 13; 
byte pins[8];

void clear() {
    for (int i = 0; i < 8; i++) {
        pins[i] = LOW;
    }
}

void save() {
    digitalWrite(RCLK, LOW); 

    for (int i = 7; i >= 0; i--) {
        Serial.println(pins[i]);
        digitalWrite(SRCLK, LOW);
        digitalWrite(SER, pins[i]);
        digitalWrite(SRCLK, HIGH); 
    }

    digitalWrite(RCLK, HIGH); 
}

void set(int index, int value) {
    pins[index] = value;
}

void setup() {
    Serial.begin(9600);

    pinMode(SER, OUTPUT);
    pinMode(RCLK, OUTPUT);
    pinMode(SRCLK, OUTPUT);
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH); 

    clear();
    save();

    
    for (int i = 0; i < 8; i++) {
        set(i, HIGH);
    }

    save();
}

void loop() {
}

The only thing I found on the internet, some people suggested using capacitors between Vcc and GND, but I don't have any and buying them is not so easy for me - either online shop or long ride to quite far away stationary shop. I wouldn't be happy if I lost this time (or money for shipping) and it won't give anything, as perhaps my problems is different and capacitors won't fix it...

It looks like you wired pin D11 to the output enable pin instead of the serial data pin of the 74HC595. Output enable should be connected to ground.

In general every chip should have its own bypassing capacitor, if you don't, you might get instability or flickering, but I think a wiring issue is more likely here.
Either way, there are hobby resistor and capacitor sets with standard values which are very handy to have lying around.

Whops, my bad! That's correct one - Imgur: The magic of the Internet

That's picture from above: https://i.imgur.com/8Ql5pse.jpeg

Also, in code and irl for tests I added extra wire that connects D10 with last LED to compare if it really flickers or my eyes are that bad. :smiley:

They're exactly the same?

The output enable pin is still floating.

Oh, that's because I'm moron and I uploaded bad photo, "correct one" had D11 connected to SER.

Also, I connected OE to GND and it works, thanks a lot! That's now using random tutorials ends - the one I was using was completely silent about OE, it said that only 11, 12 and 14 are important. -,- Well, at least now I know which site I should avoid :smiley:

As a general rule of thumb, you should always make sure that all input pins of a chip are in a well-defined state (by connecting them to ground or Vcc), even if you're not using them.

Sometimes OE can be used to adjust the brightness of the LEDs by PWM.