Whilst most of us are lucky enough to have running water on tap, it is however a scarce resource, something we should not needlessly waste. Whilst upgrading some of the plumbing in my flat, I decided to install water flow sensors to monitor my water usage, by monitoring usage I can track changes in over time and hopefully reduce the wasted water.
I had a prototype for the sensor monitor in the works, an Adafruit Feather-based design, however this needed some debugging as well as implementing network connectivity so I didn't have to use a USB connection. A full description of water monitor is out of scope here, but will be described in another project, full schematics and PCB design can be found on GitHub. This project focuses on getting the water monitor onto my network (with a little background).
Background - Water Flow SensorA quick search on eBay and AliExpress reveals a number of flow sensors suitable for connecting to pipework and appliances. After buying many versions of these I finally found one that fitted inline with 15mm pipework. I settled on the 60mm version of SEN-HZ21WI. Other versions tend to have one port for a 15mm pipe and the other a flat surface suitable for flexible pipe connections (e.g. the washing machine feed pipe).
This sensor works using a hall effect sensor with some integrated logic, it takes a supply voltage (red and black wires), 5V is suitable for this, and returns a pulsed signal on the yellow wire. This will pulse about 520-560 times per litre of water.
The output is open collector, meaning it will pull down a digital pin, but won't power it, using INPUT_PULLUP for the mictrocontroller we can sense the pulses. However in the interest of protection I added a 1k current limiting resistor and optional high value pull down (I've specified 100k here, but that's way to large in reality).
This is all great and very easy to connect our flow sensor to the micro, however this sensor consumes about 6mA each and needs to be constantly powered (144mAH/day -> 14 days on a 2000mAH battery with just 1 sensor), this severely limits out abilities to run from a battery, not to mention power needed for any radio (WiFi) connectivity.
Connectivity - WIZNet WIZ750SRBy using an Adafruit Feather board we have a range of connectivity options, however with the placement of the device (in my boiler cupboard, surrounded by large metallic objects) radio based connectivity may struggle. Likewise if this was to be used in a commercial environment, many may struggle to get this type of device connected to WiFi, where as a wired connection may be much easier.
In addition to needing connectivity the monitor also requires power, personally I don't have a electric outlet in my boiler cupboard, however I do have Ethernet sockets (obviously not everybody has this, but it's likely to be easier to run a CAT5 Ethernet cable than getting an electrical outlet installed).
So I decided to go with an Ethernet connection and POE for power.
As is typical during the debugging phase of the project I used the serial port a lot to output the sensor data and read user instructions. This is where the WIZNet WIZ750SR really shines, by simply connecting the Feather Rx/Tx/GND pins to the WIZ750SR's Tx/Rx/GND pins I was able to send normal serial data to a network connection, as well as receive values sent back, The 3v3 pin of the Feather is used to power the WIZNet module.
Below is the checkSerialCommand function to read user commands, you can see identical code to handle the USB serial connectivity commands as well as those read from the network connection via the hardware serial port (connected to the WIZNet module).
void checkSerialCommands() {
// WIZNet ethernet connection
while (Serial1.available()) {
char command = Serial1.read();
processSerialCommand(command);
}
// USB serial
while (Serial.available()) {
char command = Serial.read();
processSerialCommand(command);
}
}
Bonus features on the WIZ750SR are 4 digital IO ports, whilst the system is being debugged one of these pins can be connected to the Feather's reset pin, allowing remote reset of the prototype in the (cough - unlikely - cough) event my firmware crashes - especially useful now that it's at the back of my boiler cupboard and is difficult to get to.
Additionally using the WIZNet Virtual Serial Port the module can act as a serial port on the PC, so software to talk with the monitor can use either the remote Ethernet connection or a local USB connection in exactly the same way with just a change of COM port required, as well as not requiring TCP knowledge by the developer.
Using the built in serial port rather than trying to configure WiFi and MQTT or HTTP connections means the project is up and running quicker, with less risk of failure down the line when the WiFi credentials change. With other WiFi projects I've worked on I've lost many hours during the project just waiting for WiFi to reconnect after a firmware update, using the build in hardware serial port and the WIZNet module publishing status over the network is up and running instantly.
Configuring the WIZ750SR is also incredibly simple. I ran the WIZ750SR configuration tool, this picked up my module with no problem. Other than changing the IP address to be a known fixed IP address on my local network and changing the TCP port to 80 (meaning I could update the code to output HTML and use a browser to read water usage in the future) I did not need to make any other changes.
Once configured and connected to the water monitor I was able to open Putty to establish a TCP connection to the device and view as well as interact with the water monitor in the same way I was able to with a USB serial connection.
Whilst I'm still debugging the firmware and interested in what happens with the system, it's easy to open up a putty session and see verbose data, moving forward this could be output as json allowing easy parsing for a monitor application, such as Node Red and published to my favourite IoT platform (Tinamous.com :-) )
A bonus of using Ethernet is that I'm able to connect to my POE switch which supplies power via the CAT5 Ethernet connection using the 802.3af standard. Sadly the WIZNet module doesn't support POE directly, but POE splitters are readily available and cheap. The one I used is set to split the power out to a DC jack, I set it to 7V DC in this case (although 5V and 12V are also available). This version of the monitor has a build on-board 5V regulator to allow a 12V supply to be used with the FET switched outputs for valves on the supply. As I'm not using that at present I've set the POE splitter to 7V to reduce the loss and heat on the DC converter (a 7805).
As a side not, I couldn't find any WIZNet modules that do directly support 802.3af POE, which is a shame, having an option of that would make a lot of connected devices more interesting by providing power and network connectivity on a single cable, where power may not be easily available, or at-least significantly more expensive to get an electrician in to wire up a socket than it is to throw a CAT5 cable, for example in the loft.
Finished Install
I added a flow sensor on the shower cold water supply (left pipe) and the supply to the boiler (bottom right - domestic hot water temperature is about 65°C, which is out of the working range for the sensors, so flow needs to be on the boiler input - however this means I get the whole house hot water usage without needing more sensors and plumbing). I 3D-printed an enclosure to hold the ThingySticks water monitor and the WIZNet module, bolted the POE Splitter on to the case lid and connected it all up.
The WIZNet WIZ750SR makes it incredibly simple to add network connectivity to a project without the overhead and issues of WiFi, by using just the hardware serial port available on most dev boards.
If the project also requires power and a source isn't readily available, it's potentially easier to run a CAT5/6 network cable to the device and deliver power using POE and then get connectivity via a reliable Ethernet link.
Comments