Flow Rate Sensor Read

Hello I’m newbie, and i’m interesting using this XOD. I try to adopt from flow rate sketch that using interrupt (sketch
I’m using rise-interrupt in the XOD, but maybe I have something missing
Please, tell me what i’m doing wrong or need additional patch.


For starters, the sketch you link to enables interrupts for 1 second and counts pulses during that time. Your code always has interrupts enables, and delays one second before counting pulse. If pulses are <1 second apart, delay keeps getting reset and nothing gets counted. You want something more like this:
You’ll need to figure out how to trigger delay to start the count.

Another issue you are going to run into is that there can be multiple interrupts per pulse, so you can’t just count pulses. You might be able to get away with something like this:
This should work as long as rise-interrupt-NUM is set before the pulse fires (which should be the case).

Note: If you want to measure flow-rate more than once, you will need to reset count each time. One option:

I add the defer between signal to start count and delay just to make sure count is cleared before we start counting; otherwise we could potentially miss counting the 1st batch of interrupts. This may (or may not) be needed…

Assuming you want a flow-rate number that you can use somewhere else in your program and you want it to be constantly updated, one option is to measure the flow-rate every 1.5 seconds (since you are using 1 second to count interrupts, you probably don’t want to check much more frequently, you could check less frequently if you are not expecting dramatic changes in flow-rate). You won’t want the other parts of your program using bad low readings while a new flow-rate is being calculated, so you may need to store the last valid measurement using a buffer node that gets updated when the calculation is done.

You could put your node to multiply the scaling factor before the buffer, but that would cause the multiplication to happen every time count is updated; it really only needs to happen after the counting is done, so should probably go after the buffer.

If you need flow-rate updated more often, you can shorten your sample time (the delay-T value), but you will need to change your scaling factor to account for the shorter counting time. A shorter count time will allow you to update more often, but might generate larger rounding errors. You will likely “just miss” the last pulse counting the last batch of interrupts. The shorter your counting time (and the more interrupts per batch; i.e. the higher the flow rate), the more this will affect your calculations.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.