# pH controller design

**URL:** <https://discourse.nodered.org/t/ph-controller-design/20918>\
**Category:** General\
**Created:** [27 January 2020 17:53 UTC](https://discourse.nodered.org/t/ph-controller-design/20918 "2020-01-27T17:53:24Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![ALOKA1432](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@ALOKA1432](https://discourse.nodered.org/u/ALOKA1432)\
**Post date:** [27 January 2020 17:53 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/1 "2020-01-27T17:53:24Z")

</div>

Have anyone done pH controller using NodeRED ?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [27 January 2020 19:46 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/2 "2020-01-27T19:46:45Z")

</div>

Hi Aloka,  
Can you share what you’ve tried so far or found already? For example, what pH sensor do you use, is it analog or digital, how did you connect it, and so on.  
For example, I know that Atlas Scientific’s pH probes can be read in a couple different ways including over a serial connection. They can also be connected to arduino or raspberry pi directly through a device/hat called the Tentacle (T3). I’m seriously thinking about using them for a project of mine.

---

<div class="post-metadata">

**Author:** ![ALOKA1432](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@ALOKA1432](https://discourse.nodered.org/u/ALOKA1432)\
**Post date:** [27 January 2020 20:02 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/3 "2020-01-27T20:02:37Z")

</div>

Hey @afelix, We are just planning to set things up for our hydroponics business in near future. So this is what we are up to as per your question. Till now we are doing all things manually. and BTW that is great to know about "Atlas Scientific’s pH probes". We will look into it. What else we should look into ?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [27 January 2020 20:12 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/4 "2020-01-27T20:12:26Z")

</div>

That’s nice, I’m looking into it for hydroponics too. Atlas Scientific also creates good quality temperature probes and electric conductivity probes. All of them can be submerged, and depending on how you try to connect them they can be hooked to a single Tentacle T3 hat on top of a raspberry pi. It also exposes 2 inputs for I2C, one (or both) could be used to connect a peristaltic pump to mix your nutrient solution.

---

<div class="post-metadata">

**Author:** ![seth350](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/seth350/32/4617_2.png) [@seth350](https://discourse.nodered.org/u/seth350)\
**Post date:** [28 January 2020 04:31 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/6 "2020-01-28T04:31:50Z")

</div>

The sure fire way to control pH is to build a lookup table (aka: function generator).

PID controllers won’t control it reliably due to the logarithmic nature of pH.

First things third, you need to know how you will add your base/acid and in what volume. Dosing pumps are typically used and can be set to dispense a predefined amount per dose.

Once you have that figured out, google pH titrations and pH lookup table controllers.  
The titrations will be used to populate your lookup table.

Basically you want to find out the ratio between the volume of liquid to treat and how much volume of acid/base is needed to correct it to your needs.

A titration will need to be done for the acid and the base separately because both have different reaction times.

Once you have your samples, you can build your function generator that will output or infer the amount of acid/base to add to correct your pH based on your current pH and it’s concentration.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 January 2020 07:22 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/7 "2020-01-28T07:22:59Z")

</div>

> [@seth350](#):
>
> PID controllers won’t control it reliably due to the logarithmic nature of pH.

I have never tried but in principle that should be solved by controlling the log of pH (or the antilog dependent on which way round it is). Does that not work?

---

<div class="post-metadata">

**Author:** ![iiLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iilaw/32/14782_2.png) [@iiLaw](https://discourse.nodered.org/u/iiLaw)\
**Post date:** [28 January 2020 08:55 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/8 "2020-01-28T08:55:25Z")

</div>

> [@ALOKA1432](#):
>
> Atlas Scientific’s pH probes

Take a look at [https://www.whiteboxes.ch/shop/tentacle-t3-for-raspberry-pi/](https://www.whiteboxes.ch/shop/tentacle-t3-for-raspberry-pi/)  
t’s stackable and hosts up to 5 EZO devices from Atlas Scientific to measure PH, Dissolved Oxygen, Electric Conductivity (E.C.), Oxidation-Reduction Potential (ORP) temperature (RTD), peristaltic pump (EZO-PMP).

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [28 January 2020 09:40 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/9 "2020-01-28T09:40:38Z")

</div>

> **[Gravity Analog pH Meter Kit](https://www.robotshop.com/uk/gravity-analog-ph-meter-kit.html)**
>
> Analog pH meter designed for Arduino controllers
> LED to work as the Power Indicator, a BNC connector and PH2.0 sensor interface included
> Measuring Range: 0-14PH
> Accuracy: ± 0.1pH (25°C)

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [28 January 2020 10:34 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/10 "2020-01-28T10:34:45Z")

</div>

> [@iiLaw](#):
>
> t’s stackable

I particularly like how stackable they are:

> [@](#):
>
> By specification, Raspberry HATs are not stackable (That’s why the Tentacle isn’t allowed to be called a HAT). With the Tentacle T3 however you can stack multiple HATs to your Pi. You can stack multiple T3’s, or stack another, normally not stackable HAT on top of the Tentacle. You can easily stack 2 to get 4 isolated channels and 10 channels in total! If you have a beefy power supply and feel like messing with the pullup resistors on board, you can stack even more.
> 
> The Tentacle comes with an M2.5 standoff mounting kit.
> 
> You can also stack other HATs (that are not stackable by design). For them, the Tentacle is mostly transparent. The Tentacle doesn’t “occupy” any pins of the Raspberry. It’s connected to 5V, 3.3V, GND, SCL, SDA. The Tentacle adds pullup resistors to the I2C line so you don’t have to care about them.

I've been looking at Atlas Scientific probes as well as the T3 for a little under a year now. I've been looking into hydroponics for a couple years and I'm still trying to figure out if it would be worthwhile to set it up for personal usage rather than going commercial. So far I've figured out I can likely get the costs for starting up and operating out if I were to scale up and sell leftover produce, but working out if it would be worth it for the smaller scale is harder. Hence why I've read all these pages several times, but haven't bought any of them yet.

---

<div class="post-metadata">

**Author:** ![seth350](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/seth350/32/4617_2.png) [@seth350](https://discourse.nodered.org/u/seth350)\
**Post date:** [28 January 2020 12:00 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/11 "2020-01-28T12:00:21Z")

</div>

If you’re super clever with math, maybe you can do something with the log.

Not everyone, including me, is super clever with math. A lookup table is the one thing that does work very well and doesn’t require a deeper understanding of the math going on in a PID.

A PID will control the pH, but you will exacerbate the difficulty getting it to finely control it. It will more less always hover above and below your setpoint. For some applications that don’t require accuracy, this is fine.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 January 2020 12:20 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/12 "2020-01-28T12:20:37Z")

</div>

Using a lookup table is horrible, as you say that will never give you accurate results. The right way is using a linearisation function to approximately linearise the relationship between the control input and the pH. If anybody wants to do that then post where I can find the data and I will have a look. Not unless someone is actually going to try it out though, I don't want to spend the time unless it is worthwhile.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [28 January 2020 13:24 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/13 "2020-01-28T13:24:24Z")

</div>

I worked in various dyehouses for over 40 years so pH control is almost second nature to me.

Automatic pH control is extremely complex and has to take into account a number of variables:

1. Total system capacity.

2. Native water hardness.

3. Strength of acid/alkali donors for adjustments.

4. Accurate dosing of donors and time to reach pH equilibrium.

5. A meticulous electrode calibration scheme (For hydroponics a 1 point calibration daily at pH 4.01 should suffice)

6. Electrode contamination, electrodes need to be kept clean, and some are not suitable for continuous immersion.

There are automatic systems available but as always at a price.

[https://www.hg-hydroponics.co.uk/ph-ec-dosers--monitors-483-c.asp](https://www.hg-hydroponics.co.uk/ph-ec-dosers--monitors-483-c.asp)

I would love to see a node-red solution, small peristaltic pumps are quite cheap too.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 January 2020 13:56 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/14 "2020-01-28T13:56:31Z")

</div>

Having got all that setup what control algorithm was used to do the real time control?

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [28 January 2020 14:10 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/15 "2020-01-28T14:10:37Z")

</div>

I only ever saw automatic pH control on 2 dyeing machines in all those years, they were commercial - hard coded, I have no idea of the algorithm used, they were also very maintenance intensive.  
I think for hydroponics, where the pH range is from 5.5-5.8 to 6.5 it might be easier to just drive a peristaltic pump for a given time, wait until the pH stabilises and see how the pH has changed, repeat until an acceptable tolerance is reached. A job for Fuzzy Logic maybe?

---

<div class="post-metadata">

**Author:** ![seth350](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/seth350/32/4617_2.png) [@seth350](https://discourse.nodered.org/u/seth350)\
**Post date:** [29 January 2020 04:13 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/16 "2020-01-29T04:13:49Z")

</div>

A function generator will make it linear by using the titration data gathered from samples. It will characterize the the amount of acid/base added to the change in pH.

You would ultimately know if pH is X away from setpoint, you need to add approximately Y of acid/base to correct it.  
Sure, it will not correct it exactly to the setpoint, but it would be extremely close. From there, you can wait for the pH to stabilize and then add acid/base in smaller amounts until neutralization is reached.

---

<div class="post-metadata">

**Author:** ![dennishvo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dennishvo/32/2896_2.png) [@dennishvo](https://discourse.nodered.org/u/dennishvo)\
**Post date:** [30 January 2020 18:41 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/17 "2020-01-30T18:41:28Z")

</div>

I built an entire water monitoring system using node-red and multiple Atlas Scientific probes (pH, EC, DO). I have a bunch of nod-red code that handles the challenge of determining which sensor is reporting measurements, calibration, etc. Let me know if you want to chat.

---

<div class="post-metadata">

**Author:** ![ALOKA1432](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@ALOKA1432](https://discourse.nodered.org/u/ALOKA1432)\
**Post date:** [30 January 2020 18:56 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/18 "2020-01-30T18:56:38Z")

</div>

Yeah @dennishvo, Come online.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 February 2020 18:56 UTC](https://discourse.nodered.org/t/ph-controller-design/20918/19 "2020-02-13T18:56:43Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
