Having a swimming pool is great: you can have at any moment a regenerating swim during hot summer days. It is even pretty simple to mantain: you just have to make sure there is chlorine and, most important, that the pH is right. I have taken care manually of the pool for years but I recently decided to install an automatic pH regulator, well actually I decided to design, build and install one.
Why not buy one?
In those cases the question I get asked most is: “But why didn’t you just buy and install one?”. My answer is that of course I could have bought one but why pay for something that already exists when I can pay (usually not much less) for the components and have so much fun in the process of making my one?
Block Diagram
The general idea of the project is pretty straightforward: the system needs to have a probe sensing the pH, a peristaltic pump for dispensing “pH PLUS” product and one for dispensing “ph MINUS” product. In reality the pH only tends to increase so altho I planned for both, I then implemented only the latter.
One more thing I was interested in was to know from my PC the actual value of water temperature and pH and how much product was left in the tank so that it never runs out without me noticing it.
Schematics

I designed the board around the trusted AVR128DB32 which I have already used in some previous PCBs. The only noteworthy think is the whole schematics is the pH probe sensing circuitry since cause of the high impedance of the probe care must be taken in the choice of the buffer amplifier and in the circuit layout

I decided to use the OpAmp LMP2231 that tanks to its low input bias current and low offset voltage allows to have an accurate reading of the pH value. R32 is there to compensate the effect of input bias current and C31 for loop stability. The buffered value is then digitalized by a MCP3242, a differential 4 channels, 18 bit delta sigma ADC.
R34 and C28 form a low-pass filter to help removing noise with special care to the 50Hz mains induced noise
As for the remote control / monitoring I have included an ESP8266b module which communicates with the microcontroller via USART
PCB
As for the PCB I went with a 4-layers design (signal – ground – power – signal)

In the picture a rendering of the PCB can be seen. On the bottom side, from left to right, there is the power connector (3d model not dhown), the pH probe BNC connector, Pt1000 BNC connector, pH PLUSchannel (which include the control of the peristaltic pump, and the sensing of the amount of product remaining in the tank, via the load cell) and an identical connector for the pH MINUS channel.
Assembly
The PCB were assembled with the help of my friend Alessio who kindly allowd me to use his reflow oven and ultrasound cleaner
The control board was then mounted inside of a flanged ABS case where the OLED display is also attached


Software
The software was developed using Microchip Studio 7 in C
The most interesting thing worth highlighting are the use of lowpass digital Butterworth FIR for filtering the sensitive pH input signal. In fact with no filtering quite a lot of noise could be seen overimposed the signal (mainly 50Hz noise due to the proximity of the pump that recirculates the water in the pool)
Mounting Flange
One of the most important aspects of this project is the flange for mounting the pH probe, temperature sensor and pH MINUS product inlet. The flange was designed in Inventor and 3D printed with PLA since it has to be rigid and the operating temperature are pretty low (never higher than 30°C)

The flange needs to be mounted on the pipe that comes out of the sand filter and goes into the pool. This way the injected chemicals go directly into the pool acting as needed. The product inlet and Pt1000 temperature sensors are seaed using bi-component resin to prevent leakages. The threaded insert covered with a cap is where the pH probe will be inserted: the cap is there so that if for whatever reason the pH probe needs to be removed, the hole can be plugget with the plug preventing water from coming our

Bottom view of the flange: an O-RING seals the opening drilled into the pipe