Print.serial() once using Pin Change Interrupts

Hi guys. I tried to use the below code to print information once a time when the 3 simple sensors sense any change in its input pins, but it did not work, it keeps printing in serial monitor

int inPin = 7;   
int inPin1 = 8; 
int inPin2 = 9;   




void setup()
{
  pinMode(inPin, INPUT);     
  pinMode(inPin1, INPUT);
  pinMode(inPin2, INPUT);     
  Serial.begin(9600);
}

void loop()
{
        if (digitalRead(inPin) == HIGH && digitalRead(inPin1) == LOW)
       {
         Serial.println("DOOR #1 ACTIVATED");
         delay(1000);
       }

       
        if (digitalRead(inPin) == LOW && digitalRead(inPin1) == HIGH)
       {
         Serial.println("DOOR #1 DEACTIVATED");
         delay(1000);
       }

        if (digitalRead(inPin) == HIGH && digitalRead(inPin1) == HIGH)
       {
         Serial.println("ERROR!");
         delay(1000);
       }

}

So, I need some advice in how to use Pin Change Interrupt or any other way that allows me to print once a time the sensor senses any change in its inputs. Thank you so much.

Where did the code go that uses an interrupt?

Paul

Several things. First, do you really need to use interrupts. (I don't see an ISR.) You could just do polling like you appear to be doing since you're likely going to end up running through the loop several thousand times a second, provided that: Second, delay() is a blocking function that would mess up using interrupts. Third, the actual board you are using makes a difference if you want to use external interrupts since the can be different from board to board. Finally, what kind of sensors are you using?

Hi, I am using Uno, but I have Mega 2560 too.
The sensors are simple switches, connected to a industrial fridge door. I need to know how many times the doors are opened, closed and so on. Thank you.

You want to detect the change (from LOW to HIGH or vice versa) on a pin in your loop, not the fact that a pin is LOW or HIGH. Look at the state change detection example that comes with the IDE.

And is pointed out, you do not have an interrupt (and for this, you don't need one).