I'm newbie in arduino and I'm having some issues here. I bought two moviment PIR sensors, when someone passes in front of the sensor the logic value is HIGH, otherwise the value is LOW.
Besides that I would like to increment a value when the sensor A is HIGH, and decrement the same value when the Sensor B is HIGH.
But I have to issues here, I can't increment and decrement the variable value, and the serial print is repeating constantly for 5000 miliseconds, because I need to use delay, otherwise, the code will not work.
int pinPIRa;
int pinPIRb;
int count;
void setup() {
Serial.begin(9600);
pinMode(pinPIRa,INPUT);
pinMode(pinPIRb,INPUT);
}
void loop() {
if(digitalRead(pinPIRb) == HIGH){
Serial.print("Sensor B");
count--;
}
if(digitalRead(pinPIRa) == HIGH){
Serial.print("Sensor A");
count++;
}
delay(5000);
}
Now I have two questions for you guys, how can I prevent the serial from repeating numerous times? I tried to use Serial.flush() but it doesn't work.
And I would like to know how can I increment and decrement the count variable? The count variable is decrementing and incrementing more than one time because the code is running inside a loop.
Thank you.