Loop sensor + relay

Hi,
I'm trying to control four relays with a signal from one sensor. The signal comes from a remote sensor. The relay's operation time base is fixed by the elapsed time of the operation from the first relay, the following relays operate with this calculated elapsed time.
My skech runs fine until the value of the signal is received, after that moment the loop doesn't nothing. Only receives constantly the value but doesn't calculate the elapsed time neither the relays operate.
I appreciate very much to anyone who help me.
Regards

    // I check both bytes (or)
      uint8_t analogMSB = rx.getData(0);
      uint8_t analogLSB = rx.getData(1);
      value1 = analogLSB + (analogMSB * 256); 
      Serial.print("V from Sensor 1= ");
      Serial.println(value1);
//       // I check both bytes (or)
//      uint8_t analogMSB1 = rx.getData(2);
//      uint8_t analogLSB1 = rx.getData(3);
//      value2 = analogLSB1 + (analogMSB1 * 256); 
//      Serial.print("V from Sensor 2 = ");
//      Serial.println(value2);
 
 // turn the Relay1 on
 if (value1>=minVal&&value1<= maxVal)
{ 
digitalWrite(Relay1, HIGH);}
 if(digitalRead (Relay1) == HIGH){
//turn on millis
    start=millis();
    delay(100); // for debounce
    Serial.println("Started...");
  if (digitalRead (Relay1) == LOW)
  {
    time = millis();
    finished = millis();
    elapsed = finished - start;
    displayResult();
    delay (100);    
  }
 }
else
{ 
digitalWrite(Relay1, LOW);
}


  //turn on relay 2 during millis period
  if (Relay1 == LOW && Relay3 == LOW && Relay4 == LOW && previous == LOW && millis()- time > debounce)
  {
digitalWrite(Relay2, HIGH);
delay(elapsed);
digitalWrite(Relay2, LOW);
delay (200);
  }
  
  //turn on relay 3 during millis period
  if (Relay1 == LOW && Relay2 == LOW && Relay4 == LOW && previous == LOW && millis()- time > debounce)
  {
digitalWrite(Relay3, HIGH);
delay(elapsed);
digitalWrite (Relay3, LOW);
 }
   delay (200);
  
  //turn on relay 2 during millis period
  if (Relay1 == LOW && Relay2 == LOW && Relay3 == LOW && previous == LOW && millis()- time > debounce)
  {
digitalWrite(Relay4, HIGH);
delay (elapsed);
digitalWrite (Relay4, LOW);
 }
   delay (200);

Series2_Rx.ino (4.96 KB)

//sensor operation range
int minVal = 350; //value between 0 and 1023
int maxVal = 20; //value between 0 and 1023

I think those limits are the wrong way round, so that the test in the if statement later on:

      // turn the Relay1 on
      if (value1 >= minVal && value1 <= maxVal)

can't ever be true.

Right!

Hi Gypsum, Thank you very much! sometimes people need a break to keep the concentration and refresh the objectivity.
The trouble continues with my sketch, now the relays (2, 3, 4) run before the previous one (relay 1) finishes with the if statement (value1 >= maxVal). Additionally, the snnipets "delay(elapsed)" stop the loop,producing the increment of the elapsed time .
Any suggestions will be well received.
Thank you all
Regards

 // turn the Relay1 on
 if (value1>= maxVal){

digitalWrite(Relay1, LOW);}
if (value1<= minVal){
digitalWrite(Relay1, HIGH);}

 if(digitalRead(Relay1) == LOW){
//turn on millis
    start=millis();
    delay(10); // for debounce
    Serial.println("Started...");}
  if (digitalRead (Relay1) == HIGH)
  {
    time = millis();
    finished = millis();
    elapsed = finished - start;
    displayResult();
    delay (10);    
  }

if (value1<=maxVal){
  //turn on relay 2 during millis period
  if (Relay1State == LOW && Relay3State == LOW && Relay4State == LOW && previous == LOW && millis()- time > debounce)
  {
digitalWrite(Relay2, HIGH);
delay(elapsed);
digitalWrite(Relay2, LOW);
delay (20);
  }
  
  //turn on relay 3 during millis period
  if (Relay1State == LOW && Relay2State == LOW && Relay4State == LOW && previous == LOW && millis()- time > debounce)
  {
digitalWrite(Relay3, HIGH);
delay(elapsed);
digitalWrite (Relay3, LOW);
 }
   delay (20);
  
  //turn on relay 2 during millis period
  if (Relay1State == LOW && Relay2State == LOW && Relay3State == LOW && previous == LOW && millis()- time > debounce)
  {
digitalWrite(Relay4, HIGH);
delay (elapsed);
digitalWrite (Relay4, LOW);
 }
   delay (20);
}

Series2_Rx.ino (4.98 KB)