Don't understand why motor is not stopping

Hi,
New to this so please bare with. tuning R3 UNO using a rain sensor to extend an arm. I have a stepper motor nema-17 on a L298N controller board. Just switched to the bigger motor after I used the tiny guy that comes with beginner kit. I was able to get the tiny stepper motor to turn for how long I wanted and stop until the rain sensor changed its value. Now once I switched to the new bigger motor and different control board I can not get the program to stop running. So if the rain sensor is dry the motor spins, then delay, then spins again, so on and so forth. If I wet the sensor it will reverse direction but again doesn't stop. I have a variable check of arm to determine if the rain sensor has moved. So if arm and arm1 are equal then the rain sensor has not changed its value. The problem is that I can't get arm to be the value of digitalread(). I am using arm extend to launch the next action once the rain sensor has changed its value. Here is the code

#include <Stepper.h>

Stepper myStepper(512, 8, 9, 10, 11);
//Stepper myStepper(00, 8, 10, 9, 11);
const int captd = 4;
//const int capteur_A = A0;
int armextend = 0;
char arm;
char arm1;
int stepsPerRevolution = 0;
void setup() 
 {
  //pinMode(capteur_A, INPUT);
  
  myStepper.setSpeed(80);
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  
}

void loop() {

  pinMode(captd, INPUT);
  
arm = digitalRead(captd);

if (arm1 == arm)
{
  armextend = 0;
}
 else  {
  armextend = 1;
}

if(digitalRead(captd) == HIGH && armextend == 1) 
 {
 
   //clockwise without rain
  stepsPerRevolution = 1000;
  myStepper.step(stepsPerRevolution);
  armextend = 0; 
  delay(5000);
  
 }
   
  if (digitalRead(captd) == LOW && armextend == 1)
   {  
   // if (armextend == 1)
   
    //coutner clockwise with rain
 stepsPerRevolution = -1000;
  myStepper.step(stepsPerRevolution);
   armextend = 0;
   delay(5000);
   
      }
     

  arm1 = arm;

}

Hi Frank,

welcome to the forum and well done to post code as a code-section.

You should auto-format your code by pressing Ctrl-T in the Arduino-IDE
The indention is used to make it easier to see which line of code belongs to which curly bracket.
I understand what each single line of code does. But it is unclear to me what you want to achieve
and how your rain-sesnor is functioning.

So please write a description in normal words what signals does your rain-sensor produce and what should happen
if rain ist detected or no rain ist detected.

I is very important to do this in normal words by consequently avoiding programming-terms.
Often newbees have a - partially wrong - picture of how C++functions work. That's the reason why you should do it in normal words.

best regards Stefan

Now once I switched to the new bigger motor and different control board I can not get the program to stop running.

i tested your logic, adding prints to both conditions and see both conditions being executed once, as expected, potentially after a 5 second delay. One change i had to make was define the pin an INPUT_PULLUP

not sure you're seeing the same thing, but this suggests the problem is with your stepper commands.

the following might make it easier to see your logic

#include <Stepper.h>
Stepper myStepper(512, 8, 9, 10, 11);
//Stepper myStepper(00, 8, 10, 9, 11);

#if 0
const int captd = 4;
//const int capteur_A = A0;
#else
const int captd = A1;
#endif

int armextend = 0;
char arm;
char arm1 = HIGH;
int stepsPerRevolution = 0;

void setup()
{
    //pinMode(capteur_A, INPUT);
    myStepper.setSpeed(80);
    Serial.begin(9600);
    pinMode(13, OUTPUT);
    pinMode(captd, INPUT_PULLUP);
}

//clockwise without rain
void cw (void) {
    Serial.println ("w/o rain");
    stepsPerRevolution = 1000;
    myStepper.step(stepsPerRevolution);
}

// coutner clockwise with rain
void ccw (void) {
    Serial.println ("w/ rain");
    stepsPerRevolution = -1000;
    myStepper.step(stepsPerRevolution);
    armextend = 0;
}

void loop() {
    arm = digitalRead(captd);
    if (arm1 != arm) {
        arm1 = arm;
        if (HIGH == arm)
            cw ();
        else
            ccw ();
    }
}

GCJR, Thank you very much for helping slim down the code, haven't written a program in 20yrs (School). Still having some issues but I think the problem is partly between the chair and the keyboard, and I need a more reliable power source. I made a 12volt, and it has drained hard from the testing .So next step by a power cord, then will get back to it. my issues are kinda all over the place now (motor was turning, then would only go 1 direction, then stopped) Hopefully all of it is power related, I am only getting 4volts at the controller board.

Stefan, I will keep your noted in mind for my next post or if I need more help with this project.

Thanks again for making first timer feel welcome

Frank