 # emulate AC power; could this work ?

I want to measure the resistance of a water with the following in mind: "the more salts dissolved, the lower the resistance". From the resistance I want to determine the salt concentration in the water.

To put it very simple, one could hang two wires on a fixed and short distance of each other into the solution and then through an analogRead() determine the resistance. But .... if one uses DC, the electric potential between the wires will influence the salt (ion) concentration near the wires(electrodes) and thus influence the result of an analogRead.

If one changes the polarity of the electrodes (so use AC instead of DC) with a high enough frequency, your readings will not be affected.

So my question is whether one can emulate AC through the code below.

``````unsigned int  currentPlus = A0, currentMin = A1, tmpVal;

void setup()
{
pinMode(currentMin, INPUT);

pinMode(currentPlus, OUTPUT);
digitalWrite(currentPlus, HIGH);
}

void loop()
{
tmpVal = currentMin;
currentMin = currentPlus;
currentPlus = tmpVal;

pinMode(currentMin, INPUT);
pinMode(currentPlus, OUTPUT);

digitalWrite(currentPlus, LOW);
delay(10);

digitalWrite(currentPlus, HIGH);
delay(10);
}
``````

if the water is flowing..even just a little, then what u are doing should work.. standing water will tend to ionize both electrodes over time, even if u switch the current direction..

Thanks, I will try it.

I can't comment much on the ionization of water, but if you are just applying a 50% duty cycle square wave between 0 and 5V you are still going to have a 2.5V DC component in your signal.

You'd need to use capacitors or transformers so that only the AC component of your signal gets to the water.

Also, that's a very inefficient way to get a 50% duty cycle square wave from the Arduino. You'd do well to google "Arduino PWM."