Reef nutrition

DIY Automated Alkalinity Tester

richiev

Supporting Member
I'm interested in Alkatronic / Tridents / ..., but the vendor lock-in and the high prices make me very gun shy on getting one. Over the psat months I keep coming across various hacky things where people built their own, and I've found that intriguing. In particular, I was reading the details of the DIY Alkalinity test guide, and doing a PH + Hydrochloric acid alkalinity test actually is pretty straightforward. That appears to be what others found, including the guy who built Alkabot.

With all that knowledge, I decided it'd be another fun little project to DIY build my own, and now I'm going to track it here. The main differences I want to do versus some of the others:
  • goal is a toy project for me, with some documentation if someone else wants to do it, not a business or whatever
  • I want this to be easy to put together, with as many purchasable parts as possible. I am not interested in starting from complete scratch and DIY building peristaltic pump heads and blah blah. That certainly will mean I pay more money, but I'd like to spend my time learning the electronics & tuning versus dealing with 3d printer tolerances (though I will eventually print a container and such).
    • In future versions maybe I'll have a buyX versus buildY variation
  • Overall cost should be less than a Trident. If this starts spiraling into $$$ I'll abort. My current thinking is the parts are going to be < $100, with the total cost being $100-$200 because I'll buy some misc parts in bulk for future projects (eg extra silicone tubing, filament, stepper controller boards, ...)
  • I want the testing device to focus on fault tolerance, and be dumb. I'll probably do the controlling from a raspberry pi running reef-pi, but I don't really expect it to be tied to reef-pi itself
That's the overall goals, and I'll drop some updates in here as I go.
 
  • Like
Reactions: JVU
Liquid control via diy wifi doser
Yesterday / today I got my first success completely working, I now have successfully created a wifi enabled doser. From my computer I can run a command to have my doser dump out a target number of ml of liquid.

Example:

Code:
$ mosquitto_pub -h $reefalker_ip -p 1883 -t debug/triggerML -m '{"ml": 15.0, "mlPerFullRotation": 0.28}'

That's dumping 15.0ml on the dot of liquid into a container. The mlPerFullRotation being what I calibrated a full rotation of the pump head to be equivalent to (0.28ml).


Parts:
That's most of what I'll need overall. I also bought some HCL acid, and I need to buy 2 more pumps. I think beyond that I really just need a container. The main other pieces are a ph probe & ph circuit, both of which I actually have from other reasons, but I'll get to those when I get further along.

And for one of the most boring to watch, but extremely satisfying to have done videos in the history of the internet. here's 25seconds of glory:


Told it from my laptop to output 5ml. Laptop hit the doser over wifi, and it output 5.0ml exactly (as measured by a kitchen scale, knowing that 1g = 1ml). Extremely satisfying.
 
Last edited:
Nice!
One thing to think about would be outputting the reading in a voltage equivalent to a ph probe. This way you could connect the tester to the ph port of any controller of you want to port the reading into it.
 
Nice!
One thing to think about would be outputting the reading in a voltage equivalent to a ph probe. This way you could connect the tester to the ph port of any controller of you want to port the reading into it.
That'd be interesting. My default plan is expose it over an API, returning the most recent test run(s). A nice thing about the reef-pi is you can trivially integrate an arbitrary sensor like that by using the file input. With that you just write a file with a number in it, and then periodically it'll read the file and use the value in it as the sensor value.

That's how I do my automated fan controls with it. I have a script periodically look at the temp, calc a fan speed, then write the % of fan on to a file. I can read that file into reef-pi and put it in a graph.

Outputting as a voltage similar to a ph probe is a very interesting thought on how to integrate in to something like an Apex. I'm not familiar with how people do custom sensors with that ecosystem (I don't have an apex currently).
 
pH Measurement via Robo-Tank pH circuit + BRS pH Probe
Next up is getting the pH measurement together. For this I am using a PH circuit from Rob @ robo-tank, and a BRS double junction PH probe. I also happen to have a collection of LCD screens from a different project I was going to attempt, so I'm using one of those as well for a quick display.

PXL_20230218_195219809.jpg

The pH Probe uses I2C, which is something I've never played with before. However it's super easy. It allows multiple devices to communicate along the same set of wires (bus). I've also never used a LCD display before, and it too uses I2C. Using that is also incredibly trivial to do with an Arduino. Generally, I feel all this is surprisingly straightforward, but requires scanning a couple docs to understand how to do it.

In the above pic the pH probe is sitting in some 7.0 calibration fluid. It's reading as 7.191, and using a calibration I'm reading it as 7.002. The two-point calibration function I'm using is:

Code:
pHx = pHref1 + (pHref2 – pHref1) * (Mx – Mref1) / (Mref2 - Mref1)
  • pHx - the pH of the sample
  • pHref1 - the pH of the calibration buffer 1 (generally 4)
  • pHref2 - the pH of the calibration buffer 2 (generally 7)
  • Mref1 - the measured value for buffer 1
  • Mref2 - the measured value for buffer 2
  • Mx - the measured value for the sample
The neat by-product is I have a wireless accessible pH probe. It of course still needs a power source (eg usb outlet) or could be potentially run off a battery, but it could be used as a pH probe without having to wire into the controller. I won't be using it that way in this use, in that it'll be part of the Alk tester, but possibly useful in the future.

Parts and costs:
That specific probe & circuit aren't really required, I think any combo would work, but I have both already for other reasons, so effectively they cost me $0. These also seem to be the best quality vs cost trade off I've seen, which is why I have them in the first place.

Next step is doing my first Alk test manually. Adding tank water to a container with the pH probe, then HCL acid until I get the right measurement. After that it should be straightforward to automate it all.
 
That’s very cool!

When it is automated and in its final form. What does it need from you to take a reading? How is the sample container emptied, etc…
 
That’s very cool!

When it is automated and in its final form. What does it need from you to take a reading? How is the sample container emptied, etc…
It shouldn't need anything. The tested water will be pumped back into the tank. It'll be the same as the existing saltwater, just with a low ph (~4.5). However it'll only be tens of mL so shouldn't adversely affect anything. Same setup as the KH director and Alkatronic.

Though I also was considering draining to a reservoir and then pumping extra saltwater in to the tank, as a very small minor water change, but that seems like a lot of ongoing maintenance work
 
Hot damn @richiev ! Let me know if I can help with pcb / mech design.
ESP32's are my fav MCU!

Since you are using an OLED display, take a look at this board: https://www.amazon.com/LILYGO-T-Display-S3-ESP32-S3-Development-Soldered/dp/B0BF542H39
I use these literally everywhere!
That's super cool. I just happen to have some OLEDs around for other purposes so using it for that. If someone was building one of these themselves that's certainly the way to go though.

Well, maybe not certainly for me, because I accidentally connect two things together that shouldn't be and cause the magic electronic smoke to be released more frequently than I'd like to admit. So having a bunch of really cheap, bulk purchased, $5 boards is valuable for me. I don't want to admit how many servo controller boards I've burnt out in the last month trying to learn how to use them...
 
One thing to consider: Just automatically measure Alkalinity DRIFT.
It is pretty hard to carefully calibrate and return a real Alk value.
But you don't really need it.
You use normal hand tests to get it right. All you need to know if it is drifting too far high/low.

I was considering a DIY thing a while back.
Never built it though.
https://bareefers.org/forum/threads/automated-alkalinity-measurement.17726/
That's basically what I'm building. The dKH calculation is very straightforward on top of it.

1. Pump water out of container into tank
2. Rinse container (pump water in, pump back out), also serves to prime the water line in case anything drained out

3. Begin titration loop, adding until set point of 4.5pH hit
3.1. add some acid, with mixer on
3.2. give it a bit to stabilize
3.3. measure pH
3.4. repeat if not at 4.5pH

4. Calculate & store dKH value

5. Dump water to tank
6. Add tank water back to container to keep the pH probe wet

Done

Exact amount of water to use and strength of acid I'll play with. I'd prefer not to dump 1L of 4.5pH water into the tank, but it also probably doesn't matter as long as I'm only doing it occasionally. I also could add kalk to my ATOn to compensate.

I bought some 1.0M strength HCL acid, but I'm now regretting it and am going to dilute it to 0.1M. I won't be able to dose, even by hand with a syringe, accurately enough to use 1.0 strength. In the future I'll just buy 0.1, but for now I'll make my own by mixing with RODI ahead of time. My exact strength will likely be off a bit, due to not being able to measure precisely enough, but the given batch should be consistent, so I'll just mix up 1L or 2L at once and store it for future use.
 
Last edited:
That's basically what I'm building. The dKH calculation is very straightforward on top of it.

1. Pump water out of container into tank
2. Rinse container (pump water in, pump back out), also serves to prime the water line in case anything drained out

3. Begin titration loop, adding until set point of 4.5pH hit
3.1. add some acid, with mixer on
3.2. give it a bit to stabilize
3.3. measure pH
3.4. repeat if not at 4.5pH

4. Calculate & store dKH value

5. Dump water to tank
6. Add tank water back to container to keep the pH probe wet

Done

Exact amount of water to use and strength of acid I'll play with. I'd prefer not to dump 1L of 4.5pH water into the tank, but it also probably doesn't matter as long as I'm only doing it occasionally. I also could add kalk to my ATOn to compensate.

I bought some 1.0M strength HCL acid, but I'm now regretting it and am going to dilute it to 0.1M. I won't be able to dose, even by hand with a syringe, accurately enough to use 1.0 strength. In the future I'll just buy 0.1, but for now I'll make my own by mixing with RODI ahead of time. My exact strength will likely be off a bit, due to not being able to measure precisely enough, but the given batch should be consistent, so I'll just mix up 1L or 2L at once and store it for future use.

It has been some 7 years since I looked into it, but I really remember that the dKH calculation was not that easy.
Pretty non linear.
It was reasonable pretty close to normal values for our tank.
The problem was more with calibrating.
You calibrate with RODI that is way out of the normal range.
So I gave up on a real number, and just planned to track drift.

Yes, my plan was to use 0.1 acid, to reduce accuracy concerns, plus a bit for safety reasons.

I had some tricks with siphons planned to reduce the need for a lot of pumps, but I think that was probably a bad idea in retrospect.

Be careful of CO2 levels. Especially in your "3.2" part where you let it sit for a while and stabilize.
 
For dkH, you can use a big lookup table with piecewise approximation from there.
The problem is running all those tests to get the values for the table.
 
@rygh Can you take a look at this guide and give your opinion? http://www.reefedition.com/a-diy-alkalinity-test-by-randy-holmes-farley/

That boils down to a simple set of equations at the bottom:

Equation 1: Alkalinity (meq/L) = [volume of acid added added (mL)/Volume of tank sample (mL)] x 100

Equation 2: Alkalinity (dKH) = [volume of acid added added (mL)/Volume of tank sample (mL)] x 280
For example, if you added 20 ml of 0.1 N acid to get to the endpoint using 500 mL of aquarium water, the alkalinity would be 11 dKH (which is (20/500)x280 = 11 dKH).

There is a big table at the bottom as well, but my understanding is that's if you don't know how to run an equation and just want a reference.

You definitely need a pH probe calibrated properly, but I've been taking that as a given and I have pH 4&7 reference solutions I'm using to produce the pH calibration formula.

I'm curious if this is what you're referring to, and if so if I'm misreading something. Alternatively this may be a simplification of what you're referring to.

Edit: Also I should clarify, those equations assume 0.1M HCL. Adjusting them to a different concentration I assume is a simple multiplicative conversion, but I'm going to use 0.1M anyway going forward.
 
Last edited:
If you plan on open sourcing this or any other stuff, let me know - Happy to help with any of the mechatronics!
Initial hacky code is on GitHub. Calling it Buff, ala Alkalinity as a buffer. My first name was Alkie, but I figured that was a bit... beyond my willingness to make a public joke.


Zero tests. Code is randomly placed in files. No .h vs .cpp separation. No docs beyond what's in this thread. Code is setup for PlatformIO development, and is using it as the dependency manager.

I'm out of town for a couple days again so I'll be putting it on hold until next week. Feel free to take a look, poke around, ...
 
Alkalinity is defined as the solution’s acid-neutralizing capacity (ie pH buffering capacity against added acid). So the amount of acid in meq/L you have to add to the solution to reach the point where you break the buffering capacity (by reaching a pH of 4.5 for example) is directly the alkalinity in meq/L. We use the silly term of dKh, but that is simple math to get to from meq/L.

The pH curve is potentially complex and curvilinear (since it is breaking a buffering capacity), but the end result of the alkalinity number is linearly related to number of drops.

My understanding is that this is the easy part.
 
@rygh Can you take a look at this guide and give your opinion? http://www.reefedition.com/a-diy-alkalinity-test-by-randy-holmes-farley/

That boils down to a simple set of equations at the bottom:



There is a big table at the bottom as well, but my understanding is that's if you don't know how to run an equation and just want a reference.

You definitely need a pH probe calibrated properly, but I've been taking that as a given and I have pH 4&7 reference solutions I'm using to produce the pH calibration formula.

I'm curious if this is what you're referring to, and if so if I'm misreading something. Alternatively this may be a simplification of what you're referring to.

Edit: Also I should clarify, those equations assume 0.1M HCL. Adjusting them to a different concentration I assume is a simple multiplicative conversion, but I'm going to use 0.1M anyway going forward.
As I understand, this is the curve.
1676958189115.png

Not very linear.
But a linear approximation is probably OK. I have never tried to calculate the error.
 
At any rate, the code is probably the easy part.
The tricky part is the correct amount of water in/out, the correct amount of acid, keeping things clean, and so on.
Will the measurements be repeatable on your system.

My proposed solution to that was to make it part of the water exchange, and use a Liter or so of water per test.
That large volume made inconsistencies in pumps and such a smaller percentage.
 
As I understand, this is the curve.
View attachment 45537
Not very linear.
But a linear approximation is probably OK. I have never tried to calculate the error.
See my post above Mark. In the graph you posted, the flatter part of the black line is where it is buffering. The steeper part at around pH 4.5 is where the acid-buffering capacity (aka Alkalinity) has been overcome by the added acid, yielding a sharp drop in pH at that point with additional added acid. The number of meq/L of acid added needed to get to that point is the Alkalinity. None of the other points on this graph matter for determining the alkalinity, so the fact that it curves is not relevant to converting number of drops of acid needed to the alkalinity.

Note for example, in the red line above, pure water, you get to the point of pH less than or equal to 4.5 at the very first drop of acid, because there’s no carbonate buffer, and no alkalinity.

To emphasize: You are not modeling the curve to determine the alkalinity. You are adding drops until you get to (or below) pH 4.5, and counting up the drops (meq/L) added.
 
Back
Top