Hi All,
I would like to connect two PIR sensors on arduino board. but i have no idea to edit the coding.
int pirSensor = 2;
int ledPin = 7; //relayInput=7
int calibrate = 10;
unsigned long previousTime = 0;
unsigned long int pause = 5000 ;//5second
long unsigned int lowIn;
boolean lockLow = true ;
boolean takeLowTime ;
void setup() {
Serial.begin(9600);
pinMode(pirSensor, INPUT);
pinMode(ledPin, OUTPUT);//relayInput,output
digitalWrite(pirSensor, LOW);
digitalWrite(ledPin, LOW);
Serial.print("calibrating sensor ");
for (int i = 0; i < calibrate; i++) {
Serial.print(".");
delay(100);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}
void loop() {
if (digitalRead(pirSensor) == HIGH ) {
digitalWrite(ledPin, HIGH); // (relayInput, LOW)The Relay Input works Inversly
if (lockLow) {
lockLow = false;
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis() / 1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}
if (digitalRead(pirSensor) == LOW ) {
digitalWrite(ledPin, LOW);
if (takeLowTime) {
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if (!lockLow && millis() - lowIn > pause) {
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended at "); //output
Serial.print((millis() - pause) / 1000);
Serial.println(" sec");
delay(50);
}
}
}
// The sensor's output pin goes to HIGH if motion is present.
// However, even if motion is present it goes to LOW from time to time,
// which might give the impression no motion is present.
// This program deals with this issue by ignoring LOW-phases shorter than a given time,
// assuming continuous motion is present during these phases.