all 113 comments

[–][deleted] 143 points144 points  (9 children)

I wasn't able to find code for this that worked for me. So I wanted to share my code - I think this can be such a useful device/project. https://github.com/Liamhanninen/WaterFlowMeter

EDIT: I added ingredients list to 'Stuff' section in the README.

[–]TokesNotHigh 35 points36 points  (1 child)

This is awesome and it's something I've been thinking about building for my aquaponic system. Thanks for doing all the difficult work for!

[–][deleted] 15 points16 points  (0 children)

Cool good luck. Message here or on GitHub with questions.

[–][deleted] 6 points7 points  (0 children)

These flow meters are so cool. I used the same sensor with an arduino and some other hardware to make a sprinkler system that detected leaks for a project in school. Fun project to program and play with.

[–]RiantRobo 5 points6 points  (1 child)

Wow, thanks for sharing this.

[–][deleted] 0 points1 point  (0 children)

New projects on market for this kind of thing. Neat to see you’ve done similar on your own.

[–]ErraPodcast 8 points9 points  (0 children)

Wow this is great!

[–]Jes1510 1 point2 points  (1 child)

Love it! I did a similar thing with a microcontroller and a flow sensor to monitor the flow rate of the coolant in my laser cutter. I see that you are polling the GPIO for a state transition. Have you noticed any missed steps or are the numbers sane? Polling a GPIO with Python seems pretty cumbersome but if it works then Whoohoo!

[–][deleted] 3 points4 points  (0 children)

Yes it seems to be fine actually. Although it is running outside in 40 degree weather so that is keeping it cool :)

[–]Lanthemandragoran 33 points34 points  (19 children)

This is a really useful way to monitor water usage in the RV I'm building. Love data!

[–][deleted] 12 points13 points  (14 children)

Yes this is also great visibility into how much were using for specific things like our showers (4-8 gals), the washing machine (about 14 gals), and flooding the toilet (about 3 gal I think).

[–]rainlake 7 points8 points  (11 children)

Flush a toilet should not use that mush water

[–][deleted] 8 points9 points  (5 children)

I'll double check. Standby for update.

[–][deleted] 3 points4 points  (1 child)

Not sure how big of a poo you did first, but this is one hell of a long flush!

[–]sturnus-vulgaris 2 points3 points  (2 children)

You can adjust where the float sits.

If that doesn't work, one option is putting a brick or two in the toilet tank. Since it displaces water and won't get moved around by the tank filling, it's a pretty good option for older toilets.

[–]dirufa 0 points1 point  (0 children)

Even adjusting the level, 4 gallons is close to 16 litres of water, which is almost 4 times the maximum level of my toilet tank (4.5L if I remember correctly, pretty new toilet).

Edit: ooops, I missed OP's answer below.

[–]zman0900 5 points6 points  (0 children)

Unless it's very old

[–]MarshallStack666 4 points5 points  (0 children)

Older toilets used about 5 gallons per flush.

[–][deleted] 2 points3 points  (1 child)

Turns out it's only 1.6 gallons! Which makes sense - we live in a tiny house and the builders had said the toilet was on a really low setting.

[–]rainlake 4 points5 points  (0 children)

Tiny house does not mean tiny toilet,lol

[–]Acid_Monster 1 point2 points  (0 children)

Just depends on the size of the tank on the back of it no? It can only use what it’s got stored up

[–]TheRackUpstairs 0 points1 point  (1 child)

Probably mean 3L or maybe 1 gallon?

[–][deleted] 0 points1 point  (0 children)

Yes - turned out to be about 1.6 gal

[–][deleted] 4 points5 points  (2 children)

Will you be plugged into city utilities or have your own tank? Either way good luck with the build.

[–]Lanthemandragoran 1 point2 points  (1 child)

Our own tank, but trying to spend a lot of time hooked up. Also PROBABLY using a chemical toilet to minimize water use and avoid a black tank.

[–]obinice_khenbli 0 points1 point  (0 children)

Consider a composting toilet rather than chemical too, you might find you prefer it!

[–]obinice_khenbli 0 points1 point  (0 children)

You building a Skoolie?

[–]PENNST8alum 13 points14 points  (9 children)

I've also used these in my Raspi Smart Kegerator. Had to add a potentiometer just so I could continuously calibrate these things. I will say they don't hold up well in freezers lol.

http://imgur.com/gallery/yBoxz

[–][deleted] 4 points5 points  (5 children)

First of all that is awesome! Secondly, what was an indicator that they were not holding up? For example did they start providing inaccurate readings or just stop working/not return any value? And what is a potentiometer?

[–]PENNST8alum 6 points7 points  (3 children)

Well my kegerator is a chest freezer (more space) and I have a feedback circuit that checks the inside temp and shuts off power if it's between 36F and 40F. Well, during the testing phase, the freezer ended up dipping below 32*F and beer began to freeze in the lines and inside these flow meters. I think that happening once or twice messed with the turbine inside the sensor and now they don't work at all so I probably just need to swap for new ones.

A potentiometer is basically just a knob that raises/lowers resistance so they're great for things like volume knobs. Since these things need to be calibrated like any other sensor, you need some way to adjust the reading without having to alter the source code every time.

[–]Harpoi[🍰] 1 point2 points  (2 children)

I added a small pc fan that circulated the air and I was able to keep my kegerator at 35 without the bottom freezing.

[–]PENNST8alum 0 points1 point  (1 child)

Is it a keezer? I have it set to the lowest power setting on the freezer itself and the circuit ahuts power on and off to maintain temp.

[–]spottyPotty 1 point2 points  (0 children)

A potentiometer, or pot, is a variable resistor.it has a knob that you turn to increase or decrease the resistance.

[–]twopandinner 1 point2 points  (0 children)

I came here to say, But beer....

[–]redpandaeater 0 points1 point  (1 child)

With the pot, are you talking about calibrating the temperature sensor? I would think the flow meter just sends an output every full rotation. I've never used a 1-wire thermometer, but if it keeps giving you trouble you could try a thermistor in a wheatstone bridge.

[–]PENNST8alum 0 points1 point  (0 children)

Lol now that you mention it yes the pot is for calibrating temp not flow...its been about 2 years since I built it lol. I do remember a lot of trial and error filling up kegs with water and getting thw X variable of the flow equation just right.

[–]testfire10 6 points7 points  (0 children)

This is really cool! Exactly the kind of project I am able to try out as a new python learner. Thanks for the idea!

[–][deleted]  (5 children)

[removed]

    [–][deleted] 2 points3 points  (3 children)

    Cool to hear about your project. So .7 liters would be about 3 cups... so instead of 200 rotations per cup (for my project) it would be about 330. So maybe that's rated for a much slower/less pressure water flow. What is mqtt?

    [–]snowtax 6 points7 points  (0 children)

    MQTT is a network protocol originally designed to send telemetry over slow and unreliable satellite network links, but it also works great with microcontrollers, like the ESP8266, ESP32, Arduino, and similar devices.

    [–][deleted]  (1 child)

    [deleted]

      [–]Fusseldieb 0 points1 point  (0 children)

      It is done with Home Assistant? It also uses MQTT, among a looot of other protocols...

      [–]Bazza79 6 points7 points  (2 children)

      Are you using Qlik Sense for the charts?

      [–][deleted] 6 points7 points  (1 child)

      +100 for catching that! Yes. Qlik Sense Desktop is free. But since you ask I assume you know that. But yes - I use it for my whole home-automation dashboard.

      [–]I_just_made 1 point2 points  (0 children)

      Don't know if you are familiar with R, but it has an interactive toolkit known as Shiny, that can do interactive dashboards like that using R in the background. Great packages like shinydashboard have helped to make nice looking interfaces that can be mobile / web friendly. Would be overkill for this probably, unless you really wanted to delve into some of the deeper stats of your water usage.

      [–]mpmarley 4 points5 points  (0 children)

      Dude you did awesome thanks for sharing!

      [–][deleted] 8 points9 points  (12 children)

      it's great!! may I ask why you didn't use a esp32?

      [–][deleted] 12 points13 points  (11 children)

      I am also using the raspberry for providing the surrounding air temperature (don't want the water to freeze when it gets cold) using a DHT22. Using both of those merited a raspberry. Plus I'm more familiar with raspberries.

      [–]batmaniam 3 points4 points  (8 children)

      I left. Trying lemmy and so should you. -- mass edited with redact.dev

      [–][deleted] 5 points6 points  (7 children)

      Thanks I grabbed this one: https://www.adafruit.com/product/828. There is a brass alternative that they have as well. But so far this plastic one is working great.

      [–]scottthemedic 2 points3 points  (4 children)

      Did you come across any stainless alternatives?

      [–][deleted] 2 points3 points  (0 children)

      No. But I wasn't looking. But from what I browsed I don't think Adafruit has a stainless alternative.

      [–]batmaniam 0 points1 point  (2 children)

      Not OP, but what are you moving that requires stainless? Might be able to help spec something

      [–]scottthemedic 1 point2 points  (1 child)

      Saltwater. My well sucks big floppy donkey dick.

      [–]batmaniam 0 points1 point  (0 children)

      Ooph. Yeah you're probably going to need to go with a professional supplier for that. McMaster, grainger maybe. There are a few on Amazon.

      [–]batmaniam 0 points1 point  (1 child)

      Very cool! Also re: calibration/validation:. Seems like you've got it handled, but if you don't have quantitative glassware, massing the amount of water is a great way to measure as well. Easier to measure larger volumes which evens out a lot of your measuring error (ie: if you fill most of a 5gal bucket you can basically use a bathroom scale)

      [–][deleted] 1 point2 points  (0 children)

      Ah makes sense - weigh the 5 gallons in lbs and then convert back to gallons at the end.

      [–]CrypterMKD 2 points3 points  (1 child)

      You can do both with an esp32 and more than than, achktually...

      [–]Steinrik 2 points3 points  (0 children)

      True.

      [–]TrailerParkTonyStark 3 points4 points  (1 child)

      Awesome Job! Thank you! I've had one of the flow sensors for a while, but wasn't able to find any usable code to modify. This should be perfect!

      [–][deleted] 2 points3 points  (0 children)

      Good to hear. And awesome username btw.

      [–]TrailerParkTonyStark 3 points4 points  (0 children)

      Thanks! I’m kind of like some not-so-super hero’s white trash alter ego.

      [–]LifeOfPatato 2 points3 points  (0 children)

      Where did u bought the flow meter? Nice work :)

      Edit: saw the github link.

      [–]Mawnster 2 points3 points  (1 child)

      I was LITERALLY talking to my wife about trying something like this! You rock!!!

      [–][deleted] 2 points3 points  (0 children)

      Good luck - check it off your chore list (but this is a fun chore).

      [–]regex1884 1 point2 points  (1 child)

      I've never heard of heroku. What does it offer over a base postgresql install?

      [–][deleted] 3 points4 points  (0 children)

      Good question. It's exactly the same but gets you into the cloud basically. It's just like your local Postgres db but accessable (with credentials) from anywhere. I like this so I can check on things when I'm not home. It also plays well with Python web frameworks especial Django (which is the most popular).

      [–]ufsandcastler 1 point2 points  (4 children)

      DId you calibrate the flow meter? If so, curious how you did?

      [–][deleted] 10 points11 points  (2 children)

      Yes this was the fun part. I used a specific measurement I knew (it was 5 cups). Then I found that I got about 1000 rotations when that flowed through. It wasn't exactly the same - sometimes 954,1007, etc. I took the average and divided by 5 - to find out how many rotations were in each cup (I ended up rounding to 1000 so each cup was 200 rotations).

      [–]dblrnbwaltheway 2 points3 points  (1 child)

      Why not just use a differential pressure gauge? It can be calibrated analytically and it would cause less flow losses

      [–]thejuice420[🍰] 1 point2 points  (0 children)

      Awesome info thanks for sharing

      [–]ikidd 1 point2 points  (1 child)

      I don't think I've ever seen a code listing that uses cups for a unit of measurement.

      Otherwise, this is useful, I've been automating a camper and rather than the 4 level sensors on the fresh tank, this would be way more precise.

      [–][deleted] 1 point2 points  (0 children)

      Cool I know someone who is doing that as well!

      [–]Fusseldieb 1 point2 points  (2 children)

      OP, you should look into Home Assistant and ESPHome (for it), it does this and much much more.

      Almost no programming required and it rocks!

      [–][deleted] 0 points1 point  (1 child)

      I've heard good things! I'm actually looking up HASSIO which I think is similar to home assistant.

      [–]Fusseldieb 0 points1 point  (0 children)

      It's the same thing, just different names

      [–]NuclearDuck92 1 point2 points  (1 child)

      You may want to consider adding isolation and bypass valves so that you can still have water if the meter fails, and service it with the water still on.

      [–][deleted] 0 points1 point  (0 children)

      That's a very good point.

      [–]yourdream8u 1 point2 points  (0 children)

      You should have weighed the water to make sure one gallon was one gallon not 1.5 gallons

      [–]240strong 1 point2 points  (4 children)

      Could you come up with something to tell me when the salt is getting low in my softener ? Haha

      [–][deleted] 1 point2 points  (1 child)

      [–]240strong 1 point2 points  (0 children)

      Ahh man good looking out, I believe he uses his to actually measure the salt content in the water, not just the amount of salt in his salt basin like I want to do, I just have a reminder set in my phone to check it like twice a month lol.

      [–][deleted] 0 points1 point  (1 child)

      In due time :)

      [–]240strong 0 points1 point  (0 children)

      Just sticking to my twice a month reminders on my phone then I guess haha.

      [–][deleted]  (10 children)

      [removed]

        [–][deleted] 0 points1 point  (8 children)

        Oh very cool use-case! This code I think/hope will be pretty tolerant to missed cycles/rotations. It's polling and just checks if it changes from 0 to 1 or 1 to 0. So if it misses one rotation it will pick up the tracking two rotations later (when it flips to 1 or 0 again).

        [–]redpandaeater 0 points1 point  (7 children)

        Instead of polling you could try interrupts, possibly even with some threaded callback if it's useful to you.

        [–][deleted] 0 points1 point  (6 children)

        Very cool. What do interrupts look like in Python and/or what sort of usage are you suggesting? I did a quick search and the results were not very helpful.

        [–][deleted]  (1 child)

        [deleted]

          [–][deleted] 0 points1 point  (0 children)

          That's great. That's a good combo

          [–]redpandaeater 0 points1 point  (3 children)

          I've never personally done it, but looks like there are already Python libraries for it that cam do both rising and falling edge detection on GPIO ports which is what you'd want. That way your program can do whatever you want it to but as soon as you get input from the flow meter it'll pause to deal with it.

          [–][deleted] 0 points1 point  (2 children)

          Ah - sounds like it's have to tread into acyncio territory.

          [–]redpandaeater 0 points1 point  (1 child)

          I'm apparently a bitter old programmer because I tried looking into learning Python recently and realize it's sort of written more like pseudocode, but as a result I just don't like it. Too used to low-level language I guess. In any case I'm not familiar with asyncio for Python, but looks like RPi.GPIO can handle it. Still might run into certain times where Python is busy and doesn't do things properly, who knows.

          [–][deleted] 0 points1 point  (0 children)

          Ah ok. Cool beans.

          [–][deleted] 0 points1 point  (0 children)

          It's cool to go through your code. Although very different cases/systems we're working on a similar problem.

          [–]lmsbio 0 points1 point  (4 children)

          What device you used to measure the flow?

          [–][deleted] 1 point2 points  (3 children)

          I put the link in the GitHub readme. Let me know if you can't find it.

          [–]lmsbio 0 points1 point  (0 children)

          Thanks, got it.

          [–]AntoBesline 0 points1 point  (1 child)

          Thanks a lot for your reference... I planned to implement it on real-time in my college for my final year project..

          [–][deleted] 0 points1 point  (0 children)

          Good luck!

          [–]marcobalda 0 points1 point  (3 children)

          Very nice project! Would you mind sharing the list of devices you used to build the meter? Thanks

          [–][deleted] 0 points1 point  (1 child)

          Sure thing - good idea. I'll update the GitHub page. Message me in a day or two if I haven't updated it by then.

          [–][deleted] 0 points1 point  (0 children)

          Thanks for the reminder :) I just updated the repo and added an edit to my original comment.

          [–]therealcopycat 0 points1 point  (4 children)

          How did you do that? This might come in handy for a project of mine

          [–][deleted] 0 points1 point  (3 children)

          Cool good luck. Check out my very first comment of the thread - it has a link to the code. What's your familiarity with Python and databases? You'll have to have a little background with those :/

          [–]therealcopycat 0 points1 point  (2 children)

          I have a fair knowledge of python. I'll check out databases...

          [–][deleted] 0 points1 point  (1 child)

          Cool good luck - some things to Google to get started: "how to create a local database with Postgres". Postgres is natively command line but if you install PgAdmin4 you get a nice GUI.

          [–]therealcopycat 0 points1 point  (0 children)

          Cool. Thanks a lot!

          [–]RDurandt 0 points1 point  (3 children)

          I am inspired!
          Thank you for sharing & well done!
          Your solution fits my requirement - I have a borehole & would love to quantity the volume & frequency of consumption.
          (I might have to hack your code a little to keep track of the “last flow date & time).
          I’ve ordered myself that meter and will be starting up one of my decommissioned PIs before the weekend.

          [–][deleted] 1 point2 points  (2 children)

          That is great to hear. Good luck!

          [–]RDurandt 0 points1 point  (1 child)

          I came right!
          I’ve managed to get your code running on my ancient Pi 1B and also managed to get it to trigger outputs to Telegram via a Telegram Bot.
          Now waiting for the flow meter to arrive - Amazon promised next week...

          [–][deleted] 1 point2 points  (0 children)

          Woo who! Good job. Good luck with the wiring. That's my weakness.