Water Softeners are great - we live in London where the water is medium hardness, but even that has a significant impact on the plumbing. We were constantly scrubbing the scale off the bathtub, toilets, and the shower screen. It also clogs up pipes and valves. Hard water also has an impact on how soap foams and how it affects your skin. We decided to get a water softener and are happy we did.
Water softeners work by passing the water supply through a canister containing resin beads. The resin beads are conditioned (typically overnight) by sending a brine through the beads. The brine is discarded through a drain. For more information, see
https://www.water2buy.com/, we ended up with W2B200 model.
The install was a bit of a pain, but a good plumber put it in within a day. It certainly would not fit under the sink, so it is in the neighbouring cupboard. Photo of it unmodified below, which has my reflection in the cover. It isn't exactly an M. C. Escher
https://en.wikipedia.org/wiki/M._C._Escher.
You may have noticed the two marks written on the water softener. These indicate the minimum and maximum salt hopper fill levels. This represents a *lot* of salt. Roughly 25kg per month - you can see the remnants of the first bag to the right bottom in the photo.
We have had it for less than a month, so we are keeping a close eye on the salt hopper, but clearly our vigilance won't last. I decided I wanted some way of keep track of the salt in the hopper.
Project Overview
The project diagram is shown below. A RPi Zero W talks I2C to a Time of Flight Sensor, which provides the distance to the salt. The Pi calculates how much salt is remaining and displays that on a neopixel strip. At given hours, it sends a message to Telegram, which forwards that to my phone. At the moment, it sends messages at 07:00, 18:00, and 20:00. This is the time period when I will likely be awake and be able to deal with low salt. It is probably more than needed, but I am still working out bugs, so the messages are a good remote heartbeat.
A photo and video of the project is included below. The neopixel effects are only reacting to the measurements. They use a simple animation as I didn't want anything to flashy, but also wanted to know immediately that everything was still actually functioning. As we use this cupboard almost every day, the quick visual check is useful as a watchdog as well as informative.
Screenshot of Telegram shown here - note that I can send a small number of commands to get information from the Pi.
All in all, I am pretty pleased with how it has gone. It still needs work, but most of the work has been completed.
Details of the build
Time of Flight Sensor
I decided to use a Time of Flight (ToF) sensor that I had lying around to measure the distance from the top of the hopper to the salt. I am using a chinese breakout board version of VL53L0X (about £4 on Amazon). Additional info on this type of sensor is here
https://learn.adafruit.com/adafruit-vl53l0x-micro-lidar-distance-sensor-breakout/arduino-code. The sensor measures the distance to the salt by calculating it via the length of time it takes to get a reflection back from a laser it shot out (hence Time of Flight). It works great, except it has huge error with salt for some reason! I added a plate to the hopper as a target. The addition of the plate meant a correct measurement of 23cm, instead of the incorrect measurement with only the salt at 31cm (35% error!). Of course there was a debate about which plate to use - see below, which shows the inside of the hopper. The green cylinder contains all the resin and does the softening. The salt is pillow shaped.
The ToF sensor is simple to use. Connect via standard I2C and use the Adafruit library to get the measurement in mm. The measurement is then used to calculate how much salt is left.
Neopixel Stip
The neopixel strip is a standard 60 pixel/metre strip of WS2812 neopixels. I am using 22 of them, so everything is adjusted for that. The standard RPi WS2812 library works fine. To get better colour representation, I pass in a gamma correction matrix, which adjusts for visual perception. I use HSV colour scheme to get the gradual effect shown, otherwise it can be difficult to get the RGB values correct.
Telegram Interface
Looking into the possibilities, I was thinking of a WhatsApp interface, but it didn't seem as easy as it should be. Twitter is obviously also possible, but I wanted a messaging App. It turns out a telegram interface is fairly straightforward and loads of information is available. Some basic logic was required, but a Telegram interface turned out to be very simple. Two way communication is straightforward and commands can be responded to. Some information below.
Physical Build
The system is hidden away and I just wanted something cheap and cheerful to package the project. I used one of my favorite boxes, a Schneider IP55 boxes (80mm x 80mm x 45mm) that are available from various retailers for about £2. A Pi Zero W with a homemade hat fits fine. I bolted it to the lid as it gives better access to the Pi. The box is velcroed to the side of the cupboard, which is very convenient if something goes wrong with the hardware. Just rip if off the wall, which results in that satisfying velcro sound. A 2.5m strip is very cheap (~5).
I put the ToF sensor into the cheap plastic hopper lid and attached it by some velcro and some cable ties. I will probably build a wood lid to replace the lid which is thin plastic.
Code
Code is available on GitHub, but it is still a work in progress at the moment and has not been cleaned up or productised. Enough caveats?
Conclusion
This is really a simple project that is quite straightforward and was easy to get the initial version working. As usual, dealing with defects and refining it takes much more time than expected. All of the tech used is well documented in many good sites, so it is relatively easy to sort through how to put it all together.