I have been running a fully automated hydroponic garden for several years. I would like to expand my garden and would like some input on my conductivity sensors.
I have tried multiple circuits and have had problems with the sensor going out of calibration too fast. I have come up with a new circuit I will test shortly.
The frequency needs to be 1khz+ to prevent polarization of the ions, and build up on one electrode on the probe.
The pH probe is much simpler and I will post schematics shortly.
The circuit is as follows:
C1 ______________
 
 
1nf 
Probe
C2____ 


EC _____________
So if the ascii art doesn't look right, a capacitor is connected between pins C1 and C2, and the probe is connected between C1 and EC.
The pseudo code is as follows:
1) C1 = high, C2 = low, EC = input
cap is charged to VCC
2) C1 = input
3) EC = low
start discharge
4) Time until C1 = low
5) C1 = low, C2 = high, EC = input
cap is charged in reverse
6) C1 = input
7) EC = high
start discharge
Time until C1 = high
9) Repeat and average
Here is the function I've put together so far, if anyone can cut down number of clock cycles on the pin changes that would be appreciated.
C1 = pin 7
C2 = pin 6
EC = pin 5
double GetTDS()
{
int samples = 16;
int T1 = 0;
int T2 = 0;
long count = 0;
for (int i=0;i++;i<samples) {
// c1 high, c2 low, ec input
// charge cap
bitClear(DDRD,5); // ec input
bitClear(PORTD,5); // disable pullup
bitSet(PORTD,7); // c1 high
bitClear(PORTD,6); // c2 low
bitSet(DDRD,7); // c1 output
bitSet(DDRD,6); // c2 output
// wait for charge ?
// c1 input, c2 low, ec input
// set C1 to input
bitClear(DDRD,7); // set c1 to input
bitClear(PORTD,7); // disable pull up
// c1 input, c2 low, ec low
// dischage and time
T1 = 0;
bitSet(DDRD,5); // set EC to low and start discharge
while (bitRead(PIND,7) == 1)
{
T1++;
}
// c1 = low, c2 high, ec input
// charge cap in reverse
bitClear(DDRD,5); // set EC to input
bitClear(PORTD,7); // c1 low
bitSet(PORTD,6); // c2 high
// wait for charge ?
// c1 input, c2 high, ec input
// set c1 to input
bitClear(DDRD,7); // set c1 to input (already low)
bitSet(PORTD,5); // set EC / high
// c1 input, c2 high, ec high
// dischage and time
T2 = 0;
bitSet(DDRD,5); // set EC to output / high
while (bitRead(PIND,7) == 0)
{
T2++;
}
count = count + T1 + T2;
}
// set all pins to input
bitClear(DDRD,7);
bitClear(DDRD,6);
bitClear(DDRD,5);
bitClear(DPORT,7);
bitClear(DPORT,6);
bitClear(DPORT,5);
return count / (samples * 2);
}