Hydroponic pH and conductivity sensors
i have been running automated hydroponic garden several years. expand garden , input on conductivity sensors.
i have tried multiple circuits , have had problems sensor going out of calibration fast. have come new circuit test shortly.
the frequency needs 1khz+ prevent polarization of ions, , build on 1 electrode on probe.
the ph probe simpler , post schematics shortly.
the circuit follows:
c1 ______________
| |
| |
1nf |
probe
c2____| |
|
|
ec _____________|
so if ascii art doesn't right, capacitor connected between pins c1 , c2, , probe connected between c1 , ec.
the pseudo code follows:
1) c1 = high, c2 = low, ec = input
cap charged vcc
2) c1 = input
3) ec = low
start discharge
4) time until c1 = low
5) c1 = low, c2 = high, ec = input
cap charged in reverse
6) c1 = input
7) ec = high
start discharge
time until c1 = high
9) repeat , average
here function i've put far, if can cut down number of clock cycles on pin changes appreciated.
c1 = pin 7
c2 = pin 6
ec = pin 5
double gettds()
{
int samples = 16;
int t1 = 0;
int t2 = 0;
long count = 0;
(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 charge ?
// c1 input, c2 low, ec input
// set c1 input
bitclear(ddrd,7); // set c1 input
bitclear(portd,7); // disable pull up
// c1 input, c2 low, ec low
// dischage , time
t1 = 0;
bitset(ddrd,5); // set ec low , start discharge
while (bitread(pind,7) == 1)
{
t1++;
}
// c1 = low, c2 high, ec input
// charge cap in reverse
bitclear(ddrd,5); // set ec input
bitclear(portd,7); // c1 low
bitset(portd,6); // c2 high
// wait charge ?
// c1 input, c2 high, ec input
// set c1 input
bitclear(ddrd,7); // set c1 input (already low)
bitset(portd,5); // set ec / high
// c1 input, c2 high, ec high
// dischage , time
t2 = 0;
bitset(ddrd,5); // set ec output / high
while (bitread(pind,7) == 0)
{
t2++;
}
count = count + t1 + t2;
}
// set pins input
bitclear(ddrd,7);
bitclear(ddrd,6);
bitclear(ddrd,5);
bitclear(dport,7);
bitclear(dport,6);
bitclear(dport,5);
return count / (samples * 2);
}
i have tried multiple circuits , have had problems sensor going out of calibration fast. have come new circuit test shortly.
the frequency needs 1khz+ prevent polarization of ions, , build on 1 electrode on probe.
the ph probe simpler , post schematics shortly.
the circuit follows:
c1 ______________
| |
| |
1nf |
probe
c2____| |
|
|
ec _____________|
so if ascii art doesn't right, capacitor connected between pins c1 , c2, , probe connected between c1 , ec.
the pseudo code follows:
1) c1 = high, c2 = low, ec = input
cap charged vcc
2) c1 = input
3) ec = low
start discharge
4) time until c1 = low
5) c1 = low, c2 = high, ec = input
cap charged in reverse
6) c1 = input
7) ec = high
start discharge
time until c1 = high
9) repeat , average
here function i've put far, if can cut down number of clock cycles on pin changes appreciated.
c1 = pin 7
c2 = pin 6
ec = pin 5
double gettds()
{
int samples = 16;
int t1 = 0;
int t2 = 0;
long count = 0;
(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 charge ?
// c1 input, c2 low, ec input
// set c1 input
bitclear(ddrd,7); // set c1 input
bitclear(portd,7); // disable pull up
// c1 input, c2 low, ec low
// dischage , time
t1 = 0;
bitset(ddrd,5); // set ec low , start discharge
while (bitread(pind,7) == 1)
{
t1++;
}
// c1 = low, c2 high, ec input
// charge cap in reverse
bitclear(ddrd,5); // set ec input
bitclear(portd,7); // c1 low
bitset(portd,6); // c2 high
// wait charge ?
// c1 input, c2 high, ec input
// set c1 input
bitclear(ddrd,7); // set c1 input (already low)
bitset(portd,5); // set ec / high
// c1 input, c2 high, ec high
// dischage , time
t2 = 0;
bitset(ddrd,5); // set ec output / high
while (bitread(pind,7) == 0)
{
t2++;
}
count = count + t1 + t2;
}
// set pins input
bitclear(ddrd,7);
bitclear(ddrd,6);
bitclear(ddrd,5);
bitclear(dport,7);
bitclear(dport,6);
bitclear(dport,5);
return count / (samples * 2);
}
hi, welcome forum.
thanks sharing.
could show picture of probe ? or have website ?
when use reply button (not quick reply field) there additional options in lower-left below text field, used attach photos.
the bitset() , bitclear() compiled the fastest bit set , clear instructions atmega chip. think 2 clock cycles per setting or clearing bit. not possible faster.
code (the sketch) best placed between < code > , < / code > tags. there button (the scroll <> ).
thanks sharing.
could show picture of probe ? or have website ?
when use reply button (not quick reply field) there additional options in lower-left below text field, used attach photos.
the bitset() , bitclear() compiled the fastest bit set , clear instructions atmega chip. think 2 clock cycles per setting or clearing bit. not possible faster.
code (the sketch) best placed between < code > , < / code > tags. there button (the scroll <> ).
Arduino Forum > Using Arduino > Sensors > Hydroponic pH and conductivity sensors
arduino
Comments
Post a Comment