pH Sensor

A project log for UltraTower

Grow vegetables with ultraponics tower

J GleyzesJ Gleyzes 09/17/2022 at 09:250 Comments

pH is important in hydroponic systems, indeed depending on pH of the solution certain minerals will be more or less accessible for the plants.

This is why monitoring pH is essential to optimize plant production. The ideal range is between 5.5 and 6.5 pH. pH can fluctuate, which is not important, but it should not deviate too much from this target range. 
That is why we will add a pH sensor to the tower and maybe later a pump to regulate the pH automatically.
pH sensor circuits already available on internet have 5V outputs that are not suitable for the ESP32 and the only one that outputs 3.3V is over 40€.

Let's make one.


The probe:

First, let's talk about the pH probe. It is immersed into the solution and gives a value between -0.414V and 0.414V depending on pH. 

This value will have to be amplified and shifted to purely positive values. Indeed the ESP32 can have a maximum value of -0.3V on its pins otherwise the ESP32 is damaged and the ADC can only handle DC positive values.

The ESP32 ADC:

I have chosen level 1 attenuation which allows me to have precise values between 100mV and 1250mV. With these values the pH7 should be centered at 700mV (1200mV/2 + 100mV). 

Now we have to think about the protection of the ESP32, the lowest value should not be below 0V. Even if it is not useful for UltraTower to measure a pH of 0, you never know and it is better to secure this factor. 

So the lowest value should be 50mV at pH0, so there is 650mV between ph7 (700mV) and pH0 (50mV). We can calculate the gain X that we want:

Test on LTSpice:

Here are two operational amplifiers to convert the +/- 450mV of the ph probe (V1) to an output of 0 to 1.3V for the ESP32 ADC (COM). The first opAmp is a non-inverting amplifier with a gain of 1.44 with the 2 resistors:

With standard resistors values we get a gain of 1.45.

The second opAmp is a Differential Amplifier with a gain of 2 so I set the divider bridge at the bottom of the schematic to 350mV (700mV/2).

LTSpice simulations show that for pH0 (probe set to 0.450mV) COM is at 0.80V and for pH14 (probe set to -0.450mV) COM is at 1.35V.

These two extreme pH values will not be read by the ESP32 ADC which is between 100mV and 1250mV but they will not damage the ESP32. The range of values we are interested in is between pH4 and pH9. 


The MCP6486 is a Dual Operational Amplifier that allows to use a single chip. It needs to be powered at 3.3V and -3.3V. The -3.3V supply is provided by the TC7660 which needs only two capacitors to operate.


The output value changes when the probe is placed in different solutions. This circuit works, you just need to add a calibration so that the ESP32 knows what pH the solution is.

The power supply for the circuit is 3.3V at 1.56mA so it can be powered on and off via a pin on the esp32 to preserve the pH probe for as long as possible.

All the sensors in the functionnal block diagram are operational, now I have to make a PCB to put it all together.