PIR Sensor with L298N Motor driver Using arduino

sir/ma, please i need your help with this code
int in1 = 2;
int in2 = 3;
int sensor = 8;
int led = 13;

void setup()
{
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(sensor, INPUT);
pinMode(led, OUTPUT);

digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
digitalWrite(sensor,LOW);
digitalWrite(led,LOW);

while(millis()<13000)
{
digitalWrite(led,HIGH);
delay(50);
digitalWrite(led,LOW);
delay(50);
}
digitalWrite(led,LOW);
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);

}

void loop()
{
if(digitalRead(sensor)==HIGH)
{
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(led,HIGH);
delay(2000);
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);

digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(led,LOW);
delay(2000);
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);

}

}
The purpose of the code is to be able to open and close CD Driver whenever it detects movement on the PIR sensor, But my CD Driver keep opening and closing,
The component that I use are

  1. PIR Sensor
  2. L298N Motor Driver
  3. Arduino Uno Board
  4. CD Driver

You probably want to do the open/close when the sensor BECOMES high not keep doing it for as long as it stays high.

The StateChangeDetection example code in the IDE will show you the technique you need.

Steve