Hello everyone, hope today finds you well. Board: UNO R4. The good: I have a NC PIR set as a ON/OFF switch and have it functioning they way I would like. When PIR is activated it goes NO for three seconds, and 65 is sent to PIN 1 serial TX which activates a relay (closed) . When PIR goes back to NC, 97 is sent to PIN 1 serial TX which deactivates the relay (open). This issue I am having is that the board is constantly transmitting 97 on the TX while the PIR is in NC status. I have tried a hundred different things and can not figure out where I am going wrong. I would like it to only transmit 65 once when pir is activated, then when it deactivates three seconds later to transmit 97 one time, then wait for the next activation. I have messed around with many combinations of INPUT_PULLUP/PULLDOWN etc. (yes R4 has built-in PULLDOWN). Any assistance would be greatly appreciated.
void setup() {
Serial1.begin(9600); //serial pins (TX 1) 9600baud
pinMode(5,INPUT); //PIR SWITCH NC
}
void loop() {
if(digitalRead(5)==HIGH){ //if PIR is activated (NO)...
Serial1.write(65); //send 65 over serial TX pin 1
delay(3000); //Factory delay for PIR activation (NO) and deactivation (NC)
}else if(digitalRead(5)==LOW);{ //When PIR deactivates (NC)...
Serial1.write(97); //send 97 over serial TX pin 1
delay(10);
}
}