I have a sketch that works almost perfectly. I am using 3 PIR sensors to move servo motors to the reference location of each pie when triggered. What I am having trouble figuring out is how I can get all of my servos to reset to 90 when there is no motion detected after 60 seconds.
Here is my core code
#include <VarSpeedServo.h>
boolean pirStatus;
VarSpeedServo servo1;
VarSpeedServo servo2;
VarSpeedServo servo3;
VarSpeedServo servo4;
VarSpeedServo servo5;
int servangle = 0; // servo angle variable
int pirNo[] = {2,3,4}; // pir pin numbers
int pirPrevLow[] = {1,1,1}; // previously low flag set to true
int pirPrevUsed[] = {0,0,0}; // track if PIR has been used after going HIGH
int pirPos1[] = {30,70,150}; // positions for servo1 (0-180)
int pirPos2[] = {150,120,60}; // positions for servo2 (0-180)
int pirPos3[] = {150,120,60}; // positions for servo3 (0-180)
int pirPos4[] = {150,120,60}; // positions for servo4 (0-180)
int pirPos5[] = {150,120,60}; // positions for servo5 (0-180)
int curPosPir = 0;
int pirPin = 3;
void setup(){
Serial.begin(9600);
servo1.attach(8);
servo2.attach(9);
servo3.attach(10);
servo4.attach(11);
servo5.attach(12);
for(int i=0;i<4;i++){
pinMode(pirNo[i], INPUT);
}
delay(1000); // calibrate for about 10 seconds
}
//Main LOOP
void loop(){
for(int j=0;j<4;j++){ // for each PIR
pirPin=pirNo[j];
pirStatus = digitalRead(pirPin);
if (pirStatus == HIGH) {
if(pirPrevLow[j]) {
if (curPosPir != pirPin && pirPrevUsed[j] == 0) { // if high PIR is different than current position PIR then move to new position
servo1.write(pirPos1[j], 60, false);
servo2.write(pirPos2[j], 60, false);
servo3.write(pirPos3[j], 60, false);
servo4.write(pirPos4[j], 60, false);
servo5.write(pirPos5[j], 60, false);
curPosPir = pirPin; // keep current PIR
pirPrevUsed[j] == 1;
}
pirPrevLow[j] = 0; // pir is now not low
}
}
else {
pirPrevLow[j] = 1; // pir is now low
pirPrevUsed[j] == 0;
}
} // end j number of pirs loop
}// end infinite loop
Any advice would be appriciated.