it's easy to build

### Code

//This is the code to make the arduino function as an ohmmeter
//This code will display the voltage that drops across the unknown resistor //along with its resistance

### Code

//This is the code to make the arduino function as an ohmmeter
//This code will display the voltage that drops across the unknown resistor //along with its resistance

int analogPin= 0;
int raw= 0;
int Vin= 5;
float Vout= 0;
float R1= 1000;
float R2= 0;
float buffer= 0;

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

void loop()
{
if(raw)
{
buffer= raw * Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
R2= R1 * buffer;
Serial.print("Vout: ");
Serial.println(Vout);
Serial.print("R2: ");
Serial.println(R2);
delay(1000);
}
}

We create a variable called analogPin and assign it to 0. This is because the voltage value we are going to read is connected to analogPin A0. This voltage represents the voltage value which falls across the resistor value we are measuring.

Next we create a variable named raw, which we will use to read in the analog voltage value. This later in our code gets assigned to the analogRead() function. This value which will be placed into the raw variable can be between 0 and 1023. 0 would represent 0 volts falls across the unknown resistor. And a value of 1023 would mean that practically all 5 volts falls across the unknown resistor. Being that we are using a reference resistor of 1KΩ, a very small resistor such as 1Ω may make the A0 pin register a value of 0. And a very large resistor, such as 1MΩ would make it read a value of 1023. These are just examples to give you a feel for how the ohmmeter would work with a 1KΩ resistor as its reference resistor.

The next variable, Vin, is assigned to 5 because 5V is being supplied by the arduino to the resistive voltage divider circuit.

The next variable, Vout, is assigned initially to 0. Vout represents the divided voltage that falls across the unknown resistor.

The next variable, R1, represents the reference resistor. In our case, we are using a 1KΩ resistor as our reference, so we set it equal to 1000. If you are going to change the reference resistor to another value, for reasons explained below, you will need to change it in hardware and in software.

The variable, R2, represents the unknown resistor. It is initially set to 0 but our algorithm in our code will help us determine what value it is after the voltage that falls across it has been measured.

The next variable, buffer, is just for a placeholder for intermediate calculations.

The last block of code is our algorithm to calculating and displaying the unknown resistor value.

If you work with resistors whose values are going to be much smaller than 1KΩ or much larger than 1KΩ, then you would have to change the reference resistor to a value near the range of the resistors you are going to test. If you are testing very small resistances such as in the range of 1-100Ω, it would be best to make the reference resistor 100Ω. This way, you would get more accurate readings. Remember, this is a voltage divider circuit. If the 2 resistors are too far apart from each other, you are going to get far-range, all-or-none readings. For example, if the reference resistor is 1KΩ and the unknown resistor is 1, this means that 5V(1Ω/1001Ω)= 0.00499V falls across the 1Ω resistorand 0.995V falls across the 1KΩ resistor. The 0.00499V is so small of a number that it doesn't give much weight in the calculations. Instead if you use a 10Ω resistor as the voltage divider, then 5V(1Ω/10Ω)= 0.5V falls across the 1Ω resistor. This will give more weight and accuracy in the calculations. Thus, it will be able to tell with greater accuracy what value this unknown resistor is. This is why you should have a reference resistor in the range of the resistor values you will be testing. This is how manual ohmmeters work. These are multimeters that have an ohmmeter that you have to manually select the range. This is not an autoranging ohmmeter.