Hello,
first I want to apologize if my english is not very good,
but anyway, let's talk about this PIR problem :
I'm using an arduino with more than a PIR and a relay, but It is obvious that that is what the problem is;
to illustrate the problem let's use this situation with just the PIR and the relay :
Connections :
- PIR: (HC-SR505)
- ---> 5V
-
---> Gnd
out ---> D6 -
Relay : (SRD-05VDC-SL-C)
- ---> 5V
- ---> Gnd
S ---> D5
//relay pin:
const int relay= 5;
//PIR pin:
const int ir=6;
// count down variables:
int c=-1; // We define the relay as open
int timedelay = 100;
void setup() {
//relay pin:
pinMode(relay,OUTPUT);
//PIR pin:
pinMode(ir,INPUT);
digitalWrite(ir,LOW);
//Console
Serial.begin(9600);
}
void loop() {
int pirVal = digitalRead(ir);
Serial.println(pirVal);
if(pirVal==HIGH) {
if(c == -1){digitalWrite(relay,HIGH);} //the relay was open, so we close it
c=timedelay; //while there are mouvements, we reset the countdown to the chosen delay
}
else { // here: pirval==LOW
if(c>0){c--;}
if(c==0) { // if time is up
Serial.println("time's up");
digitalWrite(relay,LOW); // we open the relay
Serial.println(pirVal); //1*
delay(10);
Serial.println(pirVal);//2*
c=-1; // We define the relay as open
}
}
delay(100);// a test every 100ms
}
The purpose of all of this is to activate the relay if there is mouvement, and desactivate the relay after a chosen delay (here 10s) without mouvement.
But here the problem comes: about 10ms after the desactivation of the relay, I have a unwanted signal from the pin OUT of the PIR:
at 1*,pirVal= 0
at 2*,pirVal= 1
without no mouvement in front of the PIR !
To calm down after this brief signal, the PIR needs about 7-8 seconds,
So when the loop restart, the program re-activate the relay, and it never stop to desactivate and re-activate the relay every 17-18 seconds..
Can someone help me ?