MicWit
Posts: 91
Joined: Fri Nov 01, 2013 5:20 am

Using GPIO to multiple switches (as well as sensors)

Fri Nov 01, 2013 5:43 am

Hi,

I have set up a raspberry pi with a bunch of temperature probes, as found at http://raspbrew.tumblr.com/post/3985079 ... ng-ds18b20. As pictures there, I am NOT using a breadboard (I would rather solder), I am just using the sensors, a 4.7K resistor and the cables. How they are all connected is not important, what I need to do now is make a switch that tells me if water is flowing or not.

I have 20mm PVC that I need to know when water starts and stops flowing. Its for an aquaponics system, so the beds flood and drain, and I will receive an alarm on my phone if this takes too long, as it means a pipe may have burst (at least something is wrong). It also means I can keep track of the cycle times and modify water flow etc to get them better. The temp probes will be in each tank so I can keep track of that and make graphs etc with the data.

So with the flow switch, I had suggested that I could use 2 aluminium rods (cant be any copper as the fish don't like anything that will oxidise or put any chemical in the water). Basically the 2 rods would be spaced apart, and when the water flows between them, a circuit would be made. I want to test this to see if fast flowing water or anything will cause this to fail, but I need to know how to wire it first.

I know I will probably need a 1k and a 10k resistor or something? I need multiple sensors as well, working on the same pi as the temp sensors. I guess I will need to split the 3v3 that is being used with the temp sensors, but not the 4.7K resistor? What about ground and Im guessing I will use a different input pin for each of these switches? I can't seem to find any tutorials that cover more than 1 button at once.

Also, Im using python, so what code would I use? I need to know whenever the connection is made or broken, Im guessing the best bet is an infinite loop that checks every switch, waits 5secs and then loops?

Any help would be AWESOME! Thanks

WebPi
Posts: 262
Joined: Wed Apr 10, 2013 6:47 pm
Location: Birmingham, UK
Contact: Website

Re: Using GPIO to multiple switches (as well as sensors)

Fri Nov 01, 2013 10:03 am

It sounds as if your aluminium rods will essentially act like a push button switch (except the connection is made by water instead of bits of metal being pressed together), so this might be helpful: http://raspberrywebserver.com/gpio/dete ... -GPIO.html
raspberrywebserver.com - Raspberry Pi tutorials
LinuxWebServers.net - Linux Web Server tutorials and examples
pyplate.com - Python web publishing tool

MicWit
Posts: 91
Joined: Fri Nov 01, 2013 5:20 am

Re: Using GPIO to multiple switches (as well as sensors)

Fri Nov 01, 2013 12:54 pm

Thanks for that. Any idea what the 330 is? Im guessing thats a resister to be used with the LED's? I only need the button part anyhow, but I need multiple buttons. So I guess each button comes from the 3v (pin 1 or 17) and each cable goes to a resistor for each button, and then into separate GPIO pins, as well as to the button, which goes back to ground.

Im guessing the way it works, is that while the circuit is open, the GPIO pin used will have power looped through to it, but when the button closes, the power all leaks to ground? Im not sure why the resister is there, shouldn't the resister be right next to pin 23, with the button directly connected to the power with no resistor between it and the power?

Also, which pins are used for this? GPIO 23, 24 and 25 I presume are pins 16, 18 and 22? (Im not using a bread board). In the code I could just use 23, 24 and 25 as ins?

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Using GPIO to multiple switches (as well as sensors)

Fri Nov 01, 2013 4:57 pm

A little off-topic to this forum, but...

Be careful when you have current go through water. I fear, that aluminium *will* corrode when conducting current through water. High-grade stainless steel might be a better choice, but the only material which will undoubtedly be absolutely safe is platinum.

Anyway, keep the current as low as possible, a few microamperes if possible. You might use a FET comparator with very low input leakage current.

Overall, I'd prefer some other detection method. Maybe like a light barrier, with the emitting LED protruding into the pipe. If the LED is dry (EDIT: not bright... ), the top acts as a lens, and there's a bright spot across the pipe. If there's water, the lens is less effective due to the different refractive index of water. That should darken the spot measurably. There's lots of other methods. Measuring the conductivity of water seems the easiest way, but I wouldn't risk to pollute the water with metal ions of any kind.

MicWit
Posts: 91
Joined: Fri Nov 01, 2013 5:20 am

Re: Using GPIO to multiple switches (as well as sensors)

Fri Nov 01, 2013 10:26 pm

This is entirely true, and why I was thinking aluminum and not copper, but if it will throw chemicals in the water, cant use it. The led idea sounds interesting, do you have a link to a tutorial? Any other ideas? You would think it wouldn't be too hard to detect if water is flowing out a pipe!

PiGraham
Posts: 3602
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Using GPIO to multiple switches (as well as sensors)

Sat Nov 02, 2013 5:52 am

You could use a flow sensor.
http://www.ebay.co.uk/bhp/water-flow-sensor

You could use pressure sensors.

perhaps you could monitor whatever controls the flow.

MicWit
Posts: 91
Joined: Fri Nov 01, 2013 5:20 am

Re: Using GPIO to multiple switches (as well as sensors)

Sat Nov 02, 2013 8:07 am

The issues with these are that they would create back pressure.

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: Using GPIO to multiple switches (as well as sensors)

Sat Nov 02, 2013 8:19 am

There are flow sensors using doppler effect, which do not obstruct the flow. They can actially measure the speed of the water, but they're not really cheap I think.

MicWit
Posts: 91
Joined: Fri Nov 01, 2013 5:20 am

Re: Using GPIO to multiple switches (as well as sensors)

Sat Nov 02, 2013 9:27 am

That sounds good except the not part before the word cheap.

achrn
Posts: 374
Joined: Wed Feb 13, 2013 1:22 pm

Re: Using GPIO to multiple switches (as well as sensors)

Wed Nov 06, 2013 2:06 pm

I've had arduinos monitoring water flows in fish-tanks systems, though currently I don't have any computer control.
MicWit wrote:The issues with these are that they would create back pressure.
While this is true, with the right switch the back pressure is negligible. Your rods-in-flow solution generates back-pressure too.

I'd use http://uk.farnell.com/cynergy3/fs22/flo ... /dp/730890 or something like it (depending what flows you have). http://uk.farnell.com/cynergy3/uf08b100 ... dp/1877555 does a similar job but has a clear bore and probably less back-pressure (for equivalent flow). Annoyingly, the manufacturer doesn;t have pressure/flow data on their datasheets. The latter is somewhat over ten times the price of the former - it would possibly be cheaper to use the former and boost your pump power (again, depending what your flows are - I'm assuming we're not talking about Severn-barrage-scale systems).

Both of these are plastic - much better for your fish than aluminium. I would expect aluminium will cause more harm than copper, generally - aluminium is regularly used as a sacrificial anode in galvanic protection applications (actually, you'd generally use a combination of aluminium and zinc, though aluminium alone does work). While I personally wouldn't use either copper or aluminium in a fish system, if I really really had to pick one or the other, I'd use copper in preference. If you must put metal in the water, use a decently high grade of stainless steel.

Kn0man
Posts: 18
Joined: Fri Jul 10, 2015 9:36 pm

Re: Using GPIO to multiple switches (as well as sensors)

Sun Aug 16, 2015 11:30 pm

Just a thought,but couldn't you detect flow using a laser and a photosensor? When water was in the tube wouldn't it cause refraction and it would follow the flow of water and never reach the photosensor ? {condition false} when no water in tube, laser hits receptor and {condition true} ?
"The avalanche has already started; it is too late for the pebbles to vote."-Kosh Naranek

MicWit
Posts: 91
Joined: Fri Nov 01, 2013 5:20 am

Re: Using GPIO to multiple switches (as well as sensors)

Mon Aug 17, 2015 12:25 am

I can not have anything over the end of the pipe. It's not about boosting the pump size, as at this stage it is all gravity fed.

I don't think a laser and photosensor would work as they would have to be waterproof and that would cost a fortune!

At the moment I am looking at using arduinos for the job. U can get minis for less than $3 on ebay. These u can just hook up the output to alfoil on a pipe and back to a data input (with a resistor between) and measure the voltages to detect the resistance making an extremely cheap water sensor. Just need to find the time to experiment.

Kn0man
Posts: 18
Joined: Fri Jul 10, 2015 9:36 pm

Re: Using GPIO to multiple switches (as well as sensors)

Mon Aug 17, 2015 2:07 am

Ah, I see. I was thinking more along the lines of mounting an led/(laser) in the wall of your pvc (or clear tubing like pex) with the photosensor in the wall directly opposite, rather than having anything come in direct contact with the water. So I'm not even sure it was a viable solution and it sounds like you have a plan mapped out already! :) Good Luck!
"The avalanche has already started; it is too late for the pebbles to vote."-Kosh Naranek

ghp
Posts: 1409
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Using GPIO to multiple switches (as well as sensors)

Tue Aug 18, 2015 7:47 am

Hello,
recently I did some work to detect fill level of water in a glas using a capacitive sensor.
http://heppg.de/ikg/wordpress/?p=192
The capacitive stripes could be attached to the outside of the (plastic) rod, not being in contact with water. And with a clever electrode design, ambient influences could be reduced.
Uses a slave atmel328 for the frequency measurement. There is a firmware available on the page, which connects to raspberry and some python samples to talk to this device. As the 16 bit timer is used in my firmware, the software can't be ported directly to an arduino.
Regards,
Gerhard

danjperron
Posts: 3402
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Using GPIO to multiple switches (as well as sensors)

Tue Aug 18, 2015 11:15 am

Did you ever look at that post

viewtopic.php?p=449724#p449724


I made a document about it!
https://docs.google.com/document/d/1YN4 ... sp=sharing

Return to “Interfacing (DSI, CSI, I2C, etc.)”