# GPIO Flowmeter Project



## Phishfry (Sep 5, 2022)

I have a friend who has a Distilled Water Store. They have self-refill stations for 5 Gallon plastic bottles.
He is expanding and I thought a nice project would be a way to dispense 5 gallons with a flow decrease for the last 1/2 Gallon.
The bottles need decreased flow at end due to neck of the bottle.

I was thinking of using Pi3/4's GPIO and a digital flow meter with perhaps a throttling valve.








						Reading out a Flow Meter/Water Flow Sensor on the Raspberry Pi
					

How is a water flow sensor programmed on the Raspberry Pi? To use the flow sensor/flow meter, a small Python code script is sufficient ...




					tutorials-raspberrypi.com
				



Perhaps a green button to start the fill cycle. Red button for halt.

Anybody mess with similar FreeBSD GPIO flowmeter projects?

It is beyond my capabilities but I might have to start with the flowmeter. See accurate it actually is.
Real digital flowmeters are much more in price but include an LCD to show reading in addition to digital output.


----------



## Phishfry (Sep 5, 2022)

My reasoning for Pi instead of microcontroller like ESP32 is I believe I can run all 4 water stations off one Pi.
Networking onboard for remote monitoring too.

Is my computer hardware choice sane or way overkill?

The bottles hold more than 5 gallons if filled to the top. So I have a good bit of leeway for filling.
I do worry about those "Weights and Measurements" bureaucrats. Add a meter and it probably has to be approved.

The current fill stations use a button to a solenoid on 3 filling stations. Hold to fill.
Very messy water ops. Spillage galore. I believe automation will save him money and waste water down the drain.

Once again I am afraid my lack of programming experience will hamper this project.


----------



## ralphbsz (Sep 5, 2022)

I have one RPi in production, helping to monitor my water pump / well system.



Phishfry said:


> My reasoning for Pi instead of microcontroller like ESP32 is ...


There is a much simpler reason: Development and testing environment.

On a RPi, you just log in, and you can have everything there. Need a compiled program? Compile it right there. Need to put your program under source control (everything should be)? Install git or hg. Want to test the gpio? Use the gpio command. Want to develop in Python? A python interpreter is available, and you can download modules for gpio, i2c, 1-wire, serial, ModBus, and so on. Want to develop in C? Compiler is right there, and it is the same type of compiler you use in normal development. Any other language? Download the compiler. Need to serve a web page? Enable Apache, write a cgi script (in the language of your choice), and you're there. Need to store something on disk for later? It has a file system. Need to communicate over the network? It has a full stack, with completely normal tools (whether it is your favorite RPC library or just ssh). It's a completely boring normal Unix machine.



> Is my computer hardware choice sane or way overkill?


You are not cost constrained; whether you spend $30 on a RPi or $10 on a small embedded board makes no difference, compared to your other development costs.



> Once again I am afraid my lack of programming experience will hamper this project.


The problem is not the hardware, nor the basic development environment tools. The problem is going to be your patience and experience for writing totally reliable and survivable embedded software. How are you going to handle random crashes? What happens if you have a bug that crashes the program, right when the valve is open? How are you going to make your measurements fail-safe? How do you write a daemon that comes up after power outages cleanly?


----------



## Phishfry (Sep 5, 2022)

I am not sure what to use for the throttling valve and I am a valve doctor.
(It is literally one of my specialties. But that is on large valves for boats with actuators.)
This project will use either 1" to 1.5" NPT pipe for each fill station.

My initial thoughts were:
-Make it run to 4.5 gallons at valve full open then 1/2 gallon with valve at half/quarter open...

I am not sure what to use for the throttle valve. I need a cheap digital valve. Garden Sprinkler stuff is too small.
I need to ramp down velocity of water flow as measured by flowmeter reading somehow.

Any ideas?

I need to research Ice Machines. See what they use to meter water.



ralphbsz said:


> How are you going to make your measurements fail-safe?


That comes after the alpha version. Lasers or ultrasonic sensors on the bottle to give additional feedbacks???


----------



## ralphbsz (Sep 5, 2022)

You can get garden sprinkler valves that can handle very high flows, with very little back pressure. Look at Irritrol 700 valves, which are available at least in sizes up to 2". But: One of the problems of sprinkler valves is that they need at least 10 psi on the input to close. When the input pressure drops to zero, they actually open! In your case, that might be a very annoying failure mode.

The other option are full-blown solenoid valves (which use much more current), and really close when turned off, independent of input pressure. I like the models sold by AutomationDirect; they are reasonably priced, and work well. I have one 3/4" model in use right now, another on order.

For your problem of adjusting the flow, the easiest answer is probably to have two valves: One big one, which sends the full flow. In parallel to it a small valve, on a line that has either a pressure or flow reducer (could be as easy as a needle valve). I don't know of any common valves that can be throttled easily.

You say you're filling a 5 gallon bottle with a 1.5" line? What pressures are you running at? You do understand that 1.5" is a common size for fire hoses, and a 1.5" fire hose at normal pressures (60-100 psi) will deliver 50-60 gpm, and that your bottle would fill in 6 seconds? Maybe you have really low pressures.


----------



## Crivens (Sep 5, 2022)

Flow control may also be done by using PWM pins.


----------



## bjs (Sep 5, 2022)

You could possibly use weight to meter the filling...


----------



## jbo (Sep 5, 2022)

bjs said:


> You could possibly use weight to meter the filling...


This usually doesn't work well without a lot of extra stuff added to the system for the average, untrained, non-techy John Doe user/customer.
You'd have to either prevent the user from "touching" the bottle or employ fancy algorithms to detect variations in the weight vs. the expected linear increase.
Commercial systems often bypass this issue by first filling an intermediate container which is isolated from the user and can therefore employ the weight measurement technique and then dumping that container into the customer provided container.


----------



## Phishfry (Sep 5, 2022)

Thanks everyone for the suggestions.


ralphbsz said:


> 1.5" fire hose at normal pressures (60-100 psi) will deliver 50-60 gpm


I need to check pressure if I am serious about this job.
Currently the distiller plant empties into a stainless large tank. Head for the system is created by the tank.
I.5" would be overkill and 1"NPT would be more than adequate.
Alot of these ABS plastic valves are ball valves.
Still it is not a throttling valve. Open or closed with actuator and long 2.5 second cycle time. Far from ideal.



ralphbsz said:


> In parallel to it a small valve,


I like this idea. A secondary water loop with reduced piping size for the last bits of water.
Then I could just use solonoids. It would require more wiring.




jbodenmann said:


> bypass this issue by first filling an intermediate container which is isolated from the user


This was in the back of my head too.
Much like a toilet tank. Float valve for water level and solenoid for release.


I can't find any electronic needle valves.
I wonder how gasoline pumps do their ramp down.
One difference is the pump filler goes into the fuel tank spout. So they use a venturi effect for feedback.
Water filling station does not protrude into bottle.


----------



## Crivens (Sep 5, 2022)

You can use an off-the-shelf RC servo unit and drive it with a PWM signal. You may then use any ball valve you want.


----------



## Phishfry (Sep 5, 2022)

Been there done that. Back in my autonomous vessel design testing phase. RC servos controlled by BBB PWM for RC Boat tillers. Currently in self storage and SIM card for toys revoked..
It was a great learning experience.








						PWM on Beaglebone
					

I am looking to use PWM on the GPIO pins. FreeBSD 10.x seems to offer sysctl settings for usage. What is the mechanism for usage on FreeBSD 11.x ? I am looking to drive an R/C servo. Here are the BBB 10.4 settings:  root@beaglebone:~ # sysctl dev.am335x_pwm dev.am335x_pwm.2.dutyB: 0...




					forums.freebsd.org


----------



## Phishfry (Sep 5, 2022)

I did notice on my trolling of the Flowmeter topic that some in Linux land are using an interrupt driven GPIO pin.

Do not fry your Pi.




_View: https://www.youtube.com/watch?v=wpenAP8gN3c_


----------



## WMByj2SUUa (Sep 6, 2022)

How About RS232 or USB -> RS232 adapter?




_View: https://www.youtube.com/watch?v=2T9ca53KMrM_


----------



## Jose (Sep 6, 2022)

Maybe a bit off topic, but this guy uses time to figure out how much water was pumped out of his leaky sailboat. Probably too inaccurate for your purposes:



			https://l-36.com/FaultTolerant.php#data


----------



## leebrown66 (Sep 7, 2022)

FYI, our Water Treatment Plant has a half dozen flow detectors.  They need regular cleaning otherwise they get inaccurate and stop working.  It's an attachment to a regular meter, there's a metal tab on the fastest spinning dial and a hall-effect pickup to generate a spike per rotation.


----------



## jbo (Sep 7, 2022)

leebrown66 said:


> They need regular cleaning otherwise they get inaccurate and stop working.


There are maintenance free flow meters such as Coriolis and Vertex meters.
I'm not a fluid dynamics engineer but my guess would be that they are unsuitable for water treatment plants as they only work properly if the characteristics of the fluid moving through them is well defined/known. But in Phishfry 's case this should work just fine as we're talking distilled water.


----------



## leebrown66 (Sep 7, 2022)

To clarify the meters are maintenance free, and are suitable otherwise would not have passed State inspection, water is highly regulated).  We record the physical dials for the records.
It's the add-on sensor for automation that fails.


----------

