Basically you are reading a voltage to calculate one resistance in a resistive divider.

You know the one resistor value, and you know the reading on the ADC. As long as the voltage on your ADC input remains between 0 and 5V then that voltage can calculated from the ADC reading.

You have a number of values to take into account:

- The full scale voltage is 12V
- The ADC full scale voltage is whatever you have scaled your 0-12V values to.

The unknown resistance basically forms part of a ratio:

Vout = Vin * R2 / (R1 + R2)

so the output voltage is the ratio of R1:R2 multiplied by the input voltage. That output voltage must then be scaled (typically with another resistive divider) to remain within the 0-5V range. Without the extra scaling Vout would be in the range 0 to 12V (infinity ohms to 0 ohms on the top resistor). Scaling that with a 3:1 resistive divider, say, would give a range of 0 to 4V, which is ideal. Other values can be used, too, as long as they fall within the 0-5V range. That top range value is important, as it forms the voltage in note 2 above.

So if the output is then scaled between 0 and 4V, then that is the value you should use in calculating the voltage, and hence the resistance.

The voltage on the ADC is:

ADC * 5 / 1023, or ADC / 1023.0 * 5.0, which ever way around you want to do it.

The 5 is the reference voltage for the ADC (the voltage your board runs at), not the voltage of the incoming reading. So it should return a value between 0 and 4V. You then put that into the resistance calculating formula, but with an upper voltage of 4V, not 5V - note, this is the SCALED voltage, not the SUPPLY voltage.

So your formula, for a 3:1 ratio divider on the input, would be:

((R2 * Vin) / Vout) - R2

Where R2 is your 1K?, Vin is 4V, and Vout is the result of the ADC to voltage calculation, so:

((1000.0 * 4.0) / (float(ADC) / 1023.0 * 5.0)) - 1000.0

Or, simplified:

(4000.0 / (float(ADC) / 5115.0)) - 1000.0