ESP8266 flow meters

Here, real quick is my implementation of two liquid glow meters on an MQTT enabled ESP.  I really was thinking about what in my house to instrument, but it always seems that I want everything to be automated, but it’s hard to decide what you’d do with the data once you put so much effort into getting it.  I figured I’d instrument the hot and cold water to look for leaks, and to watch my usage.  I may only need a tiny hot water heater, or I may be running it out fast.  Also, charting the time on of the hot faucet may give an indication to how much water is wasted staying cold in the pex.  Anyway, my data could be used to size upgrades or energy saving things for the house, and the whole thing cost less than $20 in quantity one, so why not.

I decided to go with a plastic flow meter I got from an ebay seller whose cart I was filling up to get free shipping (see, I use the fluff I pad with).  They happen to be the same as the plastic flowmeters adafruit stock, so that’s nice.  The sensor inside is essentially a waterwheel and hall-effect sensor that counts rotations.  The sensor says it operates from 5 to 18v, but I would rather it run at 3.3.  I elected to just run it at 5 because the sensor may be less responsive, or accurate if it even did anything at 3.3v.  The output is in pulses and the pulses are naturally 5 volts, which is a problem for me.  The best thing about uni-directional sensors is that the voltage divider is just a pair of resistors.  Put simply, the voltage drop across the resistors is going to be 5 volts, but you can pick where along the drop from 5 to 0 you want and get a lower voltage signal out.  This is what I did to take the inputs from both flow meters (12K and 22K resistors were used to good effect, I have heard problems with different values).  The total bill of materials for this project is 4 resistors, 2 sensors, and one NodeMCU (which can be changed to an esp-01 when it is done being developed).  I’d say that’s pretty cheap for network logging flow meters.

This time the code is relatively simple, but with one quirk: we’re using interrupts.  The code that adafruit provided uses the hardware registers on the arduino to set the interrupts but we use a simpler method, with the ESP you can simply say attachInterrupt(pin#, function, type).  In that statement the pin# is which pin should be used for sensing, function is the function that will be executed when the interrupt is detected, and type is whether it is on a low-to-high transition, high-to-low, or either.  With that, a local counter variable, and some math to convert to liters you can see just how many liters have flowed past the meter since you last checked.  This is a rather basic implementation to show the concept with just 2 MQTT commands to read the flow out, in a final version I would add an RTC to send updates periodically, another command to zero the count, and auto-zeroing on perhaps a daily basis after the data has been sent and acknowledged as recorded.

As should be expected the code is here.

The rest of this series can be gotten through from the home page here.

Advertisements

Tags:

6 Responses to “ESP8266 flow meters”

  1. Intro to my ESP8266 adventures | Evan's Techie-Blog Says:

    […] Flow meter (for reading water flow, hot and cold) […]

  2. Jean Roux Says:

    Thank you for the article! I am looking into doing same, but without Arduino, only ESP Easy on the ESP, to MQTT / NodeRed on RPi. I bought the same flow meter, want to ass to my geyser – incoming cold line, but on your linked Adafruit product, I see it only has “Durability: minimum 300,000 cycles”, thus at 450 pulses per litre, 666,7 litres? thus the flow meter will only hold for 8 baths? (@ 80 litres per bath?) Or am I understanding the durability stats incorrectly ?

    • abzman2000 Says:

      I will tell you this honestly, I have absolutely no idea how to interpret that number. I’d put a ball valve on either side sandwiching unions sandwiching the sensor in case it fails, but then again that may be a bit over the top…

  3. Iannis Iliopoulos Says:

    I also believe that life-time is wrong or meter is a toy. But your ardino firmware needs some kind of ‘reconnect()’ function. esp8266 will lose wifi connection after few minutes and you will have no updated subscription at all.
    So from within loop() you must call reconnect() function. Inside reconnect function you simply reconnect to wifi, if it is not available, connect to mqtt server-broker and then re- subscribe to preffered topics. Piece of cake. Enjoy!

    • abzman2000 Says:

      I’m entirely sure that meter is a toy, but I lost my ability to get surplus omega meters when I changed jobs. If this proves useful then it’ll be upgraded to something more reliable. Thanks for the tip on the reconnect code, I haven’t implemented any of this in my house yet but having the proof of concept done lowers the barrier to entry when I have the time to make some more progress on this.

  4. Matthew Wawrzyniec Says:

    Can you draw a schematic of your circuit?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: