Go Down

### Topic: Arduino Ohm Meter? (Read 76200 times)previous topic - next topic

#### lxmyers

##### May 12, 2009, 04:12 am
Hi Guys,
I was wondering whether it is possible to use an Arduino as an ohm meter? I have seen a lot of documentation on Arduino voltmeters but nothing for measuring resistance.

Thanks Guys,
Alex

#### retrolefty

#1
##### May 12, 2009, 04:30 am
Sure it's possible. If you pull up an analog input pin with a resistor, then any unknown resistance connected to the pin and ground would cause the measured voltage to be reduced. You would need to scale and reverse the measurement value and I'm not sure of the usable resistance range that would result but those that like playing with the math could work it out.

By the way most ohm meters utilize the a similar (fixed voltage or current) method to determine a resistance value, being a passive component a resistor cannot be measured without applying some external voltage/current source to it.

Lefty

#### lxmyers

#2
##### May 12, 2009, 10:55 am
Thanks Lefty, i wired up a 10k pullup resistor and using the analogRead statement i get a value between 0 and 1023 on resistors connected between the pin and gnd. Does anyone know the math for converting the result from analogRead statement into a readable resistance value?

Thanks again,
Alex

#3

#### anachrocomputer

#4
##### May 12, 2009, 12:46 pm
Another way to measure resistance with the Arduino's voltage-measuring analog inputs, is to build a constant-current circuit.  This is a fairly simple transistor circuit that will make a constant, pre-determined current flow through a resistor.  Then, you can measure voltage across the resistor and use Ohm's Law.

http://en.wikipedia.org/wiki/Current_source

The only slightly tricky part will be making a current source with a PNP transistor, so that the load (the unknown resistor) can be connected to Ground.

#### lxmyers

#5
##### May 12, 2009, 02:11 pm
Hi Guys,
I had a play around and have got the code working. thanks AWOL, the link was very helpful.

I know you guys can probably do this in your sleep but i thought i would post the code anyway.

Code: [Select]
`int analogPin = 0;     // potentiometer wiper (middle terminal) connected to analog pin 3                       // outside leads to ground and +5Vint raw = 0;           // variable to store the raw input valueint Vin = 5;           // variable to store the input voltagefloat Vout = 0;        // variable to store the output voltagefloat R1 = 10;         // variable to store the R1 valuefloat R2 = 0;          // variable to store the R2 valuefloat buffer = 0;      // buffer variable for calculationvoid setup(){  Serial.begin(9600);             // Setup serial  digitalWrite(13, HIGH);         // Indicates that the program has intialized}void loop(){  raw = analogRead(analogPin);    // Reads the Input PIN  Vout = (5.0 / 1023.0) * raw;    // Calculates the Voltage on th Input PIN  buffer = (Vin / Vout) - 1;  R2 = R1 / buffer;  Serial.print("Voltage: ");      //  Serial.println(Vout);           // Outputs the information  Serial.print("R2: ");           //  Serial.println(R2);             //  delay(1000);}`

Thank you all very much for your help,
Alex

#### GekoCH

#6
##### May 30, 2009, 11:04 am
hmm does this Sketch really work?

I tried it with different resistor but the Arduino never got it right...
e.g. for a 15k Arduino says 6.7...

could some one help me!
Thx!
Geko

#### mem

#7
##### May 30, 2009, 12:00 pmLast Edit: May 30, 2009, 12:00 pm by mem Reason: 1
I didn't run that sketch but I would expect if R1 was 10k and R2 was 15k you would get the following:

Vout = 3 volts
buffer = (5/3)-1 = .66666
R2 = R1/buffer = 10/.6666 = 15.00

GekoCH, What did value of Vout did you get?

#8
Voltage: 1.97
R2: 6.35

Geko

#### mem

#9
##### May 30, 2009, 12:16 pmLast Edit: May 30, 2009, 12:17 pm by mem Reason: 1
Geko, try swapping the 10k and 15k resistors.

#### GekoCH

#10
##### May 30, 2009, 12:20 pm
WOW!
You'are great!
But why this config:

5v------10k---------Resistor------GND
|
Analog

befor it was

5v------Resistor---------10k------GND
|
Analog

#### mem

#11
##### May 30, 2009, 01:55 pm
Connecting the 10k resistor to +5v matches the calculation used in the code.

have fun!

#### Chrisprols

#12
##### Dec 13, 2010, 04:27 pm
Quote
I know you guys can probably do this in your sleep but i thought i would post the code anyway.

... you definitly did right. guys like me appreciate finding simple code. it's always good when you start to read as much as you can.

thx !

Go Up