The code looks basically correct, except you'd probably want it in your loop() rather than your setup().
Analog pins are not exact (they're analog after all). So switching the pin to the middle position - and assuming your resistors are perfectly equal, you normally will have 5% tolerance there already - will give you one time 505, the next time 510, and the third time maybe 508. Try another pin and the values may hover around 516, or even 520. That's why you must include a range for your readings to make this work.
The range of 50 (5% of the scale) is not even enough if you have really bad luck and one resistor is at the top end of the tolerance, and the other is at the bottom end. In practice, though, most will be within 2-3% from the nominal value. But just in case one of your settings doesn't work, do have a Serial print of the value read, and see if it happens to be just out of range and amend your ranges (or replace resistors) accordingly.
By the way, the reading from the analog port is normally used dimensionless. It's a number 0-1023, not a resistance. It's actually a representation of the voltage level measured.
By the way, the reading from the analog port is normally used dimensionless. It's a number 0-1023, not a resistance. It's actually a representation of the voltage level measured.
indeed! :-[
do have a Serial print of the value read, and see if it happens to be just out of range and amend your ranges (or replace resistors) accordingly.
back at home, i print to serial
0 511 1023 are the three values read (for both resistor): that's OK
I made some new investigation and I found that:
range = map(sensorReading,0,1023,0,2);
gives
0 from 0 to 511
1 from 512 to 1022
2 for 1023
range = map(sensorReading,0,1024,0,3);
gives the awaited results
0 from 0 to 341
1 from 341 to 682
2 from 682 to 1023
tadaaa ! it works... and he tutorial linked looks wrong