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.