I know I've made a post regarding this topic before, but it died. I'm now having trouble with it again. I have a flow sensor (http://www.swissflow.com/en/SF800/Flow_Meter_Specifications) that outputs a frequency based on the flow rate. I'm having trouble getting the Arduino to give me meaningful results. So far, I've tried attaching an interrupt:
but all that returned was the value 4294967295 over and over again. I don't need to know the exact flow rate or anything. I just need to know if liquid is flowing at all.
Output frequency: 100 to 2000 Hz (depending on the flow velocity)
freq = (flowCount / 1000);
...this is an integer division; fractions are truncated. freq will only ever have three values: zero, one, or two. For about half the range, freq is zero.
Print flowCount instead of freq. Is the value between 100 and 2000?
In loop, you will need to protect flowCount by disabling interrupts.
Ok, I've tried both approaches (by jonathan and coding badly), but neither have produced results. @jonathan: I tweaked my code to mimic the information on the site you provided:
and I didn't get any results whatsoever. Everything was zeros, except for the analogRead I added: that just returned 1s constantly.
@Coding Badly:
In loop, you will need to protect flowCount by disabling interrupts.
If I do this, flowCount won't increment because the function to increment flowCount is only called inside of an interrupt. And I did try just printing flowCount, but I was still getting zeros.
The discussion so far has been about code, and we've just been assuming that the hardware is OK. How do you have the sensor connected? Can you test it in isolation from the Arduino, such as by connecting an oscilloscope to the output? A schematic of your setup would be handy: even a photo of a rough hand-drawn schematic is better than nothing.
Yes, if you mean that I need to detach the interrupt, read the value, then re-attach the interrupt when I'm done reading the variable.
Another question: would it be practical to have three of these sensors, each using different counters, along with a large program that's doing serial reading and printing for wireless communication?
Hey, interesting project. I would also suggest testing the hookup first, say, with a simple code. Say hook the meter to a digital input. If it shows HIGH, display on LCD HIGH, same for low. Then blow through the meter to see if your LCD changes at all. This requires no oscilloscope, although a digital scope is always a bless. I presume you have a little rotating part inside the meter to give the pulse like a SPST switch in a rotational encorder.
By the way, how much did you pay for your meter? I'm interested in getting one now that I've seem what it is.
Well, that would work for the type of sensor you're talking about, but this flow sensor doesn't have a small rotating piece inside. The one I have is an IR sensor, so blowing through it doesn't do anything.