bwertman
Posts: 78
Joined: Mon Nov 27, 2017 9:32 pm

Connecting/reading a flow meter from RPi

Fri Jun 22, 2018 11:48 pm

I'm trying to get a reading out of this Digiten flow meter on my Rpi 3.

https://www.amazon.com/gp/product/B01D4 ... UTF8&psc=1

Here are the specs
  • Flow range:0.3-10L/min
  • Frequency: F=38 * Q (L / Min) error:¡À 2%
  • Working voltage range: 3.5-12 VDC
  • Pressure range: 0-0.8MPa
I have the red wire going to 5V and the black to GND. Yellow wire is going to GPIO13 with a 10K resistor in between.

I verified 5V at the sensor connection but can't get any reading out of the GPIO. Is this not a good GPIO to use for the flow meter because it is designated PWM? Or do I not need the 10K resistor? Something else?

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 7:24 am

Well, the first thing is that I can't see a link to a proper data sheet. The details in that advert are only a summary.

Without a data sheet, we don't know whether the output is a voltage or a current, and therefore what interface circuit to use.

If we assume it is a voltage output, then we can reasonably assume the voltage excursions are about the same as the supply voltage, and you must not apply more than 3.3V to a GPIO input. Nonetheless, if it was a voltage output I think you would have seen some kind of response on the RPi (assuming you have programmed it correctly, and unless you have killed the input), even though 10k is rather high.

Therefore there is a good chance the output looks like a switch to ground, and you need to treat it like a switch.

Beginners Guide to Wiring Things to the GPIO
Last edited by Z80 Refugee on Sat Jun 23, 2018 7:34 am, edited 1 time in total.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

pcmanbob
Posts: 4529
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 7:26 am

Hi.

The limited information provided by the supplier states the output is a square wave pulse, but it does give any other information.
if you are powering the flow meter with 5v then there is a good possibility that the output will be a 5v pulse, the pi gpio is not 5v tolerant and applying 5v to it will damage your pi.

to connect the output to the pi you need to use a potential divider circuit consisting of a 1K and 2K resistors connected like this

Image
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

User avatar
Gavinmc42
Posts: 2173
Joined: Wed Aug 28, 2013 3:31 am

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 7:34 am

You might find it works at 3.3V too.
The hall effect might be open collector which means you need a pull up to 3V3.
The problem I have with Amazon/eBay etc is there is never a decent data sheet.
Hooking a resistor/led to the output is good way to test., you can even leave them on as your pullup.

The rotating vanes will have a magnet on them, this makes the output of the hall effect go low.
What you need to do is set up a GPIO pin as interrupt on going low.
You then read the internal clock,the next interrupt you subtract first clock counter value from current value.
The faster the flow rate, the shorter the time difference.

Interrupt latency might be an issue, so averaging a few values will smooth it out.
For better accuracy a small micro controller can figure out the flow rate and be read via i2c at the PI's convenience.
I use 8 pin micros for this sort of stuff.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
lmarmisa
Posts: 1220
Joined: Thu Feb 14, 2013 2:22 am
Location: Jávea, Spain

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 7:35 am


User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 7:37 am

Gavinmc42 wrote:
Sat Jun 23, 2018 7:34 am
You might find it works at 3.3V too.
It might, but that is not guaranteed by specification.
Gavinmc42 wrote:
Sat Jun 23, 2018 7:34 am
The hall effect might be open collector which means you need a pull up to 3V3.
...which is exactly what I meant by treating it like a switch. If this is the case, there is no need to run the sensor at a below-spec voltage.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

wh7qq
Posts: 1131
Joined: Thu Oct 09, 2014 2:50 am

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 7:50 am

Wrong button

stevend
Posts: 205
Joined: Fri Oct 11, 2013 12:28 pm

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 8:38 am

There are lots of these flow sensors around; I suspect they all use the same basic mechanism. I'm using one that looks a bit more like this, for which I've tried to attach the data sheet (a bit more help than your initial link, but not much). My sensors came from someone like Hobbytronics, or look at Adafruit/Sparkfun

From my data the device won't operate off a 3.3V supply. Don't think I checked whether the output is push-pull or open collector; my interface circuit has a 10K pullup to 5V on the sensor output, followed by a level shifter.
Attachments
YF-S201.zip
Flow sensor data
(43.4 KiB) Downloaded 12 times

User avatar
bensimmo
Posts: 3457
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 8:45 am

Amazon comments give you a product code
FL-S402B
Digiten have a website too.

http://www.digit-en.com/goods/show-432.html

Gives a fraction more info.

But at least you know who to ask technical details to.

You could use piscope to see if the gpio is seeing the pulses.
http://abyz.me.uk/rpi/pigpio/piscope.html

donmerch
Posts: 17
Joined: Mon Feb 15, 2016 8:47 pm
Contact: Website

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 4:49 pm

Gavinmc42 wrote:
Sat Jun 23, 2018 7:34 am
For better accuracy a small micro controller can figure out the flow rate and be read via i2c at the PI's convenience.
I use 8 pin micros for this sort of stuff.
What 8 pin micros do you use?

stevend
Posts: 205
Joined: Fri Oct 11, 2013 12:28 pm

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 4:59 pm

Just done a quick test on the flow sensor I've got here (which is most probably the same as the OP's), and the output is push-pull - i.e. it switches between 0V and +5V, rather than being open collector.

So looks like the voltage divider described by pcmanbob is necessary.

bwertman
Posts: 78
Joined: Mon Nov 27, 2017 9:32 pm

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 5:43 pm

@pcmanbob I tried setting it up with a potential divider but I'm still not getting a reading. Not sure if I misunderstood the diagram. I didn't have a 2K resistor, so that is 2.2K running from 17C to ground. Then that is 1K resistor off the flow meter signal wire. I have it setup on GPIO13.

GND and VCC are connected at the top left of the image to the 5V rail.
IMG_2850.JPG
IMG_2850.JPG (219.06 KiB) Viewed 627 times

stevend
Posts: 205
Joined: Fri Oct 11, 2013 12:28 pm

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 6:22 pm

Its always possible that the output of the sensor won't drive a load of 3K. You could try larger resistors - 10K and 22K, say. (Not critical as long as you maintain the 2:1 ratio).
Have you got a voltmeter? If so, measure the voltage between ground and the Pi's input. It should change between 0V and about 3V if you rotate the sensor slowly.

bwertman
Posts: 78
Joined: Mon Nov 27, 2017 9:32 pm

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 6:57 pm

@stevend I tried measuring with the voltmeter between ground and GPIO13, where I had the sensor signal connected, and I got nothing.

stevend
Posts: 205
Joined: Fri Oct 11, 2013 12:28 pm

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 8:23 pm

bwertman wrote:
Sat Jun 23, 2018 6:57 pm
@stevend I tried measuring with the voltmeter between ground and GPIO13, where I had the sensor signal connected, and I got nothing.
Did you rotate the sensor slowly while measuring? (On my one, I can push the rotor round with a screwdriver or similar)
If not, maybe the GPIO line is currently set to be an output.
Try measuring on the actual output of the sensor. That should change between 0V and 5V as the sensor rotates.

Are you sure that you've got the right connections to the sensor; the power supplies in particular? (The wire colours in the photo differ from both the digiten web site and my sensor)

User avatar
bensimmo
Posts: 3457
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 8:29 pm

Are you getting 5V at the T cobbler?

i.e. a check that your cable is the right way around.


And do look at piscope :-)
That actually sees and shows you the pulses.

bwertman
Posts: 78
Joined: Mon Nov 27, 2017 9:32 pm

Re: Connecting/reading a flow meter from RPi

Sat Jun 23, 2018 10:20 pm

@stevend I don't see a way to rotate the sensor by hand. I have it connected to the output of my reverse osmosis water filter.

I confirmed 5v at the sensor. The voltage between the sensor ground and it's signal wire very slowly moves back and forth between ~10mv and ~50mv.

if this were 0v and 5V as you suggested I would say maybe the RO filter doesn't put out enough flow for the minimum 0.3L/min of the 0.3 - 10L/min range that the sensor is rated at. But that wouldn't explain the much lower output voltage would it?

bwertman
Posts: 78
Joined: Mon Nov 27, 2017 9:32 pm

Re: Connecting/reading a flow meter from RPi

Sun Jun 24, 2018 12:24 am

I just measured my RO water output with a stopwatch. It was only 200ml/min, just shy of the minimum 300ml/min the sensor is rated at. :-(

There goes 8 hours of my life I'll never get back.

User avatar
Gavinmc42
Posts: 2173
Joined: Wed Aug 28, 2013 3:31 am

Re: Connecting/reading a flow meter from RPi

Sun Jun 24, 2018 1:37 am

I used to test flow sensors by blowing air through them.
And that minimum flow is due to friction/leakage.

Get it working before hooking it up to the Pi.
Use 5V and a led/resistor to 5 V, puff some air through it and see if the led goes on/off.
It has a hall effect sensor so learn how those work.

8 hours wasted?
Well if you buy stuff from Amazon without a clue how they work, you will be in for some learning.
That's why I buy from Adafruit, Sparkfun etc you get real datasheets and most times even code and tutorials.

8 hours and what price do you put on those hours?
Sure it may have been cheaper to buy, but it has not been cheaper to use.
Then there is the time we have put in helping you ;)
For better accuracy a small micro controller can figure out the flow rate and be read via i2c at the PI's convenience.
I use 8 pin micros for this sort of stuff.

What 8 pin micros do you use?
PSoC 1 - CY8C24123A, it uses i2c for programming but then I can use the same pins for comms.
This leaves 4 pins for stuff, digital, PWM, ADC, DAC etc
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

stevend
Posts: 205
Joined: Fri Oct 11, 2013 12:28 pm

Re: Connecting/reading a flow meter from RPi

Sun Jun 24, 2018 11:13 am

bwertman wrote:
Sun Jun 24, 2018 12:24 am
I just measured my RO water output with a stopwatch. It was only 200ml/min, just shy of the minimum 300ml/min the sensor is rated at. :-(

There goes 8 hours of my life I'll never get back.
..but you've hopefully learned a few things that will be useful on another project!

bwertman
Posts: 78
Joined: Mon Nov 27, 2017 9:32 pm

Re: Connecting/reading a flow meter from RPi

Sun Jun 24, 2018 11:22 am

I've learned some things for sure.

But it's not a whole lot of consolation when your scrambling to finish an aquarium monitoring/ maintenance system and have now just 48hrs before you have to leave it for 10 weeks and trust it to run on its own without flooding your apartment. :roll:

pcmanbob
Posts: 4529
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting/reading a flow meter from RPi

Sun Jun 24, 2018 12:12 pm

Time to complete a project is always something people underestimate, I always work on 3 times what I thank it will take and then expect to be fine tuning for a bit after that once the project is up and running.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

bwertman
Posts: 78
Joined: Mon Nov 27, 2017 9:32 pm

Re: Connecting/reading a flow meter from RPi

Sun Jun 24, 2018 12:32 pm

I know, the ten week trip was only planned about four months ago though.

Five months ago everything my Pi is tasked with automating was a completely manual process;
  • water changes to maintain mineral levels and export excess nutrients
  • emptying the protein skimmer of trapped fish waste
  • topping off the tank with RODI water to make up for evaporation and maintain correct salinity
  • feeding the fish
Most of it I'm confident in but the auto top off, the most frequently running process and the one with the most potential to cause a leak, still has issues.

I just didn't have the luxury of being able to give myself 9 months to do what seemed remotely possible of happening in 3.

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Connecting/reading a flow meter from RPi

Sun Jun 24, 2018 12:39 pm

pcmanbob wrote:
Sun Jun 24, 2018 12:12 pm
Time to complete a project is always something people underestimate, I always work on 3 times what I thank it will take and then expect to be fine tuning for a bit after that once the project is up and running.
Very true. I usually get around to thinking about automating the lights and curtains only when about to leave...
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

pcmanbob
Posts: 4529
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Connecting/reading a flow meter from RPi

Sun Jun 24, 2018 1:17 pm

bwertman wrote:
Sun Jun 24, 2018 12:32 pm
I know, the ten week trip was only planned about four months ago though.

Five months ago everything my Pi is tasked with automating was a completely manual process;
  • water changes to maintain mineral levels and export excess nutrients
  • emptying the protein skimmer of trapped fish waste
  • topping off the tank with RODI water to make up for evaporation and maintain correct salinity
  • feeding the fish
Most of it I'm confident in but the auto top off, the most frequently running process and the one with the most potential to cause a leak, still has issues.

I just didn't have the luxury of being able to give myself 9 months to do what seemed remotely possible of happening in 3.

even with a fully working system, I would still want human intervention every couple of days, what happens if you have a mains fail and the SD card gets corrupted ?
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

Return to “General discussion”