74HC595 leds blink but not turn on


int DS_pin = 8;
int STCP_pin = 9;
int SHCP_pin = 10;
int flag = 0;


void setup()
{
  pinMode(DS_pin,OUTPUT);
  pinMode(STCP_pin,OUTPUT);
  pinMode(SHCP_pin,OUTPUT);
  pinMode(6,OUTPUT);
  writereg();
}

boolean registers[8];

void writereg()
{
  digitalWrite(STCP_pin, LOW);
  for (int i = 7; i>=0; i--)
  {
    digitalWrite(SHCP_pin, LOW);
    digitalWrite(DS_pin, registers[i] );
    digitalWrite(SHCP_pin, HIGH);
  }
  digitalWrite(STCP_pin, HIGH);
}

void loop()
{
  if(flag ==0){
    
    for(int i = 0; i<8; i++) { 
      registers[i] = HIGH;
      analogWrite(6,100); 
      //delay(100);
      writereg();
       
    }
    flag = 1;
  }
}

I try test shiftreg but i have only blink of leds and I dont know how to turn on ALL leds at some time

Hi,

You should have a series resistor for each led. 150~300R is ok. Also put a 0.1uF cap from 5V to ground near the '595 chip's power pins.

See this line:      //delay(100);

The "//" means that the line of code is ignored and not executed. This will make your leds blink very quickly. Remove the "//" and change 100 to 500.

Paul

PaulRB:
You should have a series resistor for each led. 150~300R is ok. Also put a 0.1uF cap from 5V to ground near the '595 chip's power pins.

Hi i have leds which power voltage is 5 V. I added delay 100, but I dont understand why leds blink, I have flag which ensure that 1 time all leds turn on, but they blink. I just want to turn on all leds at some time.

NikKKKK:
Hi i have leds which power voltage is 5 V.

Oh, really? I never heard of those.

NikKKKK:
I have flag which ensure that 1 time all leds turn on, but they blink.

Perhaps your Arduino is resetting. This could be because too much current flows, causing supply voltage to drop. Use Serial.println() to send a message to the serial monitor inside init(). This will show you when the Arduino is resetting.

PaulRB:
Perhaps your Arduino is resetting. This could be because too much current flows, causing supply voltage to drop. Use Serial.println() to send a message to the serial monitor inside init(). This will show you when the Arduino is resetting.

I checked but my message shows one time in serial monitor(

Thanks all. Problem was in leds. I take leds which voltage is 3 V and resistors and all woked.