Go Down

Topic: Hydroponic pH and conductivity sensors (Read 7149 times) previous topic - next topic


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              |
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
8) 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)
  // 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)
  count = count + T1 + T2;

// set all pins to input

return count / (samples * 2);


Jan 31, 2015, 04:18 am Last Edit: Jan 31, 2015, 04:19 am by Peter_n
Hi, welcome to the forum.

Thanks for sharing.

Could you show a picture of the probe ? or do you have a website ?
When you use the Reply button (not the Quick Reply field) there are additional options in the lower-left below the text field, that is used to attach photos.

The bitSet() and bitClear() are compiled into the the fastest bit set and clear instructions for the ATmega chip. I think it is 2 clock cycles per setting or clearing a bit. It is not possible to be faster.

Code (the sketch) is best placed between < code > and < / code > tags. There is a button for it (the scroll with the <> ).



I am new here.

I also would like to run my hyrdoponics fully automated.
Can somebody tell my what I need to buy from arduino and how to get started?



Jan 31, 2015, 10:33 am Last Edit: Jan 31, 2015, 10:39 am by Peter_n
Getting started with Arduino is buying an Arduino Uno board.

As far as I can tell there is no "starter kit" for hydroponics. So you have to do everything step by step and find out for yourself what is best for you.
You can use SSR (Solid State Relays) or normal relays to control valves or pumps, or use mosfets with 12V valves and pumps.

Soil moisture can be measured with humidity sensors or capacitive sensors.
There are also PH probes for Arduino.

I have seen good examples on youtube and there are some websites about it.
Google : arduino garden
and : arduino hydrophonics

I love the combination of fish and aquaponics, but that seems to be too far-fetched for me. At this moment I'm only interested in the subject, I don't know how to deal with frozen water outdoors or mold indoors.


I use peristaltic pumps for the nutrients and ph dosing. They are about $20 on ebay, and need a minimum of 4. I use a cheap mosfet array to control them at 12v.

Buying premade sensors can be very expensive, and are always lacking in isolation and performance.

The sensors are fairly straight forward, the isolation is the more expensive part.

Both sensors have a DC-DC isolation transformer, and 2 optocouplers connected to a atmega328 or attiny. The isolated microcontroller does the required timing or adc and sends it serial over the optocouplers.

My system consists of these parts, plus a few cheap ones I didn't include on the list:

- Arduino uno + lcd shield
- 5 peristaltic pumps (grow, micro, bloom, ph up, calmag) ($20 each)
- mosfet array ($1.50)
- pH probe ($30)
- Hanna conductivity probe ($40)
- Water source solenoid ($15)
- Float switch ($3)
- Premade light relays - ($20)

ph sensor:
-DC to DC converter ($4)
-dual optocoupler ($1)
-power ref ($1)
-dual op amp ($1)
-few precision resistors ($0.10)
-bnc connector ($2)

conductivity sensor:
-DC to DC converter ($4)
-dual optocoupler ($1)
-precision capacitor ($1)
-2 precision resistors ($0.10)

That's already over $250 just to get started for just the automation part.

I am using a 3x6 ft table with 18 holes. PVC can be cheaper, it was around $150 for the table, $60 for pump, $20 for reservoir. $120 in lights.

I don't really have too many pictures of my last setup. And currently not running.

Here is a picture I took after being out of town for about 2 months, everything was way overgrown and too mature to eat by this time.

Lately I just grow strawberries.

Also is a picture of the old control box from a few years ago.


Thank you hydrokev, very interesting.
I have a Mega + Ethernet and I connect my projects via 433MHz RF to the Mega. So I can check if everything is okay on my tablet. I can not only check the sensors, but also the batteries of remote sensors.


Buying premade sensors can be very expensive, and are always lacking in isolation and performance.
How else are you going to do it? A lot of technology goes into pH electrodes as they rely on having the correct glass membrane. pH electrodes are very high impedance devices and the cabling and connectors are all important - even flexing a decent cable will distort the readings. I don't know what you mean by lacking isolation and performance. Ground loops are the enemy of pH and any other specific ion electrode. I used them a lot in difficult situations and the most trouble-free solution is always to put a buffer op amp (FET type) as close to the electrode as possible - some commercial electrodes come already equipped. Find a decent op amp like the old MAX406, high impedance techniques like PTFE insulators or simply keep the input pin off the board. Modern FET's take single-sided supplies and run at better than 2-microamps - a 3.6-V lithium cell will give you in excess of 5-year's trouble and ground loop -free operation. Once you have buffered the signal, you can use any cable you like. As a bonus, you can convert a pH electrode into an ammonia electrode by separating the water from the electrode with PTFE tape as used by plumbers. Works a treat, I used to make them.


Sorry I was referring to the circuit portion of the sensor being expensive and sub par. I have a few probes I have purchased for this project.

The pH portion works pretty well.

The pH circuit is:

5v DC-DC converter / 2 optocouplers -> atmega -> adc / precision power reg -> analog front end

The analog front end is a LMC6482 dual op amp configured with a buffered offset of 0.5v then a 5.4 gain on the second op amp.

Using the isolated dc-dc converter and the optocouplers will prevent any ground loop problems.

Only really need around 0.03+/- accuracy on the pH.

Go Up