Go Down

Topic: pH controller unstable in field measurements (Read 6775 times) previous topic - next topic

Androxys

Hello everyone.

I am having a little issue with a pH controller I have designed.

The controller works just fine when measuring in the lab, and also outdoors when measuring buffer calibration solutions, with stable and accurate readings. However, when measuring a 100 lt salt water tank that is 1 ft away from the buffer solution cups (where it reads just fine), the readings start to get all over the place (should be around 7.1 pH, and these readings vary between 6.9 and 7.3), and seems to be worse when there's more wind.

Now, there's not much electrical noise as it's outdoors on a fairly remote place. I have 2 analog sensors (ph and temp)  but I have taken the care to put a delay between the readings to allow the ADC to stabilize. I've also taken care of shielding and put filter capacitors at the power and sensor inputs. And as seen in the code below, I average 200 samples on every cycle before displaying the value. So at the moment I am at a bit of a loss. I think it might have to do with the large mass of moving water under the wind but a commercial controller we have doesn't float that much, and I'm not sure how to accomplish this without disregarding the actual pH value.

Here is the relevant code:

Code: [Select]

unsigned int readADC(unsigned char channel)
{

  double d = 0;
  int i = 0;

  for (i = 0; i < 200; i++)
  { 
    delay(10);                            //to stabilize ADC
    d = d + analogRead(channel);
  }

  d = d / i;

  return (unsigned int)(d);

}

.
.
.
void loop (void)
{
...
   ph_mv = readADC(PHSENSOR);
   temp_mv = readADC(TEMPSENSOR);
...
}


Thank you very much for any and all advice.

robtillaart


So the longer the cable the noisier the read?

What power supply do you use?


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Androxys

No, the cable is the same. The buffer cups are on the edge of the tank, so I just have to pull the probe out of the water tank and into the buffer cup.

I am using a 230VAC - 24 VAC transformer, center tapped so I have 12 V and -12V, into a full-rectifier bridge and then into linear regulators to get 5, 9 and -9 VDC. I think however that if the problem were related to the power source I would have unstable readings everywhere, including on the buffer solutions, which doesn't happen. If I was to take a wild guess, I'd say it has to do with the water tank itself and/or the weather conditions (from observation, the windier it is, the worse it gets). I injected some CO2 previously in there, but that was about 2 weeks ago, so I guess that if it had to do with a less than uniform mix of CO2 into water, the problem would have been long gone by now. I really don't know :/

trendski

#3
Apr 20, 2012, 11:53 am Last Edit: Apr 20, 2012, 04:04 pm by trendski Reason: 1
Quote
...all over the place (should be around 7.1 pH, and these readings vary between 6.9 and 7.3), and seems to be worse when there's more wind.



7.1 is right in the middle of 6.9 to 7.3. It don't think it's that surprising for a home made device to fluctuate under outdoor windy / wet conditions. As you say you commercial device is reading fine. In my days as an environmental scientist (many moons ago) I worked for years with lots of different types of commercial monitoring systems and even they had their tricky moments under field conditions, so I empathize with your situation.

I would be worried if it was reading say 6  to 6.5 or 7.5 to 8.

Could you average over say 20 seconds of collecting data in your code and report not just the average but also the index of precision?

Have you also tried measuring right in the middle and at other parts of the tank, including at different depths? Can you eliminate the choppy conditions and test if that improves the precision? Could you try a sub-sample of the seawater in a bucket out of the wind? Long shot but- could the tank be reacting with the seawater?

You might try to find out more about the design of the commercial product and see what improvements you could make to your home-made one.
I had better precision from my temperature sensing project by using a co-ax cable for the sensor and shielding the arduino in tin-foil - if that helps XD.

This might be a useful link
http://www.66pacific.com/ph/ph.aspx

A pH probe will only put out about 0.06v per pH unit (Wikipedia). So the difference between  pH6.9 and 7.3 is only 0.4 * 0.06 = 0.024v or 24mV. I note that pH circuit designs include an amplifier stage.

EDIT: sorry I missed the bit where you said you'd shielded everything.

Cheers
Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)

SparkysWidgets

Which design are you basing it off of, granted they are all similar, I am guessing pHduino from the averaging routine. Although that routine is used in a few of places :) (hey it works great). With outdoor water bodies especially the bigger ones a little more care is needed in AC decoupling and filters on the input signal, there is a lot of noise out there and bodies of water like to pick it up, even just 100l. Damien's design and the older basic Stamp/owl2 design incorporate some additional filtering to help with these situations (an RC filter on the input plus some additional capacitors on the feedback loops).

You could also try oversampling and decimation to tighten it up a bit, take 16 reading at a set frequency then right shift(twice) the result instead of dividing it. Then take a moving average of the last N numbers of shifted results to further smooth the result. You will find that most commercial probes perform similar functions, but their reference voltages are general much lower I.E a 1.1 or 1.8 ref to the ADC. If you are building the circuit you can also use an instrumentation amplifier design which also helps, but requires at least 1 additional op-amp.

Androxys

#5
Apr 25, 2012, 02:21 pm Last Edit: Apr 25, 2012, 02:32 pm by Androxys Reason: 1
Thank you mates, those are some really good suggestions. I will try implementing some.

Quote

Have you also tried measuring right in the middle and at other parts of the tank, including at different depths? Can you eliminate the choppy conditions and test if that improves the precision? Could you try a sub-sample of the seawater in a bucket out of the wind? Long shot but- could the tank be reacting with the seawater?



Yes in fact a few days ago I went there, and had already done some of what you suggest,. The resulsts befuddled me a little bit. So:

- Different depths in the tank do not show a relevant change in variation.
- The water had some CO2 injected previously. I thought it could be from a poorly homogeneized mixture, but tried in another tank w/o CO2 and that's not the case.
- Tried in low wind conditions, still no relevant improvement (although it's a liiiittle better).

- Now comes the interesting part. I took a sample into half of a plastic water bottle, and the results are 100% accurate. Even if I moved the bottle/sensor around, so I guessed it was something else and not the wind. Then I thought of immersing the bottle with the sample into the tank, HOWEVER as soon as I touch the water surface (just the exterior of the bottle, the waters don't mix), I pick up that variation again.

So I am left guessing this has to do with the larger body of water picking some AC noise, or EM reflection at the water surface. Do you guys reckon it too?

Upon further inspection, turns out I took my 100 nF decoupling cap from the sensor entrance out of the design a few months ago. It was "eating" my sensor output, and the arduino was registering a lower voltage than supposed (maybe because of poor shielding at the time and it was picking power grid 50 Hz noise, so I had a quasi-AC wave), so I took it out. I bet this is causing me problems now, isn't it? Is the 100 nF cap adquate for this? And will some tin foil around the BNC connection help?

Also SparkysWidgets, my design is my own. I based some things in some designs, especially pHduino, but at the end of the day decided to go with an instrumentation amplifier, which as far as I remember none of the projects I saw used.

Thank you very much.
Cheers.

in10ceguy

Try grounding the water .Connect a wire that is in contact with the water and connect it to the reference side of the probe...in this case if its a combination electrode , connect to circuit's ground or you may use signal conditioner (little expensive)

EC/pH transmitters
http://webpages.charter.net/tdsmeter/index.html

Androxys

That's one fine idea, I'll try that  :smiley-mr-green:. Hopefully tomorrow I'll be able to make a couple more experiments.

Androxys

#8
May 03, 2012, 09:43 pm Last Edit: May 03, 2012, 09:46 pm by Androxys Reason: 1
Well, "grounding the water" didn't work. The probe will always output the same voltage despite the solution it's immersed in. From taking a quick look at sensor construction, I think this is because I'm essentially short circuiting the reference and the sensing part of the probe.

The RC filter between the amplifier entrance and the probe also isn't doing a lot, it doesn't reduce variance (in fact, it looked like it exacerbated the problem) and it's still eating part of my signal, with the measured value decreasing by about 3 pH (although that would be taken care of after calibration, but since the variance is still there, it's pointless).

I also tried oversampling more than I already had, which reduces the rate at which the information is updated in the screen, but the variance is still there.

I'm all out of ideas now. I'm about to keep going forward on my project, variance or not.

liudr

I think by now you should have concluded: salt water is one big conducting body. I don't know how your pH sensor works but if you connect your sensor to a large body of conductor, you have added a huge capacitance to your input. That could potentially pick up noise very easily, just like a metal plate picks up all sorts of noise if you connect it to an analog channel. Pretty much the principle of capacitive touch screen. Grounding a good conductor would work but salt water is not a good conductor. I suggest you create a small plastic buffer in the tank and it needs to be small in size, then its rim is above water but with a few small holes on the bottom. Since the pH value should not vary quickly, those holes are going to slowly equalize pH inside and outside the buffer, but cut most electric conduction to the rest of the salt water. The less holes, the better the reading. Then just measure inside the buffer region but not the entire tank. I really want to know if this works. I'm interested in fish tank pH control, similar problem, right?

robtillaart

@liudr
Quote
Since the pH value should not vary quickly

that is an assumption!   

In fact it depends on the context, for example in a river pH can change fast (pollution).
A small buffer would create a mini environment that misses the dynamics of the river.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

ChinaBuck

How are you compensating for temperature changes?

liudr

River should be fine, not a conductor like salt water. You can dip the sensor in it without picking up much noise. I just fail to see anywhere there is a nature-made flowing body of conductors (maybe the ocean is kind of conductive but it's only slightly salty). ;)

Delta_G

Seawater is 53mS/cm.  That's conductive enough. 

Are there pumps running in this tank?  If so there's the source of electrical noise.  Shield those.

Don't put any wire into this thing if there are animals in it.  Copper is poisonous to marine life.

robtillaart

Quote
Don't put any wire into this thing if there are animals in it.  Copper is poisonous to marine life.


Good point!

Solution could be something with serveral servos/steppenmotors that takes water samples - ? 
Or other type of wiring?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up