How to write IF/Else using a threshold range of values
To get the light to turn on only when the sensor reading is between two numbers, you should test if the reading is between the two numbers, and if it is, turn on the light.

To test if a value is between two numbers, you could use the &amp;&amp; AND operator to see if both conditions are met.  For example:

if (sensor &gt; loLimit &amp;&amp; sensor &lt; hiLimit) {
    digitalWrite(2, HIGH);
} else {
    digitalWrite(2, LOW);
}


Here's a shorter way to write that:

digitalWrite(2, (sensor &gt; loLimit &amp;&amp; sensor &lt; hiLimit));


In this form, the expression evaluates to 1, or HIGH, if it is true, and to 0, or LOW, if it is false.

Another approach is to test if abs(sensor-midLimit) &lt; halfGap, where midLimit is (loLimit+hiLimit)/2 and halfGap is (hiLimit-loLimit)/2.  Turn on the light if abs(sensor-midLimit) &lt; halfGap, else turn it off.