As mentioned in another post, I'm working on an Arduino Uno-based ohm meter for an instrument panel. I am running into a strange problem which I felt made this worthy of another post.
The basic code I've been following is this:
floar vin = 5; //ish float R1 = 20.0; //my 2K known resistor int v = analogRead(refPin); //the reading for A0 float buffer = v * vin; //calculating output voltage float vout = (buffer)/1024.0; float R2 = (vout*R1)/(vin-vout)*1000; //the formula
I'm using 4 different test resistors connected to different pins that I turn on or off depending on the size of the value of the resistor to be measured. 10K, 20K, 220K, and 1M. The first three return sensible (though inaccurate) values, but good enough for me to get the gist of what I have plugged in. The 1M hookup, however, returns really weird numbers. For example, a 680K resister returns 203800000.00, and trying to actually measure a 1M comes out something like 255000000.00. The formula hasn't changed, only the value of the resistors. I've even taken it out of the series on it's own and tested it with the same results. What could be an explanation for these values? Incidentally, the 220K-1M code looks like this:
R1 = 1000; v = analogRead(resistorPin); buffer = v * vin; vout = (buffer)/1024.0; R2 = (vout*R1)/(vin-vout)*1000;
Really need a diagram of your circuit and a full listing of your code.
Actually I figured this one out. I used a different series of resistors, 1K, 10K, 100K, and 1M and now the returned values seem to be ok. Weird!