Processing Forum
#define SIZE 6
int relay[SIZE] = {8, 9, 10, 11, 12, 13 }; // output digital pins to solid state relaysint pir[SIZE] = {2, 3, 4, 5, 6, 7 }; // input digital pins from Parallax PIR sensorint time= 1000;
unsigned long startTime[SIZE ] = {0,0,0,0,0,0 }; // time relay switched ONunsigned long duration[SIZE ] = {time, time, time, time, time, 20000 }; // for how long in milli-seconds (note this is minimum time)
void setup(){Serial.begin (9600);for (int i=0; i < SIZE; i++){pinMode(relay[i], OUTPUT);pinMode(pir[i], INPUT);}}
void loop(){for (int i =0; i<SIZE; i++){
if (digitalRead(pir[i]) == HIGH) // check PIR state{digitalWrite(relay[i], HIGH); // switch relay ONstartTime[i] = millis();Serial.print(digitalRead(pir[i]));Serial.print(",");}
if ((millis() - duration[i]) >= startTime[i]) // time to switch off ??{digitalWrite(relay[i], LOW); // switch relay OFF after x}}
}