Motor is randomly stopping. It should not stop until a button is pressed

I have 2 vibration switches. When I vibrate one of them 3 times, the motor will spin continuously. Once I press a button it should stop. Those functions work, however, there are times when the motor will stop spinning without touching the button. Any ideas as to

#include <Stepper.h>


#define STEPS 200

int slowVibrationSensor;
int mediumVibrationSensor;
int mediumCount;
int slowCount;

//Read variables for the buttons
int emergencyButtonRead;
int fiveRead;
int sevenRead;
int fiveSteps;

//Vibration Pins
const int mediumPin = A5;
const int slowPin = A3;
//Button Pins
const int emergencyButtonPin = 3;
const int fiveFeetPin = 2;
const int sevenFeetPin = 1;

//Motor class declaration
//Steps is the number of steps (200 is full rotation)
//4, 5, 6, and 7 are the digital ports on the board
Stepper stepper(STEPS, 4, 5, 6, 7);


void setup()
{
  //Start serial port
  Serial.begin(9600);
  Serial.println("Stepper test!");

  //30 RPMs for the motor
  stepper.setSpeed(60);
}

void loop()
{
  //Vibration Sensor read analog ports
  slowVibrationSensor = analogRead(A3);
  mediumVibrationSensor = analogRead(A5);
  
  //Buttons reads the digital pins
  emergencyButtonRead = digitalRead(emergencyButtonPin);
  fiveRead = digitalRead(fiveFeetPin);

  //Print the vibrationSensor.  Idles around 400
  //Serial.println(mediumVibrationSensor);
  //Serial.println(slowVibrationSensor);

  //Once the medium sensor hits 1022, enter statement
  if(mediumVibrationSensor >1022)
  { 
    //Inc count, and print that it was inc'd
    mediumCount++;
    Serial.print("Medium Count inc\n");

    //If inc'd 7 times, enter statement
    if(mediumCount >= 3)
    {
      //start motor and print that it ran
      Serial.println("Forward");
      //Step until the button is pressed
   
      while(digitalRead(emergencyButtonPin) == 1)
      {
        Serial.println(digitalRead(emergencyButtonPin));
        stepper.step(1);
        //mediumCount = 0;
      }
    }
  }

  if(slowVibrationSensor >1022)
  { 
    //Inc count, and print that it was inc'd
    slowCount++;
    Serial.print("Slow Count inc\n");

    //If inc'd 3 times, enter statement
    if(slowCount >= 1)
    {
      //start motor and print that it ran
      Serial.println("Forward");
      //Step until the button is pressed

      while(digitalRead(emergencyButtonPin) == 1)
      {
        stepper.step(1);
        slowCount = 0;
      }
    }
  }

  //If this button is pressed, reel it in five feet
 if(digitalRead(fiveFeetPin) == 0)
  {
    while(fiveSteps <= 800 && digitalRead(emergencyButtonPin) == 1)
    {
      Serial.println(fiveSteps);
      stepper.step(1);
      fiveSteps++;
    }
   
    fiveSteps = 0; 
  }  
  //delay(50);
}

Those functions work, however, there are times when the motor will stop spinning without touching the button.

How are the buttons sewn on? Using the internal pullup resistors would make the wiring simpler.

How is the button wired ?

Do you have pull-up or pull-down resistors on your buttons? If you want, you can use the internal built-in pull-ups and won't need to add anything to the circuit. Use pinMode INPUT_PULLUP and wire the switch so that it will read LOW when pressed (ie. between the pin and ground).

PaulS:
How are the buttons sewn on? Using the internal pullup resistors would make the wiring simpler.

Delta_G:
Do you have pull-up or pull-down resistors on your buttons? If you want, you can use the internal built-in pull-ups and won't need to add anything to the circuit. Use pinMode INPUT_PULLUP and wire the switch so that it will read LOW when pressed (ie. between the pin and ground).

UKHeliBob:
How is the button wired ?

Welp, I feel pretty dumb. Didn't have the buttons and switches set to input like you all were mentioning. Fixed a bunch of my problems. Thank you.

pinMode(emergencyButtonPin, INPUT);
  pinMode(slowPin, INPUT);
  pinMode(mediumPin, INPUT);
  pinMode(fiveFeetPin, INPUT);

Don't know how to draw out the buttons...

But one lead on the button is to ground. The other is to 5v with 330 ohm resistor and Pin 3. Would using the pull-up matter in this case?

Pins default to INPUT, so not having a pinMode() call was not the issue.

Connecting one leg to ground and one leg to the digital pin, with INPUT_PULLUP as the mode, is much simpler. Then, LOW means pressed.

330 ohms sounds a little low but if you remove it and the connection to 5V and use INPUT_PULLUP they won't be there anyway.