triggering LEDs and Sound using a PIR

I’m using the Uno with the Adafruit FX audio board. I’m attempting to create a program that uses a PIR sensor to trigger two LEDs to blink in 5 distinct patterns, each at random and trigger a sound also randomly from five recorded sounds.
So far I have the PIR sensor triggering one LED to blink. Yay! I want to get the lights working before adding the sounds. I’ll add the second LED next. Easy enough. Where I’m stuck: 1.) Can someone give me a clue as to how to organize 5 different blink patterns so I can call them out for the sounds later? 2.) I’d like the LEDs to always alternate so there is never two on at once. 3.) is there a simple way to temporarily turn off the PIR or have nothing happen when it’s triggered? I don’t want the show going on all the time assuming there will be lots of movement.
Thank you kindly for any forward movement.

check the project out here: castleintheskyrobot@tumblir

sketch_pirTest2.ino (1.21 KB)

Can someone give me a clue as to how to organize 5 different blink patterns so I can call them out for the sounds later?

Instead of writing code for every blinking pattern you need to put the pattern as data in an array. This is, in rather the same way, as you would do when using the tone function to play a tune.

Their are a few ways of doing this, but one way would be to have an array for each LED which consists of a time before that LED is toggled, that is turned on if it is off or off if it is on.
Then to drive that pattern you need a blink without delay type sketch to handle the 5 LEDs and especially the sound all seemingly at the same time. This sort of code is known as a “state machine”.
See my
Or Robin2’s several things at once

To have more than one pattern you need a two dimensional array, that is an array of arrays, so you can choose the pattern you want as one of the dimensions of the array.

You are taking quite a step up in programming here, it might be difficult to get your head round it.

I have not got a specific example of this problem but here is some code I wrote to control a bunch of LEDs on a Christmas tree. Each LED blinks with its own pattern. Please read the comments in the code and try to understand what it does.

 * Multiple Blink - Mike Cook
 * controls 8 LEDs and blinks each one at an independent rate set by
 * the value in the flashTime array

int pins[] = {18, 19, 22, 23, 25, 26, 27, 28 };  // set up the 8 pins to use as outputs - these are for a mega change according to what setup you have
int flashTime[] = { 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000};  // set up the blink time of each LED
long int changeTime[] = {0, 0, 0, 0, 0, 0, 0, 0};  // array to hold when next to change the state of each LED

char serial_char;

void setup()                    // is run once, when the sketch starts
  for(int i=0; i<8; i++){
  pinMode(pins[i], OUTPUT);                    // sets the digital pins as output
  changeTime[i] = millis() + flashTime[i];    // set the time for the next change

void loop()                     // run over and over again
  for(int i=0 ; i<8; i++){ // look at each LED timer in turn
    if(millis()>changeTime[i]) {       // it is time to change the state of the LED
        digitalWrite(pins[i], !digitalRead(pins[i]) );  // make the LED the inverse of the current state (it's the ! that inverts)
        changeTime[i] = millis() + flashTime[i];        // set the time to make the next change
    }  // end of time to change the state of the LED if statement
  }  // end of for loop looking at all the LEDs
}  // end of loop() function

Thanks GrumpyM. I'll spend some time pouring over your code. One caveat, the sounds won't need to be attached to any single LED pattern. They can be played randomly per trigger. I don't want to get too crazy here.

I've read through your State Machine essay. It's going to take a few more readings. Simply looking at the code isn't helping a great deal. :o