Pages: [1]   Go Down
Author Topic: Arduino Ohm Meter?  (Read 22781 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25733
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://en.wikipedia.org/wiki/Voltage_divider
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
int analogPin = 0;     // potentiometer wiper (middle terminal) connected to analog pin 3
                       // outside leads to ground and +5V
int raw = 0;           // variable to store the raw input value
int Vin = 5;           // variable to store the input voltage
float Vout = 0;        // variable to store the output voltage
float R1 = 10;         // variable to store the R1 value
float R2 = 0;          // variable to store the R2 value
float buffer = 0;      // buffer variable for calculation

void 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
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 269
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: May 30, 2009, 05:00:44 am by mem » Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 269
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Voltage: 1.97
R2: 6.35

Geko
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Geko, try swapping the 10k and 15k resistors.
« Last Edit: May 30, 2009, 05:17:15 am by mem » Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 0
Posts: 269
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

WOW!
You'are great!
But why this config:

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


befor it was

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


Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Connecting the 10k resistor to +5v matches the calculation used in the code.

have fun!
Logged

Rouen, France
Offline Offline
Newbie
*
Karma: 0
Posts: 44
Arduino beggiiiiinnneeerrr !
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 !
Logged

Pages: [1]   Go Up
Jump to: