Loop sensor + relay

//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.