Hi guys,
After a lot of wiring and replacing PIRs (for 10$ youd think they’d be more reliable), all is up and running.
I am having one issue that is not hardware related. The 6th relay pin (5th in the array) will not act like the others in the loop. It is constantly on for the given amount of time (unsigned long duration) and then shuts off for a moment, then back on. Otherwise this code is working wonderfully, thanks again.
This is, in the case of the code below, Relay PIN 13 and Pir PIN 7.
Any ideas?
#define SIZE 6
int relay[SIZE] = {
8, 9, 10, 11, 12, 13 }; // output digital pins to solid state relays
int pir[SIZE] = {
2, 3, 4, 5, 6, 7 }; // input digital pins from Parallax PIR sensor
unsigned long startTime[SIZE ] = {
0,0,0,0,0,0 }; // time relay switched ON
unsigned long duration[SIZE ] = {
3000, 3000, 3000, 3000, 3000, 3000 }; // for how long in milli-seconds (note this is minimum time)
void setup()
{
Serial.begin (9600);
//Serial.println("Start PIR monitor 0.1");
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 ON
startTime[i] = millis();
Serial.print(millis());
Serial.print(", ON, ");
Serial.println(i);
}
if ((millis() - duration[i]) >= startTime[i]) // time to switch off ??
{
digitalWrite(relay[i], LOW); // switch relay OFF after x
Serial.print(millis());
Serial.print(", OFF, ");
Serial.println(i);
}
}
delay(500);
}