PIR delay for Model Railway Turntable

As a total ignoramus when it comes to sketching could you please help me with a problem, which might actually be non-viable.
I want to use a PIR sensor to stop a model railway turntable from turning for an exact time after first contact. The problem I'm having is that as long as the PIR is activated the turntable is stopped, so instead of 30 seconds stop that is wanted it is in the stopped position as long as there is power to the Arduino.
So I was wondering if there's any way I can override the PIR output for a few seconds so the turntable can get away from the actual PIR sensor, BUT THEN stop for the 30 seconds as above?
The problem is that the motor 28BYJ-48 will actually move slightly whist stopped by the PIR and over time get away from the actual sensor of PIR so it can rotate again. The problem with that is that as it jumps slightly the rails on the turntable are no longer aligned with the rails on the main layout.

Thanks for your help in advance.

Hello
You may post the current sketch, with comments, well formatted, in code tags <"/">, a schematic and some pictures to see how we can help.

Here's the sketch, I hope!

#define STEPPER_PIN_1 9
#define STEPPER_PIN_2 10
#define STEPPER_PIN_3 11
#define STEPPER_PIN_4 12
int step_number = 0;
void setup() {
pinMode(13,OUTPUT);
pinMode(3,INPUT);
pinMode(STEPPER_PIN_1, OUTPUT);
pinMode(STEPPER_PIN_2, OUTPUT);
pinMode(STEPPER_PIN_3, OUTPUT);
pinMode(STEPPER_PIN_4, OUTPUT);
}

void loop() {

 if (digitalRead(3)== LOW)
  {
    digitalWrite(13,HIGH);
    
    delay(30000);
  }
  else 
  {
    
    digitalWrite(13,LOW);
    delay(10);
    
  }
  
  
  
  
  OneStep(false);
  delay(10);


}


void OneStep(bool dir){
    if(dir){
switch(step_number){
  case 0:
  digitalWrite(STEPPER_PIN_1, HIGH);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 1:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, HIGH);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 2:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, HIGH);
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 3:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, HIGH);
  break;
} 
  }else{
    switch(step_number){
  case 0:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, HIGH);
  break;
  case 1:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, HIGH);
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 2:
  digitalWrite(STEPPER_PIN_1, LOW);
  digitalWrite(STEPPER_PIN_2, HIGH);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, LOW);
  break;
  case 3:
  digitalWrite(STEPPER_PIN_1, HIGH);
  digitalWrite(STEPPER_PIN_2, LOW);
  digitalWrite(STEPPER_PIN_3, LOW);
  digitalWrite(STEPPER_PIN_4, LOW);


} 
  }
step_number++;
  if(step_number > 20){
    step_number = 0;
  }
}

Hi, I think I got the sketch on the question.
let me know if it's not.
Ta Tony

You can put a loop in right before the delay to step the motor however many steps you need to get away from the PIR. It may be tricky to ensure that the track lines up every time though.

Thanks for your answer. the next question is: How do I do what you suggest?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.