RFID reader with Motion Sensor

Hi all I'm currently doing a project and have spent around one month figuring out about my software issue about the motion sensor couldn't detect any motion This problem occurs when I combined RC522 RFID reader and HC - SR501 Motion Sensor. My microcontroller is Arduino Mega. Below is my source code please do have a look and we can have a discussion about how to rectify this issue together

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 53
#define RST_PIN 8
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
boolean DetectionChanged = false;
void detection() {DetectionChanged = true;}
int inputPin = 9;
int pirState = LOW;
int val = 0;

void setup()
{  Serial.begin(9600);   // Initiate a serial communication
  pinMode(inputPin, INPUT); // Tell the arduino to make pin 9 an INPUT
  attachInterrupt(digitalPinToInterrupt(inputPin), detection, CHANGE); // When there is a change on pin 2 the detection code
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Approximate your card to the reader...");
  Serial.println();
}

void loop()
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : ""));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (DetectionChanged) {
    DetectionChanged = false;
  val = digitalRead(inputPin); // reads the digital state on pin 2 ( HIGH OR LOW )
  if (val == HIGH) { // if this value is HIGH
    if (pirState == LOW) { // And the variable is LOW
      Serial.println("Motion detected!"); // Then there is motion , write this to the serial monitor
      pirState = HIGH; // Make variable HIGH
    }
  }
  else {
    if (pirState == HIGH) { // if the variable is HIGH
      Serial.println("Motion ended!"); // Then there is no detection
      pirState = LOW; // Make variable LOW
    }
  }
}
}

I really need your input and suggestion as this is considered as an important project for me
Thanks in advance

int inputPin = 9;
  attachInterrupt(digitalPinToInterrupt(inputPin), detection, CHANGE); // When there is a change on pin 2 the detection code

Which is correct, the code or the comment ?

UKHeliBob:

int inputPin = 9;
  attachInterrupt(digitalPinToInterrupt(inputPin), detection, CHANGE); // When there is a change on pin 2 the detection code

Which is correct, the code or the comment ?

It's the code that correct, I'll change the comment accordingly.