PIR to turn led

This sketch will turn pin4 high correctly, but after the initial high, the led on pin13 toggles on/off at the "pause" rate (5 sec). Would you please advise where the error is?

void loop()
{  
  if(digitalRead(pirPin) == HIGH){
    digitalWrite(enable,HIGH);
       motor(); //WORKS
        lastMotion = millis();
       digitalWrite(ledPin, HIGH);      
       if(lockLow){           
         lockLow = false;            
         delay(50);
         }         
         takeLowTime = true;        
       }
     if(digitalRead(pirPin) == LOW){       
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }       
       if(!lockLow && millis() - lowIn > pause){             
           lockLow = true;                                  
           delay(50);        
        }     
     }
    motor();   
}

I don't see anything called "pin4".

if(digitalRead(pirPin) == HIGH){
...
       }
     if(digitalRead(pirPin) == LOW){

Any reason for not using "else"?

Should have said the PIR pin which is on pin 4. Instead of a second "if", would "else" be correct?

This sketch will turn pin4 high correctly

But pin4 is an input from the PIR?
How does the sketch control it?

When I approach the board, the PIR sensor (on pin 4) reacts as it should; the LED on pin 13 lights but then it flashes on/off every five seconds.

And the value of "pause" is?

Please, just post the whole lot - we can't see what goes on in "motor", and we can't see what all the values are.motor(); //WORKS means not a great deal, unless "WORKS" is defined.

Sorry, I'm not making it easy.

/*______________________________opto switch____________________*/
int switch1 = 5;
int switch2 = 6;

/*_____________________________motor___________________________*/

int randNumberSpeed; // variable to store the random speed value
int randNumberDir;  // variable to store the random direction value
int motorSpeed = 11; // motor speed
int motorDir = 12; // motor direction
long lastMotion;
int enable = 3;

/*----------------------------PIR-------------------------------*/

long unsigned int lowIn; 
int calibrationTime = 30;
long unsigned int pause = 5000;  
boolean lockLow = true;
boolean takeLowTime;  
int pirPin = 4;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;
/*---------------------------Motor--------------------------------*/
void setup()
{
//time = millis();
Serial.begin(9600);
randomSeed(millis());
pinMode(motorSpeed,OUTPUT);
pinMode(motorDir,OUTPUT);
pinMode(enable,OUTPUT);

/*----------------------------PIR------------------------------*/
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);
 //give the sensor some time to calibrate
  for(int i = 0; i < calibrationTime; i++){
      delay(1000);
  }    
     
  
 /*________________________optoSwitch___________________________*/
pinMode(switch1,INPUT);
pinMode(switch2,INPUT);
} 
  
/*---------------------------PIR-------------------------------*/
void loop()
{  
  if(digitalRead(pirPin) == HIGH){
    digitalWrite(enable,HIGH);
       motor(); //WORKS
        lastMotion = millis();
       digitalWrite(ledPin, HIGH);      
       if(lockLow){           
         lockLow = false;            
         delay(50);
         }         
         takeLowTime = true;        
       }
     if(digitalRead(pirPin) == LOW){       
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }       
       if(!lockLow && millis() - lowIn > pause){             
           lockLow = true;                                  
           delay(50);        
        }     
     }
    motor();   
}
/*----------------------------Motor---------------------------*/

void motor(){

if (millis() - lastMotion < 10000){
//randomSeed(millis()); // sets millis() as seed

randNumberDir = random(255); // random number from 0-255
analogWrite(motorDir, randNumberDir); // outputs PWM signal
delay(500); // pauses for half a second

randNumberSpeed = random(255); // random number from 0-255
analogWrite(motorSpeed, randNumberSpeed); // outputs PWM signal
delay(500); // pauses for half a second
//motorStop();
}
else{
  
  digitalWrite(motorSpeed,LOW);
  digitalWrite(motorDir,LOW);
  digitalWrite(enable,LOW);
 }
}

/*_______________________opto switch_______________________________*/

void optoSwitch(){

if(switch1 == HIGH){
  digitalWrite(motorDir,HIGH);
  digitalWrite(motorSpeed,LOW);
  delay(500);
  motor();  
}

if(switch2 == HIGH){
   digitalWrite(motorDir,LOW);
  digitalWrite(motorSpeed,HIGH);
  delay(500);
  motor();
  
  
  
}

}