While I was looking online for solenoid valves for my irrigation system, I discovered flow sensors… so I got myself one, like this one:
The idea is that the flow sensor allows me to measure how much water is being used out of my rainwater tanks (and going onto the garden).
First a bit of an idea of what the flow sensor looks like attached to the output of the pump:
The flow sensor is next after the (yellow) pump controller. It requires a DC power supply of 5V to 24V – I am using 5V, and provides an open drain output, which I have connected to one of the channels of an opto-coupler. (One mistake I made was putting the flow sensor too close to the pump. When the pump switches off, the sensor picks up interference.)
The output of the optocoupler (LTV847) is fed into a cascaded pair of 4 bit binary counters (74HC4520). The outputs of the counter are then fed into GPIO port B of a MCP 23017 GPIO expander which is on the I2C bus of the Raspberry Pi Zero that is the brains of my irrigation controller. The INTB line of the MCP23017 is fed into one of the GPIOs of the Zero. That allows me to generate an interrupt when one of the GPIO pins on the MCP changes state – I have configured an interrupt to be raised when bit 7 of the counter changes from zero to one. (GPIO pin numbers are WiringPi pin numbers.)
The daemon which logs flow data then increments the flow counter whenever an interrupt is raised. The lower bits of the counter can be read from the MCP23017 whenever required.
Soldered onto veroboard it looks like this:
Currently I am feeding the data from the flow sensor into a ThingSpeak channel: