 Resistor switching with transistors for ohmmeter

In making a project which reads ohms, I found that two reference resistors are necessary in order to get
an accurate reading over the range I’m interested in. The problem: how to switch between them?
I tried connecting them straight to the I/O pins on the board, like so (apologies for the old-school character drawings):

Unknown resistor (R1) Reference resistor 1 (R2)
GND |---------///-±----------///----------< Arduino digital pin 5
|
| Reference resistor 2 (R3)
Pin A0 >-------±----///----------------< Arduino digital pin 6

And then to control which reference is being used:

digitalWrite(5, HIGH);      /*turn on reference 1*/

/*****Read the value on pin A0 in here******/

digitalWrite(5, LOW);     /*turn off reference 1*/

By turning on the correct pin, 5v is fed through the resistor to complete the voltage divider used to measure the unknown resistor.
(Note: I have not included the resistance reading code, it’s not relevant to this problem and could be adjusted to fit whatever solution works. Basically the code found here: https://forum.arduino.cc/index.php?topic=618638.0)
The real problem with this circuit is that if an Arduino pin is at LOW, it’s effectively grounded. So, if pin 5 (R2) is HIGH and pin 6 (R3) is LOW, a voltage divider is created across R2 and R3, messing up the reading since both R3 and R1 are paths to ground. Any solution to this would be greatly appreciated; I still can’t figure this one out. Thanks.

Unless you use a constant (known) current through the
in a linear manner.
Herb

Use a H11F1TVM opto fet.

https://www.mouser.ca/datasheet/2/308/H11F3M-D-1810361.pdf https://www.digikey.ca/product-detail/en/on-semiconductor/H11F1TVM/H11F1TVM-ND/1793948

OR

https://www.digikey.ca/products/en/isolators/optoisolators-transistor-photovoltaic-output/903?k=H11F&k=H11F&pkeyword=H11F

The problem: how to switch between them?

Make one pin output -> HIGH
Make the other pin -> input no pull ups.

Mind you this is not a very good circuit because the voltage you get from an output pin will change according to how much current is being drawn.

Thank you all for the replies. After more testing I think this circuit is not the answer anyhow so I have redesigned to eliminate the switching problem (since this doesn't need to be changed often, a simple jumper setup will work just fine.) Thanks again.

Using the Arduino pins in this fashion - switching between HIGH and INPUT (with the pin written LOW so it does not enable INPUT_PULLUP) - will work just fine.

It is in fact, the basis of the "Ardutester" project. You do need to consider that the output driver has an effective internal resistance of about 45 Ohms, so it would not be too accurate or at least would need to be calibrated with series resistors under a few hundred Ohms.

You may want to give this a read. HOW TO MAKE AN ARDUINO OHM METER keeping in mind how things work. The important part is understanding what the code is doing. We know the applied voltage and we can read the voltage drop across our known resistance. Since we apply 5 volts (we assume to be accurate) if we drop 2.5 volts across our known and our known is 1,000 Ohms that tell us our current must be 2.5 mA and if we subtract our known voltage drop from VCC we know the drop across our unknown is also 2.5 volts and we know the current in a series circuit is the same. The Unknown resistor is 1,000 Ohms.

As pointed out in the link this does not result in a highly accurate ohmmeter. Not exactly a precision bridge but a good learning tool.Understanding what is going on paves the way for understanding the code.

Ron