# Arduino Auto Ranging Ohmmeter, Part 1

An Arduino auto ranging ohmmeter is easy to implement using an Arduino Uno or other Arduino development boards. And depending on the implementation, it can rival the accuracy of commercial digital ohmmeters available in the market.

To better appreciate an auto ranging Arduino ohmmeter, let us first create a simple ohmmeter using an Arduino Uno development board. After studying the underlying theory behind its operation, we will assemble a more accurate, full-pledged auto ranging ohmmeter.

## The Simple Arduino Ohmmeter

A simple Arduino ohmmeter schematic diagram is shown below. It uses an Arduino Uno development board and a 10kΩ reference resistor (Rref) in series with the resistor being tested (Rx).

The following Arduino IDE sketch will display the value of the unknown resistor Rx on the Arduino IDE’s serial monitor.

#define Rref 10000.0

void setup() {
Serial.begin(9600);
}

void loop()
{
float Rx = Rref * x/(1024 - x);
Serial.println(Rx);
delay(2000);
}


Here is a screenshot of the output of the sketch shown above. A resistor with a value of 4.7kΩ and a tolerance of 1% was used as Rx.  The output shows a value of 4.670kΩ.  However, it sometimes fluctuates to 4.649kΩ.  The measured value looks close enough to the actual value of the resistor.   Considering that a 1% tolerance is equal to 47Ω, we expect to get a value between 4.653kΩ and 4.747kΩ.

## Prelude to Arduino Auto Ranging Ohmmeter

### How is resistance measured?

In an Arduino ohmmeter, the unknown resistance of a resistor is measured indirectly using Ohm’s Law.

The Current (I) flowing into a circuit is equal to the impressed Voltage (V) divided by the circuit Resistance (R).

Ohm’s Law

$\fn_jvn&space;{\color{Blue}&space;\textup&space;I=\frac{\textup&space;V}{\textup&space;R}}\qquad\qquad&space;\textup&space;{Ohm's&space;Law}$

Using the above equation, if we know the voltage (V) across the resistor and the current (I) flowing through it, we can calculate its resistance value.

The voltage (V) across the resistor is easily measured by connecting it to the ADC (Analog to Digital Converter) pin of an Arduino development board. But we need a way to calculate the Current (I) flowing thru it so we can compute the Resistance R.

### The Voltage Divider Circuit – Computing the Current (I)

There is a technique used to compute the current (I) thru an unknown resistor. The technique involves placing another resistor with a known value in series with the unknown resistor. The resulting circuit is known as a Voltage Divider Circuit. Please see Figure 4 below.

In the voltage divider circuit above, Rref is the resistor of a known value and Rx is the unknown resistor being measured. VRx will be read and measured by an ADC, hence, let us assume that this is a known voltage.

The input voltage Vref is divided between the two resistors in series, Rref and Rx. Therefore,

$\fn_jvn&space;{\color{Blue}&space;\textup&space;V_{\textup&space;{ref}}=\textup&space;V_{\textup&space;{Rref}}+\textup&space;V_{\textup&space;{Rx}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;0.1)}}$

and the voltage VRref across the known resistor Rref is,

$\fn_jvn&space;{\color{Blue}&space;\textup&space;V_{\textup&space;{Rref}}=\textup&space;V_{\textup&space;{ref}}-\textup&space;V_{\textup&space;{Rx}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;0.2)}}$

Since Rref is of a known resistance and we already know the voltage across it, we can now compute the value of IRref, the current passing thru it.

$\fn_jvn&space;{\color{Blue}\textup&space;I_{\textup&space;{Rref}}=\frac{\textup&space;V_{\textup&space;{Rref}}}{\textup&space;R_\textup&space;{ref}}=\frac{\textup&space;V_{\textup&space;{ref}}-\textup&space;V_{\textup&space;{Rx}}}{\textup&space;R_{\textup&space;{ref}}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;0.3)}}$

The current IRref is the same current flowing thru the unknown resistor Rx. So, it follows that,

$\fn_jvn&space;{\color{Blue}\textup&space;I_{\textup&space;{Rx}}=\textup&space;I_{\textup&space;{Rref}}=\frac{\textup&space;V_{\textup&space;{ref}}-\textup&space;V_{\textup&space;{Rx}}}{\textup&space;R_{\textup&space;{ref}}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;0.4)}}$

Finally, to compute the resistance of the unknown resistor, Rx, we substitute Equation 0.4 in the resistance formula below.

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{x}}=\frac{\textup&space;V_{\textup&space;{Rx}}}{\textup&space;I_\textup&space;{Rx}}=\frac{\textup&space;V_{\textup&space;{Rx}}}{\frac{\textup&space;V_{\textup&space;{ref}}-\textup&space;V_{\textup&space;{Rx}}}{\textup&space;R_{\textup&space;{ref}}}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;0.5)}}$

Rearranging Equation 0.5, we get the final equation for computing Rx.

$\dpi{120}&space;\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{\textup&space;x}}=\frac{\textup&space;R_{\textup&space;{ref}}*\textup&space;V_{\textup&space;{Rx}}}{{\textup&space;V_{\textup&space;{ref}}-\textup&space;V_{\textup&space;{Rx}}}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;1)}}$

### Analog to Digital Converter – Measuring Voltage Across the Resistor

The voltage across the resistor being measured is fed to the ADC of an Arduino development board. Arduino Uno’s ADC has a resolution of 10 bits or 210, which is equal to 1024. This means that the reference voltage for the ADC is divided by 1024. Representing the ADC output reading with the variable x, VRx can be computed using the formula:

$\dpi{120}&space;\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{\textup&space;{Rx}}}=\frac{\textup&space;V_{\textup&space;{ref}}}{1024}*\textup&space;x}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;2.0)}}$

Also, given the value of VRx, which is the input to the ADC, we can find the value of x by using the formula:

$\dpi{120}&space;\fn_jvn&space;{\color{Blue}\textup&space;x=\frac{1024}{\textup&space;V_{\textup&space;{ref}}}*\textup&space;V_{\textup&space;{Rx}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;2.1)}}$

Caveat:

The Arduino’s Due, Zero and MKR Family boards have 12-bit ADC capabilities but are by default set to 10-bit resolution. If they are run in 12-bit resolution by calling analogReadResolution(12), the constant 1024 must be replaced with 4096.

Using Equation 1 and Equation 2.0 as mentioned above, we can compute the value of the unknown resistor Rx if we have the ADC output reading x.

In an Arduino IDE sketch, we may use the following code to compute the value of Rx:

#define Rref 10000.0

void setup() {
float Vrx = x * 5.0/1024  //compute voltage across resistor
float Rx = Rref * Vrx /(5.0-Vrx);  //compute resistance


### Computing Rx as a Function of x

The Equation 1 above for computing the value of the unknown resistor Rx is based on a pre-computed value of VRx. Actually there is a more simple formula for figuring out the value of Rx. The output value x of the ADC can be used to directly compute Rx. The formula is:

$\dpi{120}&space;\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{\textup&space;x}}=\frac{\textup&space;R_{\textup&space;{ref}}*\textup&space;x}{{1024-\textup&space;x}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;3)}}$

Notice the similarity of Equation 1 & Equation 3. The voltages, Vref and VRx, were simply replaced with their equivalent ADC values.

Let’s do a little exercise. We’ll try to prove that Equation 1 and Equation 3 are indeed equal to each other.

First, using the voltage divider circuit in Figure 2, the value of the voltage VRx (again using Ohm’s Law) is,

$\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{Rx}}=\textup&space;I_{\textup&space;Rx}*\textup&space;R_{\textup&space;{x}}=\frac{\textup&space;V_{\textup&space;{ref}}}{\textup&space;R_{\textup{ref}}+\textup&space;R_{\textup&space;x}}*\textup&space;R_{\textup&space;x}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;4)}}$

VRx is fed into the ADC, so we can use Equation 2,

$\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{\textup&space;{Rx}}}=\frac{\textup&space;V_{\textup&space;{ref}}}{1024}*\textup&space;x}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;2.0)}}$

Equating Equation 4 and Equation 2.0, we have,

$\fn_jvn&space;{\color{Blue}\frac{\textup&space;V_{\textup&space;{ref}}}{\textup&space;R_{\textup{ref}}+\textup&space;R_{\textup&space;x}}*\textup&space;R_{\textup&space;x}=\frac{\textup&space;V_{\textup{ref}}}{1024}*\textup&space;x}$

Using the cross multiplication method,

$\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{ref}}*\textup&space;R_{\textup{x}}*1024=(\textup&space;R_{\textup&space;{ref}}+\textup&space;R_\textup&space;x)*\textup&space;V_{\textup&space;{ref}}*\textup&space;x}$

Move Vref and 1024 to the right side of the equation.

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup{x}}=\frac{(\textup&space;R_{\textup&space;{ref}}+\textup&space;R_\textup&space;x)*\textup&space;V_{\textup&space;{ref}}*\textup&space;x}{\textup&space;V_{\textup&space;{ref}}*1024}}$

Cancel out Vref.

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;x}=\frac{\textup&space;x*(\textup&space;R_{\textup&space;{ref}}+\textup&space;R_\textup&space;x)}{1024}}$

We need to remove the variable Rx that is on the right side of the equation. Multiply the terms of the numerator and then separate the two terms.

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;x}=\frac{\textup&space;x*\textup&space;R_{\textup&space;{ref}}}{1024}+\frac{\textup&space;x*\textup&space;R_\textup&space;x}{1024}}$

Move the second term containing the variable Rx to the left side of the equation.

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;x}-\frac{\textup&space;x*\textup&space;R_\textup&space;x}{1024}=\frac{\textup&space;x*\textup&space;R_\textup&space;{ref}}{1024}}$

Factor out Rx.

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;x}(1-\frac{\textup&space;x}{1024})=\frac{\textup&space;x*\textup&space;R_\textup&space;{ref}}{1024}}$

Multiplying both sides of the equation with 1024, we get,

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;x}(1024-\textup&space;x)=\textup&space;x*\textup&space;R_\textup&space;{ref}}$

Finally move the term in the parenthesis to the right side of the equation.

$\fn_jvn&space;{\color{Blue}\textup&space;R_\textup&space;x=\frac{\textup&space;R_\textup&space;{ref}*\textup&space;x}{{1024-\textup&space;x}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;3)}}$

This shows that we can directly use the ADC output x, which is the value from the analogRead() function, to compute the value of Rx without the need to compute the value of VRx.

### The Ohmmeter Accuracy

Referring to Figure 4 above, let’s compute VRx in terms of the two series resistors.

$\dpi{120}&space;\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{Rx}}=\textup&space;I_{\textup&space;Rx}*\textup&space;R_{\textup&space;{x}}=\frac{\textup&space;V_{\textup&space;{ref}}*\textup&space;R_\textup&space;x}{\textup&space;R_{\textup{ref}}+\textup&space;R_\textup&space;x}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;4)}}$

Now, assume the following resistor values: Rref = 10KΩ and Rx = 10KΩ. Let’s compute VRx using Equation 4.

$\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{Rx}}=\frac&space;{5\textup&space;V*10\textup&space;k\Omega}{10\textup&space;k\Omega+10\textup&space;k\Omega}=2.5\textup&space;V}$

Compute x using Equation 2.1.

$\fn_jvn&space;{\color{Blue}\textup&space;x=\frac{1024}{\textup&space;V_{\textup&space;{ref}}}*\textup&space;V_{\textup&space;{Rx}}}$

$\fn_jvn&space;{\color{Blue}\textup&space;x=\frac{1024*2.5\textup&space;V}{5\textup&space;V}=512}$

Let us do the same computation for the values of Rref = 10KΩ and Rx = 1KΩ.

$\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{Rx}}=\frac&space;{5\textup&space;V*1\textup&space;k\Omega}{10\textup&space;k\Omega+1\textup&space;k\Omega}=\frac{5\textup&space;V}{11}=0.4545\textup&space;V}$

$\fn_jvn&space;{\color{Blue}\textup&space;x=\frac{1024*0.4545\textup&space;V}{5\textup&space;V}=93}$

Again, compute for Rref = 10KΩ and Rx = 100Ω.

$\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{Rx}}=\frac&space;{5\textup&space;V*100\Omega}{10\textup&space;k\Omega+100\Omega}=\frac{500\textup&space;V}{10,100}=0.0495\textup&space;V}$

$\fn_jvn&space;{\color{Blue}\textup&space;x=\frac{1024*0.0495\textup&space;V}{5\textup&space;V}=10}$

Using the three (3) computed ADC values, compute Rx using Equation 3.

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{\textup&space;x}}=\frac{\textup&space;R_{\textup&space;{ref}}*\textup&space;x}{{1024-\textup&space;x}}}\qquad\qquad&space;\textup{\textsc{\scriptsize(Equation&space;3)}}$

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{\textup&space;x}}=\frac{10\textup&space;k\Omega*512}{{1024-\textup&space;512}}=\frac{5120\textup&space;k\Omega}{512}=10\textup&space;k\Omega}$

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{\textup&space;x}}=\frac{10\textup&space;k\Omega*93}{{1024-\textup&space;93}}=\frac{930\textup&space;k\Omega}{931}=0.9989\textup&space;k\Omega}$

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{\textup&space;x}}=\frac{10\textup&space;k\Omega*10}{{1024-\textup&space;10}}=\frac{100\textup&space;k\Omega}{1014}=98.6\Omega}$

Below is a table of the above computations.

 Rref Rx (Actual) VRx ADC (x) Rx (Computed) 10kΩ 10kΩ 2.5V 512 10.00kΩ 10kΩ 1kΩ 0.4545V 93 0.9989kΩ 10kΩ 100Ω 0.0495V 10 98.6Ω

If you compare column 2, Rx (Actual) and column 5, Rx (Computed) of the table shown above, you will notice that there are discrepancies between the actual Rx values and the computed Rx values of row 2 and row 3. Only the first row has the exact value of the computed Rx value. Also, take note that row 2 has a lower discrepancy compared to row 3.

To clearly see the problem, let us take a second set of computations. This time, instead of a 10kΩ Rref, let’s use a value of 1kΩ for Rref

Rref = 1kΩ and Rx = 10kΩ

$\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{Rx}}=\frac&space;{5\textup&space;V*10\textup&space;k\Omega}{1\textup&space;k\Omega+10\textup&space;k\Omega}=\frac{50\textup&space;V}{11}=4.545\textup&space;V}$

$\fn_jvn&space;{\color{Blue}\textup&space;x=\frac{1024*4.545\textup&space;V}{5\textup&space;V}=931}$

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{\textup&space;x}}=\frac{1\textup&space;k\Omega*931}{{1024-931}}=\frac{931\textup&space;k\Omega}{93}=10.01\textup&space;k\Omega}$

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

Rref = 1kΩ and Rx = 1kΩ

$\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{Rx}}=\frac&space;{5\textup&space;V*1\textup&space;k\Omega}{1\textup&space;k\Omega+1\textup&space;k\Omega}=\frac{5\textup&space;V}{2}=2.5\textup&space;V}$

$\fn_jvn&space;{\color{Blue}\textup&space;x=\frac{1024*2.5\textup&space;V}{5\textup&space;V}=512}$

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{\textup&space;x}}=\frac{1\textup&space;k\Omega*512}{{1024-512}}=\frac{512\textup&space;k\Omega}{512}=1\textup&space;k\Omega}$

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

Rref = 1kΩ and Rx = 100Ω

$\fn_jvn&space;{\color{Blue}\textup&space;V_{\textup&space;{Rx}}=\frac&space;{5\textup&space;V*100\Omega}{1\textup&space;k\Omega+100\Omega}=\frac{500\textup&space;V}{1100}=0.4545\textup&space;V}$

$\fn_jvn&space;{\color{Blue}\textup&space;x=\frac{1024*0.4545\textup&space;V}{5\textup&space;V}=93}$

$\fn_jvn&space;{\color{Blue}\textup&space;R_{\textup&space;{\textup&space;x}}=\frac{1\textup&space;k\Omega*93}{{1024-93}}=\frac{93\textup&space;k\Omega}{931}=99.89\Omega}$

Here is the table for the second set of computations.

 Rref Rx (Actual) VRx ADC (x) Rx (Computed) 1kΩ 10kΩ 4.545V 931 10.01K 1kΩ 1kΩ 2.5V 512 1.00K 1kΩ 100Ω 0.4545V 93 99.89 Ohms

Studying the two tables will highlight the facts about the voltage divider circuit being used to measure the resistance of the unknown resistor Rx

• The most accurate measurement of the value of Rx occurs when Rx and Rref are equal.
• The higher the difference of the values of Rx and Rref, the less accurate the measurement will be.

To reduce the error in the measurement of resistance, a solution is to use different values for Rref. It can be implemented by manually switching reference resistors from a bank of resistors during a measurement.

Or better yet, automatically select and switch the proper value of Rref electronically, and controlled by software. That leads us to an Arduino auto ranging ohmmeter.

## References on Arduino Auto Ranging Ohmmeter

Ohmmeter Using Arduino – circuitstoday.com – diode in series with reference resistors
Arduino Based Auto-Ranging Ohmmeter – simple-circuit.com – transistor switch
Resistomatic – an Arduino-based autoranging ohm-meter -blog.rareshool.com – simple resistor bank, no diodes, no transistors
Arduino Digital Multimeter
How accurate is an Arduino Ohmmeter?