faire un "home" moteur pas à pas

Bonjour à tous
Pour un projet de robotique, j'ai besoin que le moteur ( un neman 17 avec un easydriver) face un "home" pour connaitre sa position à la mise sous tension pour qu'il puisse commencer ça boucle.
Pour cela j'ai utilisé la fonction "while" en début de boucle.
Pour la détection j'utilise un Switch NO.
Se qui se passe: le moteur tourne sans arrêt malgré que le switch se ferme, et donc les vrais instructions ne commencent pas.
J'en appelle à vos lumières :wink:
Si joint le sketch
Merci de m'avoir lu
A+

int smDirectionPin = 2; //Direction pin
int smStepPin = 3; //Stepper pin
int smBoutonPin = 9; //switch NO pin 9

void setup(){
  pinMode(smBoutonPin, INPUT_PULLUP);
  digitalWrite(smBoutonPin, LOW);  
  pinMode(smDirectionPin, OUTPUT);
  pinMode(smStepPin, OUTPUT);

  
  Serial.begin(9600);
}
 
void loop(){

//faire un home
  
  while(smBoutonPin!=LOW)
  {
  digitalWrite(smDirectionPin, HIGH); //écrit la direction dans EasyDriver (HIGH: sens anti horaire).
  /*Slowly turns the motor 1600 steps*/
  for (int i = 0; i < 1600; i++){
  digitalWrite(smStepPin, HIGH);
  delayMicroseconds(2000);
  digitalWrite(smStepPin, LOW);
  delayMicroseconds(2000);
  }
  }
    delay(1000);
    
//home touvé avancer d'un demi tour

  digitalWrite(smDirectionPin, LOW); //écrit la direction dans EasyDriver (LOW: sens horaire).
  /*Turns the motor fast 1600 steps*/
  for (int i = 0; i < 800; i++){
  digitalWrite(smStepPin, HIGH);
  delayMicroseconds(800);
  digitalWrite(smStepPin, LOW);
  delayMicroseconds(800);
  }
  
  delay(100);
  
//commencer la vrai boucle

  digitalWrite(smDirectionPin, LOW); //écrit la direction dans EasyDriver (LOW: sens horaire).
  /*Slowly turns the motor 1600 steps*/
  for (int i = 0; i < 800; i++){
  digitalWrite(smStepPin, HIGH);
  delayMicroseconds(900);
  digitalWrite(smStepPin, LOW);
  delayMicroseconds(900);
  }
 
  delay(1000); //Pauses for a second (the motor does not need to pause between switching direction, so you can safely remove this)
 
  digitalWrite(smDirectionPin, HIGH); //écrit la direction dans EasyDriver (HIGH: sens anti horaire).
  /*Turns the motor fast 1600 steps*/
  for (int i = 0; i < 800; i++){
  digitalWrite(smStepPin, HIGH);
  delayMicroseconds(900);
  digitalWrite(smStepPin, LOW);
  delayMicroseconds(900);
  }
 
  delay(1000);
}

I assume you subscribe to the notion that an Arduino is not a power supply. Start by disconnecting the arduino control connections and see what happens. If it keeps going it is Hardware, if not it is probably software. You can always use LEDs to be sure the signals are correct before connecting the motor. Also be sure the grounds are all connected together.

Merci gilshultz de ta réponse

Le système fonction bien, car quand je considère le moteur comme une DEL que je dois allumer ou éteindre par le switch, cela fonctionne.
En dessous le sketch du moteur ON.OFF via le switch, qui fonctionne

const int Direction = 2; //Moteur Direction pin 2
const int Step = 3; //Moteur Step pin 3
const int Bouton = 9; //switch NO pin 9
int etatBouton = 0;

void setup(){
  pinMode(Bouton, INPUT_PULLUP);
  pinMode(Direction, OUTPUT);
  pinMode(Step, OUTPUT);

  
  Serial.begin(9600);
}
 
void loop(){
etatBouton = digitalRead(Bouton);

   if(etatBouton==HIGH){ //contact bouton ouvert (le moteur tourne).
  
  digitalWrite(Direction, LOW); //écrit la direction dans EasyDriver (LOW: sens horaire).
  /*Slowly turns the motor 1600 steps*/
  for (int i = 0; i < 1; i++){
  digitalWrite(Step, HIGH);
  delayMicroseconds(2000);
  digitalWrite(Step, LOW);
  delayMicroseconds(2000);
  }
   }

  else{  // contact bouton fermé (le moteur s'arrête).
  digitalWrite(Step,LOW);
  }
  }

Si dessous le sketch avec la condition "while" dans le "loop" pour que le moteur face un "home" à un point précis avant de commencer les vrais instructions (les vrais instructions ne sont pas présentes dans l'exemple).

const int Direction = 2; //Moteur Direction pin 2
const int Step = 3; //Moteur Step pin 3
const int Bouton = 9; //switch NO pin 9
int etatBouton = 0;
 
void setup(){
  
pinMode(Bouton, INPUT_PULLUP);
pinMode(Direction, OUTPUT);
pinMode(Step, OUTPUT);
 
Serial.begin(9600);
}
 
void loop(){
  
etatBouton = digitalRead(Bouton);

while(Bouton==LOW){
  
   digitalWrite(Direction, LOW); //écrit la direction dans EasyDriver (LOW: sens horaire).
  /*Slowly turns the motor 1600 steps*/
  for (int i = 0; i < 1; i++){
  digitalWrite(Step, HIGH);
  delayMicroseconds(2000);
  digitalWrite(Step, LOW);
  delayMicroseconds(2000);
  }
}
}

A+

C'est bon, il fallait mettre etatBouton = digitalRead(Bouton); dans le wile.