user49493: Note: Before i explain my issue i would like to note that I am a beginner in electronics. Please pay attention to that when providing solutions and explanations. Thank you.
I have succeeded at making an auto ranging Ohmmeter it is still ofcours experimental there for I would like to get some opinions and perhaps solutions to some of the issues I’m facing 
How it works:
It is based on a simple voltage divider. After experimenting it seems that a voltage drop across the unknown resistor in a certain range (this case [3.135V, 0.99V] with a voltage source equal to 3.3V) gives the most precise results compared to other values.
This Ohmmeter has a very useful feature and that is auto ranging, it changes the range automatically when the voltage drop values are not in the previously mentioned interval ([3.135V, 0.99V]).
The accompanied image shows how the device works.
If the value of Rx is too small compared to (R1+R2+R3) the Arduino switches the analog reading from A0 to A1 if the problem still accurse the Arduino will change again to A2 meaning it is now measuring not the value of Rx but (Rx+R1+R2) in series after that the Arduino is programmed to do the subtraction accordingly.
This device presents some noticeable inconvenients  that need to be eliminated:

It depends on experimental values, so it is not certain if it’ll
function properly in different conditions.
For accurate (still not exact) measurements the value of Rx has to be greater than R1
It provides acceptable measurements compared to the actual value with an error that is not too big (less than 1% relative error) the precision was obtained by the use of some of the arduino functions (such as voltage reference) also I have chosen the voltage source to be 3.3V instead of 5V to reduce noise, now if one wishes to use a different microcontroller other than arduino will it still be possible to obtain the same precision.

I would like to know your professional opinion regarding these inconvenients and if you may solutions for them, I have accompanied the code for better understanding.
Thank you
#include <ResponsiveAnalogRead.h>
ResponsiveAnalogRead analogPin0(A0, true);
ResponsiveAnalogRead analogPin1(A1, true);
ResponsiveAnalogRead analogPin2(A2, true);

int raw1= 0,raw2=0,raw3=0;
int Vin= 3.3;
float Vout1= 0,Vout2=0,Vout3=0;

float R1= 10000,R2=100000,R3=1000000;
float Rx= 0;
float buffer= 0;

void setup()
{
  analogReference(EXTERNAL);

Serial.begin(9600);
}

void loop()
{
  analogPin0.update();
  analogPin1.update();
  analogPin2.update();
raw1=analogPin0.getValue();
buffer= raw1 * Vin;
Vout1= (buffer)/1024.0;
if(Vout1<=3.135&&Vout1>=0.99) //firstif
{

buffer= (Vin/Vout1) -1;
Rx= (R1+R2+R3) * buffer;
Serial.print("Vout1: ");
Serial.println(Vout1);
Serial.print("Rx: ");
Serial.println(Rx);
delay(1000);
}
   else //else1 of first if
   {

   raw2=analogPin1.getValue();
   buffer= raw2 * Vin;
   Vout2= (buffer)/1024.0;
      if(Vout2<=3.135&&Vout2>=0.99) //second if of first else
      {
      buffer= (Vin/Vout2) -1;
      Rx= (R2+R3) * buffer;
      Rx=Rx-R1;
      Serial.print("Vout2: ");
      Serial.println(Vout2);
      Serial.print("Rx: ");
      Serial.println(Rx);
      delay(1000);
      }
      else 
      {
      raw3=analogPin2.getValue();
      buffer= raw3 * Vin;
      Vout3= (buffer)/1024.0;
          if(Vout3<=3.135&&Vout3>=0.99)
          {
          buffer= (Vin/Vout3) -1;
          Rx= R3 * buffer;
          Rx=Rx-(R1+R2);
          Serial.print("Vout3: ");
          Serial.println(Vout3);
          Serial.print("Rx: ");
          Serial.println(Rx);
          delay(1000);
          }
       }
   }
}

======================================================

to jot here are the results as i have previously explained the ohmmeter worked pretty well at the beginning but when i turned it off Then back on the value measured changed, the error got much bigger i tried changing the caliber aka R1 from 220 to 100 but the results were the same, the error was still big
thank you 



user30198: The answer by @EdgarBonet seems to be a very nice solution for the lowered output voltage of a pin, when a low resistor value is used.
A arduino uno pin can output 20mA without problem, even up to 40mA if needed. So a safe value to measure low resistor values is 220 ohm, which could result in a maximum of 23mA.  
Analog input A1 is used both as digital output to power the circuit and also as a analog input to measure how much the voltage has dropped.
This is a quick test:
// Using the idea in the answer by Edgar Bonet
//
// Allow that the voltage of a digital output is
// lowered by the low resistor value,
// to calculate the unknown resistor.
//
// With two resistors in series.
// A1 - 220 ohm - A0 - 10 ohm - GND
//
// The circuit is a voltage divider.
// A1 powers the voltage divider.
// A0 measures the output.

#define R1 220
#define N_SAMPLES 10

void setup() {
  Serial.begin(9600);
  pinMode(A1,OUTPUT);
  digitalWrite(A1, HIGH);
}

void loop() {

  // Pin A1 is already set as a digital output and set HIGH.
  // Using analogRead(A1) is to measure the real output
  // voltage. There is a voltage drop, because of the current.
  float Vin = averageRead(A1);
  Serial.print("Vin=");
  Serial.print(Vin);

  float Vout = averageRead(A0);
  Serial.print(" Vout=");
  Serial.print(Vout);

  if(Vin > 0.0 && Vout < Vin) {
    float Vt = Vout / Vin;
    float Rx = (Vt * R1) / (1 - Vt);
    Serial.print(" Rx=");
    Serial.println(Rx);
  }

  delay(500);
}

float averageRead(int analogPin) {
  int total = 0;
  for(int i=0; i<N_SAMPLES; i++) {
    total += analogRead(analogPin);
  }
  return float(total) / N_SAMPLES;
}

That is very nice. It is no problem when the unknown resistor is 10 ohm.
Because of the low resistor values, I did not add delays. With high resistor values, some delay is needed before measuring the analog values.
The next step is to find the best value by finding the value that is the most in the middle, as Edgar Bonet has explained in his answer.  
// Autoranging by finding the value that is most in the middle.
// Using the answer by Edgar Bonet

#define N_SAMPLES 10          // the number of samples to average, maximum 30

// Four resistors to power the circuit (one at a time).
// A1 has a resistor of 220 ohm, A2 has 3k3, A3 47k, and A4 750k
// The other leg of the resistors are all connected to A0.
// The unknown resistor Rx is at pin A0 and GND.
const float R[4] = {220.0, 3300.0, 47000.0, 750000.0};
const int pinR[4] = {A1, A2, A3, A4};
const unsigned long wait[4] = {1, 2, 4, 10};  // delay, values guessed.
const int pinMeasure = A0;

void setup() {
  Serial.begin(9600);
  Serial.println("Autoranging");
}

void loop() {
  float Vin[4];    // Vin is the pin that powers the circuit
  float Vout[4];   // Vout is the voltage over the unknown resistor

  for(int i=0; i<4; i++) {
    // Power the circuit with this resistor
    pinMode(pinR[i], OUTPUT);
    digitalWrite(pinR[i], HIGH);

    // Vin is the pin that powers the circuit.
    // This is always low impedance, no need to wait.
    Vin[i]  = averageRead(pinR[i]);

    // Extra delay to wait for the voltage to become steady,
    // before reading the analog data.
    // Might be needed for the higest resistor values
    // Perhaps there is a cable to the unknown resistor
    // that has capacitance.
    delay(wait[i]);

    // The first 'analogread()' sets the multiplexer.
    // For a high impedance circuit, the first
    // 'analogread()' might be less acurate.
    // Read it a few times, and throw it away.
    averageRead(pinMeasure);

    // Everything is settled by now.
    // Read the analog input for real.
    Vout[i] = averageRead(pinMeasure);

    pinMode(pinR[i], INPUT);  // Make this pin high impedance
  }

  // Find the value for Vout that is the most in the middle.
  // For an Arduino Uno, the middle ADC value is 512.
  float diff = 2000.0; // set to value higher than possible as default
  int best = 0;        // index of the best resistor

  for(int i=0; i<4; i++) {
    float d = fabs(512.0 - Vout[i]); // difference for this resistor
    if(d < diff) {                   // closer to the middle?
      diff = d;                      // remember new difference
      best = i;                      // remember index best resistor
    }
  }

  if(Vin[best] <= 0.0) {
    Serial.println("Something wrong with the circuit");
  }
  else if(Vout[best] >= Vin[best]) {
    Serial.println("Rx not connected");
  }
  else {
    float Vt = Vout[best] / Vin[best];     // temporary precalculation
    float Rx = (Vt * R[best]) / (1 - Vt);  // calculate unknown resistor

    Serial.print(" Rx=");
    Serial.print(Rx);
    Serial.print(" ohm (with resistor ");
    Serial.print(R[best]);
    Serial.print(")");
    Serial.println();
  }

  delay(250);
}

float averageRead(int analogPin) {
  int total = 0;
  for(int i=0; i<N_SAMPLES; i++) {
    total += analogRead(analogPin);
  }
  total += N_SAMPLES / 2;  // see www.gammon.com.au/adc
  return(float(total) / float(N_SAMPLES));
}

I would like to add a capacitor from A0 to GND (parallel with the unknown resistor) to reduce noise. This capacitor should be 1nF or less. The delay in the code is large enough to wait for the voltage to settle with 1nF.
The increase of the resistors by 15 times is a large step. That makes it less accurate, but the arduino uno has only 6 analog inputs. By using 5 resistors with an increase of 6 times is better.
4 resistors 15x : 220, 3k3, 47k, 750k
5 resistors 6x  : 220, 1k2, 8k2, 47k, 270k
There are a few ways to do more:

When two resistors result in a output that is close to the middle, it is possible to average the results.
When the 5 resistors are used, it is for example possible to lower the value of the 8k2 resistor. When all higher values are turned on, the resulting resistor value becomes 6k8 instead of 8k2.
For high resistor values, the output voltage of a pin is not lowered, and digital outputs can be used as well.

An protection resistor for A0 might be needed. I think that a value of 470 ohm or 1k should be fine.
Many thanks to @EdgarBonet, I used his answer and added the average and the delay.

Update November 2018
@RekaiaDraoui
When using a breadboard, there can be contacts which are not perfect. That can cause a lot of troubles.
Are you using a circuit as this:


user7508: As you probably already know, the standard setup for measuring a
resistance with an Arduino is to put the unknown resistor in series with
a known one between 5V and GND, and measure the voltage at the point
in-between them:
     5V
     │
     R₁
 A0 ─┤
     R
     │
    GND

where R is the unknown resistor and R1 is the known
reference. The resistance is then computed as:
const float R1 = ...;  // reference resistance

int reading = analogRead(A0);
float R = (float) reading / (1024 - reading) * R1;

First, it is worth noting that the reference voltage does not appear in
this calculation. You could, of course, do the calculation in terms of
voltage, but you should then notice that the reference voltage can be
simplified away. This is not surprising if you realize than the ADC of
the Arduino does not actually measure a voltage: it rather measures a
voltage ratio: the ratio of the input voltage to the reference
voltage. This ratio can then be easily related to the resistance ratio
R/R1. What all this implies is that you should not expect to
get better accuracy by using a 3.3 V reference rather than
5 V. Any inaccuracy in the voltage reference is irrelevant to the
measurement of the resistance.
Next, when measuring a physical quantity, you are almost always
interested in the relative rather than the absolute accuracy. From
the equation above, it can be easily shown that you get the best
relative resolution when the reading is near the middle of the ADC
range:
raw reading    │   64 │  128 │  256 │  512 │  768 │  896 │  960
───────────────┼──────┼──────┼──────┼──────┼──────┼──────┼──────
resolution (%) │ 1.67 │ 0.89 │ 0.52 │ 0.39 │ 0.52 │ 0.89 │ 1.67

This is consistent with your observations, and it means that the
reference resistor should ideally have a value that is of the same order
as the unknown resistor.
Now, for the autoranging, I would advise you against putting all your
reference resistors in series. With this setup, you always have the same
voltage across the unknown resistor, irrespective of what range you
choose. Reading a different input does not help. You may find out that
the voltage between R1 and R2 gives a better
reading (closer to mid-range), and you get a better accuracy on the
measurement of R+R1. However, when you subtract R1
you are immediately degrade the relative accuracy of the result. In
the end you cannot really improve the accuracy this way.
What I suggest is to put the reference resistors in parallel instead of
in series, and power each one from an analog pin:
     A1  A2  A3
     │   │   │
     R₁  R₂  R₃
 A0 ─┼───┴───┴── ...
     R
     │
    GND

You then use these analog pins in digital mode: all of then in INPUT
mode, except one which is set to OUTPUT HIGH. You can try all of
them in turn and select whichever gives a result closer to mid-range. Or
you can implement a smarter algorithm that finds the optimal one without
trying them all.
There is something to be aware of with this setup: the pins have an
output resistance that is about 25 Ω, which ends up being in series
with the corresponding reference resistors. You can account for that by
adjusting, in your code, the values of those references. But then that
output resistance is not very well known, and can vary with temperature.
This should only be an issue when you are in the low ranges though. You
can mitigate this problem by measuring the voltage at the pin that is
currently pulling up, and replacing 1024 in the equation for R by that
reading. That's why I suggest to use analog instead of digital pins.
Finally, there are a couple of limitations that you should be aware of
when measuring resistances with the Arduino ADC. At the low end of the
resistance range, you cannot use a reference resistor with a very low
value, because you have to make sure you do not pull more than about
20 mA from the pin that pulls up. Your smallest reference may then
end up being somewhere around 220 Ω, and you will loose significant
accuracy when you try to measure anything below 50 Ω. At the upper
end of the range, you should be aware that the ADC is meant to measure
voltage sources with an output resistance no larger than 10 kΩ,
otherwise you risk cross-talk between the ADC channels. Then your higher
reference should probably be 10 kΩ, and any measurement above
50 kΩ will give poor accuracy. Going past these limitations would
require extra electronics, like a good-quality op-amp to “condition” the
signal into something that the ADC can reliably measure.

49493: <p>Note: Before i explain my issue i would like to note that I am a beginner in electronics. Please pay attention to that when providing solutions and explanations. Thank you.</p>

<p>I have succeeded at making an auto ranging Ohmmeter it is still ofcours experimental there for I would like to get some opinions and perhaps solutions to some of the issues I’m facing 
How it works:</p>

<p>It is based on a simple voltage divider. After experimenting it seems that a voltage drop across the unknown resistor in a certain range (this case [3.135V, 0.99V] with a voltage source equal to 3.3V) gives the most precise results compared to other values.</p>

<p>This Ohmmeter has a very useful feature and that is auto ranging, it changes the range automatically when the voltage drop values are not in the previously mentioned interval ([3.135V, 0.99V]).
The accompanied image shows how the device works.</p>

<p>If the value of Rx is too small compared to (R1+R2+R3) the Arduino switches the analog reading from A0 to A1 if the problem still accurse the Arduino will change again to A2 meaning it is now measuring not the value of Rx but (Rx+R1+R2) in series after that the Arduino is programmed to do the subtraction accordingly.</p>

<p>This device presents some noticeable inconvenients  that need to be eliminated:</p>

<ol>
<li><p>It depends on experimental values, so it is not certain if it’ll
function properly in different conditions.</p></li>
<li><p>For accurate (still not exact) measurements the value of Rx has to be greater than R1</p></li>
<li>It provides acceptable measurements compared to the actual value with an error that is not too big (less than 1% relative error) the precision was obtained by the use of some of the arduino functions (such as voltage reference) also I have chosen the voltage source to be 3.3V instead of 5V to reduce noise, now if one wishes to use a different microcontroller other than arduino will it still be possible to obtain the same precision.</li>
</ol>

<p>I would like to know your professional opinion regarding these inconvenients and if you may solutions for them, I have accompanied the code for better understanding.</p>

<h1>Thank you</h1>

<pre><code>#include &lt;ResponsiveAnalogRead.h&gt;
ResponsiveAnalogRead analogPin0(A0, true);
ResponsiveAnalogRead analogPin1(A1, true);
ResponsiveAnalogRead analogPin2(A2, true);

int raw1= 0,raw2=0,raw3=0;
int Vin= 3.3;
float Vout1= 0,Vout2=0,Vout3=0;

float R1= 10000,R2=100000,R3=1000000;
float Rx= 0;
float buffer= 0;

void setup()
{
  analogReference(EXTERNAL);

Serial.begin(9600);
}

void loop()
{
  analogPin0.update();
  analogPin1.update();
  analogPin2.update();
raw1=analogPin0.getValue();
buffer= raw1 * Vin;
Vout1= (buffer)/1024.0;
if(Vout1&lt;=3.135&amp;&amp;Vout1&gt;=0.99) //firstif
{

buffer= (Vin/Vout1) -1;
Rx= (R1+R2+R3) * buffer;
Serial.print("Vout1: ");
Serial.println(Vout1);
Serial.print("Rx: ");
Serial.println(Rx);
delay(1000);
}
   else //else1 of first if
   {

   raw2=analogPin1.getValue();
   buffer= raw2 * Vin;
   Vout2= (buffer)/1024.0;
      if(Vout2&lt;=3.135&amp;&amp;Vout2&gt;=0.99) //second if of first else
      {
      buffer= (Vin/Vout2) -1;
      Rx= (R2+R3) * buffer;
      Rx=Rx-R1;
      Serial.print("Vout2: ");
      Serial.println(Vout2);
      Serial.print("Rx: ");
      Serial.println(Rx);
      delay(1000);
      }
      else 
      {
      raw3=analogPin2.getValue();
      buffer= raw3 * Vin;
      Vout3= (buffer)/1024.0;
          if(Vout3&lt;=3.135&amp;&amp;Vout3&gt;=0.99)
          {
          buffer= (Vin/Vout3) -1;
          Rx= R3 * buffer;
          Rx=Rx-(R1+R2);
          Serial.print("Vout3: ");
          Serial.println(Vout3);
          Serial.print("Rx: ");
          Serial.println(Rx);
          delay(1000);
          }
       }
   }
}
</code></pre>

<p>======================================================
<a href="https://i.stack.imgur.com/4S4s8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4S4s8.png" alt="Circuit"></a></p>

<p>to jot here are the results as i have previously explained the ohmmeter worked pretty well at the beginning but when i turned it off Then back on the value measured changed, the error got much bigger i tried changing the caliber aka R1 from 220 to 100 but the results were the same, the error was still big
thank you </p>

<p><a href="https://i.stack.imgur.com/8xJ4L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8xJ4L.png" alt="first measurment "></a></p>

<p><a href="https://i.stack.imgur.com/6CgRr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6CgRr.png" alt="after"></a></p>
 30198: <p>The answer by @EdgarBonet seems to be a very nice solution for the lowered output voltage of a pin, when a low resistor value is used.</p>

<p>A arduino uno pin can output 20mA without problem, even up to 40mA if needed. So a safe value to measure low resistor values is 220 ohm, which could result in a maximum of 23mA.  </p>

<p>Analog input A1 is used both as digital output to power the circuit and also as a analog input to measure how much the voltage has dropped.</p>

<p>This is a quick test:</p>

<pre><code>// Using the idea in the answer by Edgar Bonet
//
// Allow that the voltage of a digital output is
// lowered by the low resistor value,
// to calculate the unknown resistor.
//
// With two resistors in series.
// A1 - 220 ohm - A0 - 10 ohm - GND
//
// The circuit is a voltage divider.
// A1 powers the voltage divider.
// A0 measures the output.

#define R1 220
#define N_SAMPLES 10

void setup() {
  Serial.begin(9600);
  pinMode(A1,OUTPUT);
  digitalWrite(A1, HIGH);
}

void loop() {

  // Pin A1 is already set as a digital output and set HIGH.
  // Using analogRead(A1) is to measure the real output
  // voltage. There is a voltage drop, because of the current.
  float Vin = averageRead(A1);
  Serial.print("Vin=");
  Serial.print(Vin);

  float Vout = averageRead(A0);
  Serial.print(" Vout=");
  Serial.print(Vout);

  if(Vin &gt; 0.0 &amp;&amp; Vout &lt; Vin) {
    float Vt = Vout / Vin;
    float Rx = (Vt * R1) / (1 - Vt);
    Serial.print(" Rx=");
    Serial.println(Rx);
  }

  delay(500);
}

float averageRead(int analogPin) {
  int total = 0;
  for(int i=0; i&lt;N_SAMPLES; i++) {
    total += analogRead(analogPin);
  }
  return float(total) / N_SAMPLES;
}
</code></pre>

<p>That is very nice. It is no problem when the unknown resistor is 10 ohm.</p>

<p>Because of the low resistor values, I did not add delays. With high resistor values, some delay is needed before measuring the analog values.</p>

<p>The next step is to find the best value by finding the value that is the most in the middle, as Edgar Bonet has explained in his answer.  </p>

<pre><code>// Autoranging by finding the value that is most in the middle.
// Using the answer by Edgar Bonet

#define N_SAMPLES 10          // the number of samples to average, maximum 30

// Four resistors to power the circuit (one at a time).
// A1 has a resistor of 220 ohm, A2 has 3k3, A3 47k, and A4 750k
// The other leg of the resistors are all connected to A0.
// The unknown resistor Rx is at pin A0 and GND.
const float R[4] = {220.0, 3300.0, 47000.0, 750000.0};
const int pinR[4] = {A1, A2, A3, A4};
const unsigned long wait[4] = {1, 2, 4, 10};  // delay, values guessed.
const int pinMeasure = A0;

void setup() {
  Serial.begin(9600);
  Serial.println("Autoranging");
}

void loop() {
  float Vin[4];    // Vin is the pin that powers the circuit
  float Vout[4];   // Vout is the voltage over the unknown resistor

  for(int i=0; i&lt;4; i++) {
    // Power the circuit with this resistor
    pinMode(pinR[i], OUTPUT);
    digitalWrite(pinR[i], HIGH);

    // Vin is the pin that powers the circuit.
    // This is always low impedance, no need to wait.
    Vin[i]  = averageRead(pinR[i]);

    // Extra delay to wait for the voltage to become steady,
    // before reading the analog data.
    // Might be needed for the higest resistor values
    // Perhaps there is a cable to the unknown resistor
    // that has capacitance.
    delay(wait[i]);

    // The first 'analogread()' sets the multiplexer.
    // For a high impedance circuit, the first
    // 'analogread()' might be less acurate.
    // Read it a few times, and throw it away.
    averageRead(pinMeasure);

    // Everything is settled by now.
    // Read the analog input for real.
    Vout[i] = averageRead(pinMeasure);

    pinMode(pinR[i], INPUT);  // Make this pin high impedance
  }

  // Find the value for Vout that is the most in the middle.
  // For an Arduino Uno, the middle ADC value is 512.
  float diff = 2000.0; // set to value higher than possible as default
  int best = 0;        // index of the best resistor

  for(int i=0; i&lt;4; i++) {
    float d = fabs(512.0 - Vout[i]); // difference for this resistor
    if(d &lt; diff) {                   // closer to the middle?
      diff = d;                      // remember new difference
      best = i;                      // remember index best resistor
    }
  }

  if(Vin[best] &lt;= 0.0) {
    Serial.println("Something wrong with the circuit");
  }
  else if(Vout[best] &gt;= Vin[best]) {
    Serial.println("Rx not connected");
  }
  else {
    float Vt = Vout[best] / Vin[best];     // temporary precalculation
    float Rx = (Vt * R[best]) / (1 - Vt);  // calculate unknown resistor

    Serial.print(" Rx=");
    Serial.print(Rx);
    Serial.print(" ohm (with resistor ");
    Serial.print(R[best]);
    Serial.print(")");
    Serial.println();
  }

  delay(250);
}

float averageRead(int analogPin) {
  int total = 0;
  for(int i=0; i&lt;N_SAMPLES; i++) {
    total += analogRead(analogPin);
  }
  total += N_SAMPLES / 2;  // see www.gammon.com.au/adc
  return(float(total) / float(N_SAMPLES));
}
</code></pre>

<p>I would like to add a capacitor from A0 to GND (parallel with the unknown resistor) to reduce noise. This capacitor should be 1nF or less. The delay in the code is large enough to wait for the voltage to settle with 1nF.</p>

<p>The increase of the resistors by 15 times is a large step. That makes it less accurate, but the arduino uno has only 6 analog inputs. By using 5 resistors with an increase of 6 times is better.<br>
4 resistors 15x : 220, 3k3, 47k, 750k<br>
5 resistors 6x  : 220, 1k2, 8k2, 47k, 270k</p>

<p>There are a few ways to do more:</p>

<ul>
<li>When two resistors result in a output that is close to the middle, it is possible to average the results.</li>
<li>When the 5 resistors are used, it is for example possible to lower the value of the 8k2 resistor. When all higher values are turned on, the resulting resistor value becomes 6k8 instead of 8k2.</li>
<li>For high resistor values, the output voltage of a pin is not lowered, and digital outputs can be used as well.</li>
</ul>

<p>An protection resistor for A0 might be needed. I think that a value of 470 ohm or 1k should be fine.</p>

<p><strong>Many thanks to @EdgarBonet</strong>, I used his answer and added the average and the delay.</p>

<hr>

<p>Update November 2018</p>

<p>@RekaiaDraoui</p>

<p>When using a breadboard, there can be contacts which are not perfect. That can cause a lot of troubles.</p>

<p>Are you using a circuit as this:</p>

<p><a href="https://i.stack.imgur.com/EfSb8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EfSb8.png" alt="Autoranging with reading the powering voltages"></a></p>
 7508: <p>As you probably already know, the standard setup for measuring a
resistance with an Arduino is to put the unknown resistor in series with
a known one between 5V and GND, and measure the voltage at the point
in-between them:</p>

<pre><code>     5V
     │
     R₁
 A0 ─┤
     R
     │
    GND
</code></pre>

<p>where R is the unknown resistor and R<sub>1</sub> is the known
reference. The resistance is then computed as:</p>

<pre class="lang-c++ prettyprint-override"><code>const float R1 = ...;  // reference resistance

int reading = analogRead(A0);
float R = (float) reading / (1024 - reading) * R1;
</code></pre>

<p>First, it is worth noting that the reference voltage does not appear in
this calculation. You could, of course, do the calculation in terms of
voltage, but you should then notice that the reference voltage can be
simplified away. This is not surprising if you realize than the ADC of
the Arduino does not actually measure a voltage: it rather measures a
voltage <em>ratio</em>: the ratio of the input voltage to the reference
voltage. This ratio can then be easily related to the resistance ratio
R/R<sub>1</sub>. What all this implies is that you should not expect to
get better accuracy by using a 3.3&nbsp;V reference rather than
5&nbsp;V. Any inaccuracy in the voltage reference is irrelevant to the
measurement of the resistance.</p>

<p>Next, when measuring a physical quantity, you are almost always
interested in the <em>relative</em> rather than the <em>absolute</em> accuracy. From
the equation above, it can be easily shown that you get the best
relative resolution when the reading is near the middle of the ADC
range:</p>

<pre><code>raw reading    │   64 │  128 │  256 │  512 │  768 │  896 │  960
───────────────┼──────┼──────┼──────┼──────┼──────┼──────┼──────
resolution (%) │ 1.67 │ 0.89 │ 0.52 │ 0.39 │ 0.52 │ 0.89 │ 1.67
</code></pre>

<p>This is consistent with your observations, and it means that the
reference resistor should ideally have a value that is of the same order
as the unknown resistor.</p>

<p>Now, for the autoranging, I would advise you against putting all your
reference resistors in series. With this setup, you always have the same
voltage across the unknown resistor, irrespective of what range you
choose. Reading a different input does not help. You may find out that
the voltage between R<sub>1</sub> and R<sub>2</sub> gives a better
reading (closer to mid-range), and you get a better accuracy on the
measurement of R+R<sub>1</sub>. However, when you subtract R<sub>1</sub>
you are immediately degrade the <em>relative</em> accuracy of the result. In
the end you cannot really improve the accuracy this way.</p>

<p>What I suggest is to put the reference resistors in parallel instead of
in series, and power each one from an analog pin:</p>

<pre><code>     A1  A2  A3
     │   │   │
     R₁  R₂  R₃
 A0 ─┼───┴───┴── ...
     R
     │
    GND
</code></pre>

<p>You then use these analog pins in digital mode: all of then in <code>INPUT</code>
mode, except one which is set to <code>OUTPUT</code> <code>HIGH</code>. You can try all of
them in turn and select whichever gives a result closer to mid-range. Or
you can implement a smarter algorithm that finds the optimal one without
trying them all.</p>

<p>There is something to be aware of with this setup: the pins have an
output resistance that is about 25&nbsp;Ω, which ends up being in series
with the corresponding reference resistors. You can account for that by
adjusting, in your code, the values of those references. But then that
output resistance is not very well known, and can vary with temperature.
This should only be an issue when you are in the low ranges though. You
can mitigate this problem by measuring the voltage at the pin that is
currently pulling up, and replacing <code>1024</code> in the equation for R by that
reading. That's why I suggest to use analog instead of digital pins.</p>

<p>Finally, there are a couple of limitations that you should be aware of
when measuring resistances with the Arduino ADC. At the low end of the
resistance range, you cannot use a reference resistor with a very low
value, because you have to make sure you do not pull more than about
20&nbsp;mA from the pin that pulls up. Your smallest reference may then
end up being somewhere around 220&nbsp;Ω, and you will loose significant
accuracy when you try to measure anything below 50&nbsp;Ω. At the upper
end of the range, you should be aware that the ADC is meant to measure
voltage sources with an output resistance no larger than 10&nbsp;kΩ,
otherwise you risk cross-talk between the ADC channels. Then your higher
reference should probably be 10&nbsp;kΩ, and any measurement above
50&nbsp;kΩ will give poor accuracy. Going past these limitations would
require extra electronics, like a good-quality op-amp to “condition” the
signal into something that the ADC can reliably measure.</p>
