DIY EC sensor

OP
S

Sral

Active Member
Review score
+0 /0 /-0
View Badges
Joined
May 2, 2022
Messages
364
Reaction score
429
Review score
+0 /0 /-0
Location
Germany
Alright, I didn't find ready information with a quick search, but using the cell constant defined on this website:

Specific Conductivity = Conductivity * Cell Constant (K)
Cell Constant = distance / Area

ASSUMING they use the units:
[µS/cm] = [µS] * Cell Constant
the cell constant needs to have the unit [1/cm]

Calculating the expected resistance in a few conditions:
fresh water​
salt water​
500-2000 µS/cm​
10.000-50.000 µS/cm​
K = 0.1 cm^-1200 -50 Ohm 10 - 2 Ohm
K = 1 cm^-12000 - 500 Ohm 100 - 20 Ohm
K = 10 cm^-120k - 5k Ohm1000 - 200 Ohm

I can still measure a few hundred Ohm with a 1k reference resistor.
Downside is, of course, that you dump about 1mA current through the water, which sounds dangerous. For humans about 20mA become dangerous, not sure how it is for fish o_O
I will therefore aim at the 1k-100k range.

So we should be looking for probes with cell constants of 10/cm for fresh water or 100/cm for salt water, then you measure something like a few kOhm and dump a maximum of 0.1 mA through the water, which sounds a lot better.

I had a quick try with my audio jack and measured a resistance of several 10kOhm in water with something like 4000µS/cm, which sounds like a cell constant of roughly 40-200. Would be funny if that works out :D
 
Top Shelf Aquatics
OP
S

Sral

Active Member
Review score
+0 /0 /-0
View Badges
Joined
May 2, 2022
Messages
364
Reaction score
429
Review score
+0 /0 /-0
Location
Germany
I tested a few known resistors in place of the test resistor:
Voltage_calibration_log.png

My formula reproduces that almost perfectly. I'll probably have to see whether I can adjust the formula to include slight circuit imperfections. Still nice to see !

I also tested my EC probe in tap water for now and that gives a VOUT of 0.72 V , equaling about 5200 Ohm or about 192 µS. Since we live in an area with very soft water, I'm going to assume that I have a probe with roughly K ~ 1 / cm, since soft water should range around a TDS of roughly 100 ppm or roughly 200 µS/cm.
 

robsworld78

Well-Known Member
Review score
+0 /0 /-0
View Badges
Joined
Feb 14, 2020
Messages
894
Reaction score
1,183
Review score
+0 /0 /-0
Location
Edmonton, Canada
Looks like things are coming along nicely, good job! :) Wish I could understand more of what you posted though but I'm sure all these details will be very useful to some.

For the probe I always link the K1 based on what I read on Atlas website, maybe it depends on the circuit though.

They say this for the K1 probe, seems to cover everything.

The Atlas Scientific K1 EZO-Conductivity Kit is perfect measuring water with a conductivity range from 10µs to 100,000µs. That means this kit is perfect for environmental monitoring, hydroponics, and both freshwater and saltwater aquariums.

If you need any help getting PCB's ordered let me know. If you put all the parts on the same side of the board you can get them preassembled fairly cheap.
 
Top Shelf Aquatics
OP
S

Sral

Active Member
Review score
+0 /0 /-0
View Badges
Joined
May 2, 2022
Messages
364
Reaction score
429
Review score
+0 /0 /-0
Location
Germany
Looks like things are coming along nicely, good job! :) Wish I could understand more of what you posted though but I'm sure all these details will be very useful to some.

For the probe I always link the K1 based on what I read on Atlas website, maybe it depends on the circuit though.

They say this for the K1 probe, seems to cover everything.



If you need any help getting PCB's ordered let me know. If you put all the parts on the same side of the board you can get them preassembled fairly cheap.
Well, I can try explaining it with more detail once I'm somewhat finished experimenting.

I guess you are right about the probe, if the circuit works different it might not send as much current through the water. That is probably either a peculiarity of my implementation, or no actual concern.

The help regarding PCB ordering would be greatly appreciated, since I have no experience whatsoever ^^
Might be useful to use similar parts to your pH circuit regarding I2C a micro-controller and voltage isolation as well.
 

robsworld78

Well-Known Member
Review score
+0 /0 /-0
View Badges
Joined
Feb 14, 2020
Messages
894
Reaction score
1,183
Review score
+0 /0 /-0
Location
Edmonton, Canada
Well, I can try explaining it with more detail once I'm somewhat finished experimenting.

I guess you are right about the probe, if the circuit works different it might not send as much current through the water. That is probably either a peculiarity of my implementation, or no actual concern.

The help regarding PCB ordering would be greatly appreciated, since I have no experience whatsoever ^^
Might be useful to use similar parts to your pH circuit regarding I2C a micro-controller and voltage isolation as well.
Thanks, I just meant I wish I had a better understanding of how components all work together. What you're doing is on a completely different level than my controller, even if you tried to explain it more I wouldn't get it so don't do it for me.

I can definitely help with the PCB in any way, just let me know. I agree it's best to add a microcontroller and isolation, like that everything is done on one PCB and don't have to worry about outside interference as much.

For MCU I use the attiny85 20mhz version. These are all the part numbers that use the same package size. This part is a little hard to get these days but Win-Source from China seems to be the only company with them available so check them out. There's also the ATtiny25 and ATtiny45 which are easier to get but less resources. For my pH circuit I had to use the full Wire library for I2C which took most resources so I can't use the other versions, if you can do good job with the code you might get away with one of those.

ATtiny85-20SU
ATtiny85-20SUR
ATtiny85-20SH
ATtiny85-20SHR

Here's a guide explaining how to program them, this is what got me going.


I use this programmer.


And I use this clip when I'm able to get the ATtiny85 premounted.


If I mount the MCU I have a different device that I drop the chip into but still use the same programmer.

You also have to set fuses on the ATtiny85 using the programmer, I don't have a guide for that but can explain it in detail when you get there. This is required to enable the eeprom etc. It's a bit of a learning curve but overall not to difficult.

To isolate the I2C I use the ISO1540DR.


For power I use something like this.

 

robsworld78

Well-Known Member
Review score
+0 /0 /-0
View Badges
Joined
Feb 14, 2020
Messages
894
Reaction score
1,183
Review score
+0 /0 /-0
Location
Edmonton, Canada
Oh one idea I came up with for my pH circuit that works well was to add a 2nd DC regulator. The DC isolator is 5v in 5v out but on the output I added a decent 3.3v regulator and powered the circuit with it. The thought was if a voltage spike happens on the 5v rail the actual pH circuit would never see it as it would be absorbed by caps and the extra regulator. That also brought down the ripple to 8mv peak to peak which will help keep readings stable.
 
OP
S

Sral

Active Member
Review score
+0 /0 /-0
View Badges
Joined
May 2, 2022
Messages
364
Reaction score
429
Review score
+0 /0 /-0
Location
Germany
As far as I know regulators aren't designed to keep ripple out, especially if they have to power a load. That's why I have added a capacitance bridge to supply almost ripple free ~4.2-4.5V to the 3.3V regulator:
BDF1BC1F-F5ED-4DD7-B5DF-EFB2EE0C39B5.jpeg

It's basically a low-Pass filtered VCC (5V). The large resistor slowly feeds the capacitor. The feeding is so slow that basically all frequencies above 1.6Hz (=1/(2*pi*R*C) will get seriously reduced, giving a very smooth VCC reference at the transistor base. This smooth voltage is now followed at the transistor's emitter (output) minus the around 0.6V diode drop over the transistor. If I used a RC circuit to feed the regulator with 8mA directly I would need a resistor that's 100 times (the transistor's gain) lower, which would limit ripple reduction to frequencies above 160 Hz.

I'll probably do this as well for any final design, since this reduces ripple to very low levels, as you can see in my previous Post.
 

robsworld78

Well-Known Member
Review score
+0 /0 /-0
View Badges
Joined
Feb 14, 2020
Messages
894
Reaction score
1,183
Review score
+0 /0 /-0
Location
Edmonton, Canada
As far as I know regulators aren't designed to keep ripple out, especially if they have to power a load. That's why I have added a capacitance bridge to supply almost ripple free ~4.2-4.5V to the 3.3V regulator:
BDF1BC1F-F5ED-4DD7-B5DF-EFB2EE0C39B5.jpeg

It's basically a low-Pass filtered VCC (5V). The large resistor slowly feeds the capacitor. The feeding is so slow that basically all frequencies above 1.6Hz (=1/(2*pi*R*C) will get seriously reduced, giving a very smooth VCC reference at the transistor base. This smooth voltage is now followed at the transistor's emitter (output) minus the around 0.6V diode drop over the transistor. If I used a RC circuit to feed the regulator with 8mA directly I would need a resistor that's 100 times (the transistor's gain) lower, which would limit ripple reduction to frequencies above 160 Hz.

I'll probably do this as well for any final design, since this reduces ripple to very low levels, as you can see in my previous Post.
Yeah I kind of said that wrong, the 3.3v regulator had a lower ripple spec compared to the DC isolator so that's why it brought it down. I do have some filter caps as well but think it's different than what you have going on. :)
 
OP
S

Sral

Active Member
Review score
+0 /0 /-0
View Badges
Joined
May 2, 2022
Messages
364
Reaction score
429
Review score
+0 /0 /-0
Location
Germany
Yeah I kind of said that wrong, the 3.3v regulator had a lower ripple spec compared to the DC isolator so that's why it brought it down. I do have some filter caps as well but think it's different than what you have going on. :)
That's understandable, even when saying that regulators aren't very good at it, they are probably better than capacitive DC isolators in almost all cases ^^

Filter caps are also not quite designed for that, since they are being fed very quickly, since the VCC line has maybe something like 1 Ohm impedance or lower. Might be higher for high frequencies if you have a higher inductance cable. Using that less than 1 Ohm with a 10µF bypass cap gives a frequency limit of above 16kHz. Mind, the better your input line (lower resistance and inductance) the worse this gets, so these bypass caps are only designed to compensate the limitations of the input lines for very high frequencies, like a circuit that spikes from GND to VCC output in a matter of µs or faster, which equals to frequencies in the 100kHz or above.

That's why I like to call them bypass capacitors, not filtering capacitors, since they are not designed to filter anything, like ripple, but "only" bypass the input line to supply spiked loads.
(Truth be told, you could see this as a kind of backwards filtering, since the input line never sees the ultrafast spike as its dampened by the bypass capacitor, as would be usefull for my SCD30 air quality sensor dropping my I2C power line, as you might have seen earlier ^^).
 
Last edited:

robsworld78

Well-Known Member
Review score
+0 /0 /-0
View Badges
Joined
Feb 14, 2020
Messages
894
Reaction score
1,183
Review score
+0 /0 /-0
Location
Edmonton, Canada
That's understandable, even when saying that regulators aren't very good at it, they are probably better than capacitive DC isolators in almost all cases ^^

Filter caps are also not quite designed for that, since they are being fed very quickly, since the VCC line has maybe something like 1 Ohm impedance or lower. Might be higher for high frequencies if you have a higher inductance cable. Using that less than 1 Ohm with a 10µF bypass cap gives a frequency limit of above 16kHz. Mind, the better your input line (lower resistance and inductance) the worse this gets, so these bypass caps are only designed to compensate the limitations of the input lines for very high frequencies, like a circuit that spikes from GND to VCC output in a matter of µs or faster, which equals to frequencies in the 100kHz or above.

That's why I like to call them bypass capacitors, not filtering capacitors, since they are not designed to filter anything, like ripple, but "only" bypass the input line to supply spiked loads.
(Truth be told, you could see this as a kind of backwards filtering, since the input line never sees the ultrafast spike as its dampened by the bypass capacitor, as would be usefull for my SCD30 air quality sensor dropping my I2C power line, as you might have seen earlier ^^).
Yeah you're right, what I'm doing is basically just a bypass cap. I just remembered I also have some ferrite beads on the board for filtering which did help quite a bit.
 
OP
S

Sral

Active Member
Review score
+0 /0 /-0
View Badges
Joined
May 2, 2022
Messages
364
Reaction score
429
Review score
+0 /0 /-0
Location
Germany
Alright, I tested my circuit with two audio jacks:
The gold plated has 3 contacts, the nickel plated has 4. I bridged them together such that I had effectively 3 contacts on both of them: the outer parts on GND and the inner contact on AC, to hopefully reduce fringe effects.

I tested them with tap water first:
Output voltageGold platedNickel plated
air0.065V0.065V
tap water1.056V0.856V
salt water2.650V

I was hoping for a lower output in tap water, so I simply tried what I would get for salt water. I therefore added about 1g of kitchen salt to my 150 ml glas, which I estimate to be roughly 5000-10000 ppm or 10000-20000 µS/cm. Using this the audio jack has a cell constant of somewhere around:
K = 3.2-6.4 1/cm

Which leads to quite a bit of current in salt water, as explained earlier.

Another problem is that the higher voltages at the output with salt water are much more susceptible to my power spikes every 2s. So Audio jacks seem to be pretty suitable for fresh water, but for reef tanks we might need something else. That being said, it's probably still doable.
I'll keep you updated about the final accuracies, which I will test in salt water as well. The circuit would work with every kind of probe you can get on Amazon or the like for 30$ anyway.
 

Wolfw28

Active Member
Review score
+0 /0 /-0
View Badges
Joined
Mar 13, 2022
Messages
142
Reaction score
95
Review score
+0 /0 /-0
Location
Myakka City
Alright, I didn't find ready information with a quick search, but using the cell constant defined on this website:

Specific Conductivity = Conductivity * Cell Constant (K)
Cell Constant = distance / Area

ASSUMING they use the units:
[µS/cm] = [µS] * Cell Constant
the cell constant needs to have the unit [1/cm]

Calculating the expected resistance in a few conditions:
fresh water​
salt water​
500-2000 µS/cm​
10.000-50.000 µS/cm​
K = 0.1 cm^-1200 -50 Ohm10 - 2 Ohm
K = 1 cm^-12000 - 500 Ohm100 - 20 Ohm
K = 10 cm^-120k - 5k Ohm1000 - 200 Ohm

I can still measure a few hundred Ohm with a 1k reference resistor.
Downside is, of course, that you dump about 1mA current through the water, which sounds dangerous. For humans about 20mA become dangerous, not sure how it is for fish o_O
I will therefore aim at the 1k-100k range.

So we should be looking for probes with cell constants of 10/cm for fresh water or 100/cm for salt water, then you measure something like a few kOhm and dump a maximum of 0.1 mA through the water, which sounds a lot better.

I had a quick try with my audio jack and measured a resistance of several 10kOhm in water with something like 4000µS/cm, which sounds like a cell constant of roughly 40-200. Would be funny if that works out :D
When you get that perfected I have your next project. It’s a photocell for testing water parameters ie. kh Calcium magnesium etc.
 

the register

Community Member
Review score
+0 /0 /-0
View Badges
Joined
Apr 16, 2009
Messages
34
Reaction score
39
Review score
+0 /0 /-0
Regarding filtering out other noise and keeping voltage low, it'd be additional complexity for sure, but another completely different option is separate the water from the tank and measure. For instance pumping into a vessel and then dumping back out, ala Trident/Mastertronic/...


If you get it working otherwise that's certainly overly complicated, but just throwing the idea out there
 

Ranjib

7500 Club Member
Review score
+0 /0 /-0
View Badges
Joined
Apr 16, 2016
Messages
9,688
Reaction score
16,748
Review score
+0 /0 /-0
Location
Pleasant Hill, Concord
Regarding filtering out other noise and keeping voltage low, it'd be additional complexity for sure, but another completely different option is separate the water from the tank and measure. For instance pumping into a vessel and then dumping back out, ala Trident/Mastertronic/...


If you get it working otherwise that's certainly overly complicated, but just throwing the idea out there
the probe's longevity , when outside water will not be negatively impacted?
 
OP
S

Sral

Active Member
Review score
+0 /0 /-0
View Badges
Joined
May 2, 2022
Messages
364
Reaction score
429
Review score
+0 /0 /-0
Location
Germany
Regarding filtering out other noise and keeping voltage low, it'd be additional complexity for sure, but another completely different option is separate the water from the tank and measure. For instance pumping into a vessel and then dumping back out, ala Trident/Mastertronic/...


If you get it working otherwise that's certainly overly complicated, but just throwing the idea out there
Absolutely ! That would definitely remove noise and protect your fish. Works the same for pH probes.

the probe's longevity , when outside water will not be negatively impacted?
pH probes will definitely be impacted, as they contain a reference liquid that can dry out.
EC probes are not impacted by this, as they have only two metal contacts. Besides possible corrosion they should not care. That being said however, when you have drops of salt water drying out on their surface the salt concentration slowly increases until they might actually start corroding from the high salt content on the surface.

You could remedy both by simply leaving the water in there or only leaving a very small hole in the chamber to equalize the pressure. This should slow down the drying so much that it should not happen between measurements.

Emptying the chamber can also be done easily by using a pythagorean cup siphon mechanism. Fill it 80% and the water will stay, fill in 20% more and it will drain ^^
Pretty much like this Youtube video:

I would recommend using a tilted base though, as that should drain more thoroughly.
 
Nutramar Foods
OP
S

Sral

Active Member
Review score
+0 /0 /-0
View Badges
Joined
May 2, 2022
Messages
364
Reaction score
429
Review score
+0 /0 /-0
Location
Germany
Thanks, I just meant I wish I had a better understanding of how components all work together. What you're doing is on a completely different level than my controller, even if you tried to explain it more I wouldn't get it so don't do it for me.

I can definitely help with the PCB in any way, just let me know. I agree it's best to add a microcontroller and isolation, like that everything is done on one PCB and don't have to worry about outside interference as much.

For MCU I use the attiny85 20mhz version. These are all the part numbers that use the same package size. This part is a little hard to get these days but Win-Source from China seems to be the only company with them available so check them out. There's also the ATtiny25 and ATtiny45 which are easier to get but less resources. For my pH circuit I had to use the full Wire library for I2C which took most resources so I can't use the other versions, if you can do good job with the code you might get away with one of those.

ATtiny85-20SU
ATtiny85-20SUR
ATtiny85-20SH
ATtiny85-20SHR

Here's a guide explaining how to program them, this is what got me going.


I use this programmer.


And I use this clip when I'm able to get the ATtiny85 premounted.


If I mount the MCU I have a different device that I drop the chip into but still use the same programmer.

You also have to set fuses on the ATtiny85 using the programmer, I don't have a guide for that but can explain it in detail when you get there. This is required to enable the eeprom etc. It's a bit of a learning curve but overall not to difficult.

To isolate the I2C I use the ISO1540DR.


For power I use something like this.

Thanks again for the info. The only problem I see is that I would also like to use I2C since that's ubiquitous in Reef-Pi ^^

One thing that I thought about: I could pretty much drop the whole OP-Amp setup and generate the rectangle AC signal with a microcrontroller and just read the voltage signal on my test resistor directly with the same microcontroller and a reasonably fast ADC in differential mode. Do you have any experience with the speed of the ADC on the ATtiny ?

Otherwise we could also just use a whole PI pico ... seems like a bit of an overkill but hey, it's available and its cheap ^^
Only problem might be that the PI Pico is seemingly not designed to be used as an I2C peripheral in microPython ... so I might need to code this somewhat myself using c.
 
Last edited:

robsworld78

Well-Known Member
Review score
+0 /0 /-0
View Badges
Joined
Feb 14, 2020
Messages
894
Reaction score
1,183
Review score
+0 /0 /-0
Location
Edmonton, Canada
Thanks again for the info. The only problem I see is that I would also like to use I2C since that's ubiquitous in Reef-Pi ^^

One thing that I thought about: I could pretty much drop the whole OP-Amp setup and generate the rectangle AC signal with a microcrontroller and just read the voltage signal on my test resistor directly with the same microcontroller and a reasonably fast ADC in differential mode. Do you have any experience with the speed of the ADC on the ATtiny ?

Otherwise we could also just use a whole PI pico ... seems like a bit of an overkill but hey, it's available and its cheap ^^
Only problem might be that the PI Pico is seemingly not designed to be used as an I2C peripheral in microPython ... so I might need to code this somewhat myself using c.
The ATtiny can be programmed for I2C, I have 2 pins configured for SDA/SCL, another 2 are ADC's to read the probe and one is an output for an onboard LED just as an indicator something is going on. I believe I have one spare pin. I can send you the code so you have something to work with, only downside is I use the wire library for I2C which takes up a lot of the memory. It also has an eeprom which can be handy.

Not sure on the ADC speed, visually it's fast. ;) It has 10-bit resolution which is plenty enough for pH, it can read in +/- .001 increments but maybe that has more to do with the opamp.

The pico is another option, definitely overkill and isn't so friendly when it comes to building circuit but is easier to program. That board is designed to be soldered directly to another PCB so it's nice that way and would eliminate any analog wires. That's the reason I like the microcontroller embedded, much less chance of interference on ADC lines and it keeps them short. The problem though is it requires manual labor to mount and never the option of pre-mounted. If you went this route you could make the circuit the same size as the pico and solder it to one side of the board.

ATtiny does take some getting use to and requires special $20 clip + $20 programmer. Once you know what to do it's quick, it takes me about 2-3 minutes to program which includes setting up. The nice thing is it's easy to embed on a PCB and takes up no space. Downside is these days you have to solder the IC to the board manually, it's easy but still work, less work than soldering a pico to a board though. When things are good you can get them pre-mounted and then just a matter of programming which is awesome.
 

the register

Community Member
Review score
+0 /0 /-0
View Badges
Joined
Apr 16, 2009
Messages
34
Reaction score
39
Review score
+0 /0 /-0
The ATtiny can be programmed for I2C, I have 2 pins configured for SDA/SCL, another 2 are ADC's to read the probe and one is an output for an onboard LED just as an indicator something is going on. I believe I have one spare pin. I can send you the code so you have something to work with, only downside is I use the wire library for I2C which takes up a lot of the memory. It also has an eeprom which can be handy.

Not sure on the ADC speed, visually it's fast. ;) It has 10-bit resolution which is plenty enough for pH, it can read in +/- .001 increments but maybe that has more to do with the opamp.

The pico is another option, definitely overkill and isn't so friendly when it comes to building circuit but is easier to program. That board is designed to be soldered directly to another PCB so it's nice that way and would eliminate any analog wires. That's the reason I like the microcontroller embedded, much less chance of interference on ADC lines and it keeps them short. The problem though is it requires manual labor to mount and never the option of pre-mounted. If you went this route you could make the circuit the same size as the pico and solder it to one side of the board.

ATtiny does take some getting use to and requires special $20 clip + $20 programmer. Once you know what to do it's quick, it takes me about 2-3 minutes to program which includes setting up. The nice thing is it's easy to embed on a PCB and takes up no space. Downside is these days you have to solder the IC to the board manually, it's easy but still work, less work than soldering a pico to a board though. When things are good you can get them pre-mounted and then just a matter of programming which is awesome.
Assuming they work, unlike the impossible to acquire pi and Arduino boards, there's a bazillion ESP8266 NodeMCU boards available on Amazon. You can find them for around $3 each even, and you get wifi capabilities.

My quick Google search makes it seem it supports ADC, but I have no expertise there.
 
AquaCave Logo Banner
OP
S

Sral

Active Member
Review score
+0 /0 /-0
View Badges
Joined
May 2, 2022
Messages
364
Reaction score
429
Review score
+0 /0 /-0
Location
Germany
Assuming they work, unlike the impossible to acquire pi and Arduino boards, there's a bazillion ESP8266 NodeMCU boards available on Amazon. You can find them for around $3 each even, and you get wifi capabilities.

My quick Google search makes it seem it supports ADC, but I have no expertise there.
Thanks, that was also a route I was researching. I looked at a STM32, which should do the job. An ESP32 should in principle be able to do the same I guess.
 

robsworld78

Well-Known Member
Review score
+0 /0 /-0
View Badges
Joined
Feb 14, 2020
Messages
894
Reaction score
1,183
Review score
+0 /0 /-0
Location
Edmonton, Canada
Thanks, that was also a route I was researching. I looked at a STM32, which should do the job. An ESP32 should in principle be able to do the same I guess.
The STM32's is what I always wanted to use as they are cheap, plentiful and lots to choose from but programming can be difficult for things like I2C as prewritten libraries are hard to come by so you need a good understanding of how these chips work.
 

Are you ready for giant clams in your tank?

  • I currently keep a giant clam in my aquarium

    Votes: 26 16.9%
  • I have kept giant clams in the past, but don’t have any now

    Votes: 23 14.9%
  • I am interested, but I haven’t kept giant clams yet

    Votes: 65 42.2%
  • I have no plans to keep giant clams

    Votes: 40 26.0%
Top