Go Down

### Topic: Conductivity measurement tool from an Arduino Uno! (Read 2881 times)previous topic - next topic

#### mixania

##### Oct 24, 2012, 10:51 pmLast Edit: Oct 25, 2012, 06:02 pm by mixania Reason: 1
Hey Arduino forum,

Recently I've been thinking on what kind of project should I build next with having a few parts.

I've decided to make a conductivity measurement tool out of an Arduino Uno!! Exiting, isn't it !?

Well... It was in the beginning. But then It's boring when you just see some numbers ranging from 0 to 1023 coming out from the serial monitor that are read from an analogRead function.

I used some water and then tried adding salt to it, in order to test my tool. I place two wires into the water. (One's connected to GND and the other is connected to 5V through a pull-up of 10K and to another wire going to A1) And It works! Its even capable of reading the conductivity of my body by placing one end of wire in one hand and the other wire in the other hand.

The thing I really want to achieve is convert those numbers into some widely used conductivity measurement. I don't know from were to start though.

Here's my simple code:

NOTE: I use the map function so that it reads 0 when there's no electricity, and 1023 when it's at its max. If I don't use it then It would read 0 when the two wires touch each other.

Code: [Select]
`int sensor = 14; // sensor pinint comp; void setup() {  Serial.begin(9600); // Serial for Debuging}void loop() {   comp = analogRead(sensor);     comp = map(comp, 0, 1023, 1023, 0);   Serial.print("Reading =");   Serial.println(comp);   delay(500);}`

Thanks!!

#### DVDdoug

#1
##### Oct 24, 2012, 11:32 pm
What are you trying to measure?  Do you have an idea of what kind of "numbers" you expect?

Usually we measure the resistance, which is simply the mathematical inverse of conductivity.

Resistance is measured by passing a known "constant" current through an unknown resistance.   Then you measure the voltage, and calculate resistance using Ohm's Law.  The Arduino measures voltages between 0 and 5V.

That means that the current has to be in the correct range to give you the correct voltage range (for that resistance).   An Ohmmeter (or multimeter) has several range settings for measuring between a few Ohms to megohms.  If the resistance is low, the voltage will be low and you might need an amplifier.

#### mixania

#2
##### Oct 24, 2012, 11:38 pmLast Edit: Oct 24, 2012, 11:45 pm by mixania Reason: 1

What are you trying to measure?  Do you have an idea of what kind of "numbers" you expect?

Sorry man, I accidentally pressed the "Publish" button while editing. You should re-read it to get what i'm trying to say

#### PeterH

#3
##### Oct 25, 2012, 12:40 am

I place two wires which into the water. (One's connected to GND the other is connected to 5V through a pull-up of 10K and to another wore going to A1) It works! Its even capable of reading the conductivity of my body by placing one end in one hand and the other wire in the other.

What you've set up is a voltage divider. Thinking of your measured voltage being somewhere between the two end points (0V and 5V), the ratio of the voltages to those end points is the same as the ratio of resistances. If your analog read returns 511, for example, that means you have equal voltage differences on both sides so you have equal resistances; the resistance you're reading is the same as your 10KOhm pullup resistor.

To work it out for the general case, you need to calculate the ratio (x / (1023-x)) where x is your analog reading, and then multiply that by your pullup resistance to get the resistance you're measuring. Note that when the measured resistance is very high relative to the pullup resistance and your analog reading gets up to 1023, this expression produces a divide-by-zero error; you would need to check the analog read value and indicate 'out of range' if it gets up to 1023.

#### nickgammon

#4
##### Oct 25, 2012, 12:48 am
Quote
NOTE: I use the map function so that it reads 0 when there's no electricity, and 1023 when it's at its max.

Code: [Select]
`   comp = map(comp, 0, 1023, 1023, 0);`

Huh? Isn't zero no electricity anyway? Or are you reversing the reading? How about:

Code: [Select]
`comp = 1023 - comp;`
Please post technical questions on the forum, not by personal message. Thanks!

#### mixania

#5
##### Oct 25, 2012, 12:58 am

Huh? Isn't zero no electricity anyway? Or are you reversing the reading? How about:

No, Unfortunately, it is'nt. That's why i'm using the map function. To reverse 0 (which means 5V without map function) to 1023.

#### nickgammon

#6
##### Oct 25, 2012, 01:02 am
The subtraction is still easier to understand.
Please post technical questions on the forum, not by personal message. Thanks!