The value stop the code

int led = 13; // Alimentation de la bobine
int hall = A0; // Analyse du capteur a effet Hall
long startTime  = 0;                    // start time for stop watch
long elapsedTime = 0 ;



unsigned long valeur; //Donnees directes du capteru a effet Hall
float tension; // Valeur actuelle en voltage du capteur
float pretension; //  Valeur precedente en voltage du capteur

void setup() // Effectuer une seule fois
{
  pinMode (hall, INPUT); // Declarer capteur a effet Hall comme INPUT
  pinMode (led, OUTPUT); // Declarer led comme OUTPUT
  digitalWrite(led, HIGH); 
  delay (500);
  digitalWrite(led, LOW); 
  Serial.begin (38400); // Vitesse du retour des donnees
}


void loop() // Effectuer à chaque fois
{
  pretension = tension; // Tension precedente vs tension actuelle
  valeur = analogRead (hall); // Lecture du capteur a effet Hall
  tension = valeur * 5.0 / 1024; // Formule de calcul du voltage du capteur a effet Hall
  long RPMactuel = 60000000  / elapsedTime;
  long  initime = 0.03 * elapsedTime;
  long elapsed_Time;



  if (2.50 < tension && tension < 2.95)
  {
    if (tension < (pretension - 0.005)) {  // compare them
      elapsedTime =   (micros() - startTime) + initime;   
      startTime = micros(); 
      digitalWrite(led, HIGH); 
      delay (initime);
      digitalWrite(led, LOW); // do something, they are different
      
      while (tension > 2.5){
        valeur = analogRead (hall);
        tension = valeur * 5.0 / 1024;
           if (tension ==  pretension)
        {
           valeur = analogRead (hall);
        tension = valeur * 5.0 / 1024;
          digitalWrite(led, HIGH); 
          delay (20);
          digitalWrite(led, LOW);
          delay (50);
        }
        else {digitalWrite(led, LOW);}
        
      }

    } 
  }



  Serial.print("elapsedTime= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(elapsedTime);
  Serial.print("tension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(tension);	
  Serial.print("pretension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(pretension);
  Serial.print("RPMactuel= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(RPMactuel);	
  Serial.print("initime = ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(initime);



  Serial.println();  // Sauter une ligne lors de l'affichage
  Serial.println();
}

This code don’t work it’s not running the led is not blink.

int led = 13; // Alimentation de la bobine
int hall = A0; // Analyse du capteur a effet Hall
long startTime  = 0;                    // start time for stop watch
long elapsedTime = 0 ;



unsigned long valeur; //Donnees directes du capteru a effet Hall
float tension; // Valeur actuelle en voltage du capteur
float pretension; //  Valeur precedente en voltage du capteur

void setup() // Effectuer une seule fois
{
  pinMode (hall, INPUT); // Declarer capteur a effet Hall comme INPUT
  pinMode (led, OUTPUT); // Declarer led comme OUTPUT
  digitalWrite(led, HIGH); 
  delay (500);
  digitalWrite(led, LOW); 
  Serial.begin (38400); // Vitesse du retour des donnees
}


void loop() // Effectuer à chaque fois
{
  pretension = tension; // Tension precedente vs tension actuelle
  valeur = analogRead (hall); // Lecture du capteur a effet Hall
  tension = valeur * 5.0 / 1024; // Formule de calcul du voltage du capteur a effet Hall
  long RPMactuel = 60000000  / elapsedTime;
  long  initime = 0.3 * elapsedTime;
  long elapsed_Time;



  if (2.50 < tension && tension < 2.95)
  {
    if (tension < (pretension - 0.005)) {  // compare them
      elapsedTime =   (micros() - startTime) + 20000;   
      startTime = micros(); 
      digitalWrite(led, HIGH); 
      delay (20);
      digitalWrite(led, LOW); // do something, they are different
      
      while (tension > 2.5){
        valeur = analogRead (hall);
        tension = valeur * 5.0 / 1024;
           if (tension ==  pretension)
        {
          digitalWrite(led, HIGH); 
          delay (20);
          digitalWrite(led, LOW);
          delay (50);
        }
        else {
          
          digitalWrite(led, LOW);}
        
      }

    } 
  }



  Serial.print("elapsedTime= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(elapsedTime);
  Serial.print("tension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(tension);	
  Serial.print("pretension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(pretension);
  Serial.print("RPMactuel= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(RPMactuel);	
  Serial.print("initime = ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(initime);



  Serial.println();  // Sauter une ligne lors de l'affichage
  Serial.println();
}

but this one works perfectly can someone plz explain me why it’s not working?
thank you

  long RPMactuel = 60000000  / elapsedTime;

is clearly wrong, as 60000000 is outside the range of an int and needs to be
written as a long constant, ie: 60000000L

yeah but I used it in the second code and it works too why the first one is not working

Have you tried my fix on the first version then?

You also appear to be dividing by zero in both versions.

You really expect members to compare two sketches line by line to see what's different between the two versions?

But that said, I see that a difference (and who knows if it's the only difference, since you didn't point it/them out?) is that initime in the top one is 1/10 what it is in the bottom one. So it could be that the LED is on for too short a time for it to seem like it's on and that's why it's not blinking... maybe it IS, just too quickly to see?

Bur really, if you want people to comment on one sketch compared to another, have the sense (read as: courtesy) to point out what you changed.

Better still have only one piece of code with the alternative lines included and one of them commented out. You might even see the problem yourself if the changes are one under the other.

…R

int led = 13; // Alimentation de la bobine
int hall = A0; // Analyse du capteur a effet Hall
long startTime  = 0;                    // start time for stop watch
long elapsedTime = 0 ;



unsigned long valeur; //Donnees directes du capteru a effet Hall
float tension; // Valeur actuelle en voltage du capteur
float pretension; //  Valeur precedente en voltage du capteur

void setup() // Effectuer une seule fois
{
  pinMode (hall, INPUT); // Declarer capteur a effet Hall comme INPUT
  pinMode (led, OUTPUT); // Declarer led comme OUTPUT
  Serial.begin (38400); // Vitesse du retour des donnees
}


void loop() // Effectuer à chaque fois
{
  pretension = tension; // Tension precedente vs tension actuelle
  valeur = analogRead (hall); // Lecture du capteur a effet Hall
  tension = valeur * 5.0 / 1024; // Formule de calcul du voltage du capteur a effet Hall
long RPMactuel = 60000000  / elapsedTime;
  if (2.50 < tension && tension < 2.95)
  {
    if (tension < (pretension - 0.005)) {  // compare them
      elapsedTime =   (micros() - startTime) + 20000;   
      startTime = micros(); 
      digitalWrite(led, HIGH); 
      delay (20);
      digitalWrite(led, LOW); // do something, they are different
while (tension > 2.5){
valeur = analogRead (hall);
tension = valeur * 5.0 / 1024;
digitalWrite(led, LOW);}

    } 
  }


  Serial.print("elapsedTime= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(elapsedTime);
  Serial.print("tension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(tension);	
   Serial.print("RPMactuel= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(RPMactuel);	




  Serial.println();  // Sauter une ligne lors de l'affichage
  Serial.println();
}

this code works but when i enter those values

long initime = 0.03 * elapsedTime;
digitalWrite(led, HIGH); 
      delay (initime);
      digitalWrite(led, LOW); // do something, they are different

why

elapsedTime= 141084
tension= 2.50
RPMactuel= 425


elapsedTime= 141084
tension= 2.45
RPMactuel= 425


elapsedTime= 141084
tension= 2.39
RPMactuel= 425


elapsedTime= 141084
tension= 2.52
RPMactuel= 425

the code aways stops ar that serial print i am trying to figure out why

Have you tried any of the tips that were given yet ?

Don't you see some peculiar stuff in that serial print you posted ?

I do.
The ("tension") voltage changes, but the elapsed time doesn't seem to change, nor does the RPM.

You seem to control some coil (bobine translates to coil, but you're calling it LED) through pin 13.
Do you have a coil attached, and if so did you protect your Arduino from getting damaged by the back EMF that this would cause ?
Also, if you are indeed controlling a coil, are you also using a transistor to handle it's current ?

Great thread title.
So descriptive.