PIR sensor and relay

Hi,
I have a small problem with PIR sensor. I want to control relay (which will control solenoid, but that's not important) with PIR sensor (HC-SR505). The problem is, when the sensor is first activated relay turns on and off in infinite loop. Please help. There is my code:

#define pir_sensor 3
#define solenoid 2

int on_time = 1500;

bool detected = false;

void m_detector() {
  
  detected = true;
  
}

void setup() {

  pinMode(pir_sensor, INPUT_PULLUP);   //PIR sensor
  pinMode(solenoid, OUTPUT);           //Water output
  
  Serial.begin(115200);
  attachInterrupt(digitalPinToInterrupt(3), m_detector, RISING);

  delay(2000);    //Power up delay
  
}

void loop() {

  Serial.println(detected);

  if (detected == true) { 

    digitalWrite(solenoid, HIGH);
    delay(on_time);
    digitalWrite(solenoid, LOW);
    
    detected = false;
    
  }

}