An Arduino-based toilet cistern monitor.
Sometimes the toilet needs an extra flush, and the cistern takes a while to fill up. How full is it? How long should I wait?
These are important questions.
Finally, we have answers.
Sensor at work:
An ultrasound distance sensor is installed within the toilet cistern. It emits ultrasound pulses which are reflected from the water surface and indicate the tank fill level. The sensor is controller by an Arduino microcontroller which reads the data, and generates the "image" to be displayed on the connected 8x8 LED matrix.
Electronics:
- 1 Arduino Leonardo
- 1 8x8 LED matrix
- 1 HC-SR04 Ultrasonic distance sensor
- Ribbon cable
- Jumper pin connectors
- 1 Ethernet cable
- 1 Mini breadboard
- 1 USB power supply
Other:
- 1 Small plastic box
- Double-sided sticky tape
- Cardboard
- Small screws
- Drill and assorted bits
- Various small pliers, screwdriver, common tools
This was done in 2 parts, with the sensor adapter and the display module built seperately
Within the toilet cistern I found that there were 2 removable plastic clips which hold a protective plate onto it's front. Each of these had a small pre-existing hole bored through it, which was ideal for mounting the sensor in the right direction. To this plastic clip I attached an angled piece of metal, and the mini breadboard on the other end. The sensor sits here facing downward and "secured" by a tie-wrap. I cut open an Ethernet cable and used 4 of the inner wires to connect the breadboard.
Initially I prototyped the project using the Ethernet cable trailing out and everything hooked up to a breadboard:
This was enough to prove the concept worked within the cistern and interference didn't occur with the sides of the tank.
Next I moved on to mounting the components in a case. This was a repurposed 200g Ferrero Rocher box. I drilled two holes in the bottom (not visible here) large enough to admit the Ethernet cable and micro-USB power supply.
And connecting them with some 12cm lengths of ribbon cable:
And with this complete, I tidied up the wiring, reattached the flush button, mounted the whole unit to the wall, and powered it up:
See the full Arduino C++ code in toilet-sensor.ino.
This can also be viewed in the Fritzing software using the diagram.fzz file.
Once the sensor and display were installed, the readings needed to be calibrated, since there's no way to know exactly how high or low the water level will be in comparison to the test runs (The sensor angle might have shifted during installation, etc). Calibration can be done very easily by capturing the serial output of the Arduino and exporting it to a spreadsheet.
Due to the confined space within the cistern and the natural movement of the water as it refills, the data at the start and end of the refill cycle is quite noisy. Ideally this would be solved by taking higher frequency measurements and smoothing for an average value, but this can come later.
For simplicity, in this example I take the top
value as 400
and the bottom
value as 1900
. These values are configured at the top of the code file.
These tutorials and guides proved useful during the project