Pages: [1]   Go Down
Author Topic: [VERY BASIC] Measuring resistance.  (Read 858 times)
0 Members and 1 Guest are viewing this topic.
Rouen, France
Offline Offline
Newbie
*
Karma: 0
Posts: 44
Arduino beggiiiiinnneeerrr !
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

   Hi all !

Sorry if this is such a basic question (and maybe it’s been answered too many times already).
I want to measure a resistance with on my arduino board.

From the different message I’ve read : it has to be done with a voltage divider. One should do this schematic:

                            Analog input pin
         unknown R1         |      XX Ohm R2
+5  ----^^^^^^^-----+----^^^^^^^^^^------
                                                                         |
                                                                        ---
                                                                        Ground

I am guessing that if I want to have as much precision as possible, I should put the smallest resistance on R2. However if I put a very tiny small resistance, the board will try to send as much current as possible, therefore I’m going to burn my board. And guess: I don’t want to burn my board.

So how should I calculate the resistance to put ?
I wanted to use the formula u=r*i … u=5Volts (given by the board), r is the smallest resistance I look for, but I don’t know the maximum Intensity
I looked at the hardware page and couldn’t find it. They talk abour 3.3V, 5V, pvm ports, etc. they got me lost smiley-sad

Thanks if you can help smiley
« Last Edit: March 24, 2011, 05:42:23 am by Chrisprols » Logged

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

Ah ! ... and since this post wouldn't be so complete without a sketch. Here is what I found from the old forum. The credits goes to lxmyers (everybody say "thank you lxmyers")


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);                    // do the measurement every 1000ms (=every 1 sec)
}


Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

R2 is there to make your measurement safe for the Arduino, the smaller R2 the higher the max current when R1 is zero.

You can use swappable R2 for different resistances on R1 to get better resolution.

Ohms law is here again.
Current  I=Vcc/(R1+R2)
What you get in to analog input is, Uin=I * R1

Be sure your R2 is big enough if R1 is getting closer to zero.

Cheers,
Kari

Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, when I was composing the post, telephone rang...

So I basicly say what you already knew.

If your R1 is zero, R2 with value of 100ohm is taking 50mA. What you are going to measure, says more to suitable value for R2.

And, the bigger the current, more it takes the Vcc down if regulator is not strong.

You could consider external power supply, or opamp to do things safer.

Cheers,
Kari
Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

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

Hi !
Thanks for your reply Kari.

Well my question was "double". I wanted to know what is the smallest resistance I can put to have maximum precision on my measurement and minimum risk on my Arduino board.
I'm just going to connect VCC to pin 3 (for example) with the resistance I want to measure. Then pin 3 to the resistance of 100 Ohms which will go to the ground.


VCC                         pin 3 (analog read)
         unknown R1         |      100Ohm R2
+5  ----^^^^^^^-----+----^^^^^^^^^^------
                                                                         |
                                                                        ---
                                                                        Ground


If I understand well, if my unknown resistance is zero, then total resistance will be 100 Ohms and delivered current will be 50 mA (100 * 50 = 5V) which is within the specs. And I should not burn my board. The reading on my analog input should be very-very close to 5V.
If my unknown resistance is very big, amperage should be very low (good for me !) and the analog input should be very-very close to zero volts.

After this I just need to perform a calibration to know my range of readings and I'll be fine.

To tell you more what I want to measure: a soil moisture DYI sensor. Basically 2 conductor (piece of metal or pencil carbon thingy) in a shaped plaster of Paris stick. I'll stick this in my plant ground and log the values of the resistance over time. Then I'll plot this on excel and see where I want to put the limits for a potential automatic watering system. (as you will have understood, I have no idea of what kind of resistance I expect).
http://www.cheapvegetablegardener.com/2009/03/how-to-make-cheap-soil-moisture-sensor.html
BUT, I have other ideas with photosensor, potentiometer, etc.

One more question: putting 100 Ohm resistor is great for measuring a value that will go from zero to an unknown maximum value ... how do I optimize my system for a resistor that will oscillate between 10kOhms and 12kOhms (or 20kOhms and 30kOhms ... or what ever other value !) ?
Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Make yourself an Excel sheet and test it there, if you want, I can make you a extremely simple one for trying different values.

Have you tested your home made sensor that the value is between 10k-12k when it is in soil?

Cheers,
Kari
Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Get the limits for your sensor, then it will be easier to calculate pulldown resistor.

I recommend to use bigger pull-down resistor to reduce current, and corrosion under ground, water and electricity does its magic.

Cheers,
Kari
Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

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

Hi !
thank you all for the repplies.

I don't know how much Ohms to expect. I see 2 situations possible:
1- the resistance varies from 0 to XX Ohms (for the example, we could say 10kOhms)
2- the resistance varies from XX Ohms to XX+YY Ohms (for the example, we could say between 13k and 17k !)

... In both those cases, I am looking for the appropriate resistor to put in order to have the best precision/range of measurement.
Logged

Red Sea, Saudi Arabia
Offline Offline
God Member
*****
Karma: 12
Posts: 579
..On The Red Sea
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, because the Arduino Input/Output pins are very high impedance when in Input mode, you could have 2 or more resistors connected to your test point and select one to set "High" at a time and have multiple resistance-measuring "ranges"...

The 40 ma maximum per pin sets the lowest resistance you can measure accurately, but you can measure resistances up to 100K and more with higher resistances for the known resistance.

I use this principle in an Arduino tester: http://terryking.us/arduino-testing.htm
Logged

Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

Pages: [1]   Go Up
Jump to: