Meanwhile consider:
const int analogPin1 = A5;
const int redLed = 8;
const int greenLed = 12;
const float tolerance = 15.0 / 100.0; // 15%
const int limitHigh = 1024.0 / 2.0 + 1024.0 * tolerance;
const int limitLow = 1024.0 / 2.0 - 1024.0 * tolerance;
void setup()
{
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}
void loop()
{
int raw = analogRead(analogPin1);
if (raw < limitLow or raw > limitHigh) {
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
}
delay(100);
}
In this case, it is voltage that is futile, not resistance.
The idea here, is that if the reference resistor and test resistor are the same, the ADC reading will be exactly half full scale. So if you are testing 100k pots, your reference resistor should be a 100k, 1% or better fixed resistor.
My formulas for the limits might need some work because a voltage divider formula isn't linear, but I have a life and have real work to do.