please help, PIR sensor code problem

high guys,

I'm am fairly new to the world of electronics/ arduino.

I am trying to make 8 led lights light up sequentially once the PIR sensor has been tripped however, the lights all flash and shouldnt, please help and see code below:

int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int pirPin = 3;
int val = 0;

const byte COL_COUNT = 8;

unsigned char sequence[COL_COUNT] = {B00000001, B00000011, B00000111, B00001111, B00011111, B00111111, B01111111, B11111111};

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

void loop()
{
val = digitalRead(pirPin);
if (val == HIGH)
{
int col_data = 0;
for (int col = 0; col < COL_COUNT; col++)

bitWrite(col_data, col, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, col_data);
digitalWrite(latchPin, HIGH);
delay(300);
}

delay(2500);

int col_data = 0;
for (int col = 0; col < COL_COUNT; col++)
{
bitWrite(col_data, col, LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, col_data);
digitalWrite(latchPin, HIGH);
delay(600);
}
}

You've set up an array called sequence but haven't used it anywhere.
I think that array should be an array of ints, not chars, as binaries are just numbers. You could write them as 1,3,7,15,31,63,127 and 255. The result will be the same.

thanks for reply,

but that still doesnt fix the problem with the PIR sensor.

What happens is when i add the if statement for the PIR the leds do not sequence, however it all works fine without the PIR if statement. all very confusing

This section of code appears to be missing some braces:

for (int col = 0; col < COL_COUNT; col++)   
  
    bitWrite(col_data, col, HIGH);
    digitalWrite(latchPin, LOW); 
    shiftOut(dataPin, clockPin, LSBFIRST, col_data); 
    digitalWrite(latchPin, HIGH);
    delay(300);

At least compared to the for loop that follows it.

very good spot! thankyou, however, this still hasn't fixed the problem =(

please help me guys, why isn't to sequence protocol being carried out after the PIR sends a live signal to the arduinio :frowning: :frowning: :frowning: :frowning: :frowning:

Run your code in loop once: either control it with a flag or move it to setup. Force val to be high so that both loops run. Does it work as you expect?