Giter VIP home page Giter VIP logo

flowmeter's Introduction

FlowMeter Library Version Build Status analytics

FlowMeter is an Arduino library that provides calibrated flow and volume measurement with flow sensors.

You can use it to count flow and volume of liquids and gases (although the documentation focuses on applications using liquids) and can support multiple flow sensors at the same time.

It also works as a totalizer, accumulating total volume and average flow rate over the run time of your project.

A provision for calibration helps you to get the most out of your sensor. You can even estimate the recent and overall error margin.

The library is intended for use with flow sensors that provide a frequency output signal proportional to flow, although other types of sensors could be made to work.

A Simple Example

Getting started with FlowMeter is easy. Take a look at this simple example:

void setup() {
  // prepare serial communication
  Serial.begin(115200);

  // get a new FlowMeter instance for an uncalibrated flow sensor on pin 2
  Meter = new FlowMeter(digitalPinToInterrupt(2), UncalibratedSensor, MeterISR, RISING);
}

void loop() {
  // wait between output updates
  delay(period);

  // process the (possibly) counted ticks
  Meter->tick(period);

  // output some measurement result
  Serial.print("Currently ");
  Serial.print(Meter->getCurrentFlowrate());
  Serial.print(" l/min, ");
  Serial.print(Meter->getTotalVolume());
  Serial.println(" l total.");

  //
  // any other code can go here
  //
}

In the above example, a flow sensor is assumed to be connected to the INT0 pin. The corresponding object Meter is updated every period (in milliseconds, e.g. 1000ms).

So after every measurement period, the current flow rate and the total volume are printed out.

Please read on in the examples section of the library's documentation pages.

Installing the library

Just check out the FlowMeter Repository on GitHub (or download the ZIP archive) and copy it to your libraries/ folder (usually within your Arduino sketchbook).

See the installation section in the documentation pages for more.

Unit of measure

The FlowMeter library expresses flow in the unit l/min. Most units of measure can be derived by simple conversion (just try not to measure in Sverdrups).

As an example, conversion between l/min and US gal/min can be done with a factor of 3.78541178, conversion from min to s with a factor of 60.

$$3.78541178 l/min ≈ 1 gal/min ≈ 0.0167 gal/s.$$

Please make sure you consult the documentation in order to further understand how the library works.

Should you calibrate your own sensor?

The FlowMeter library can be used with many different flow sensors right away. Some sensor examples are listed in the documentation.

For many projects you don't need to worry about calibration. But it still makes sense to be aware of the limitations that come with an uncalibrated sensor in a metering application.

It's easy to calibrate yourself. Preferrably you'd do this after installing the sensor into your project. The flow meter then benefits from increased precision within the viscosity and flow range of your application.

There's a complete how-to in the documentation.

Calibration Example: Irrigation with FS400A

Documentation

For further details please take a look at the FlowMeter documentation pages.

Also, the library source code (in the folder src/) and the examples (in the folder examples/) are fully documented.

flowmeter's People

Contributors

outlandnish avatar per1234 avatar sekdiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flowmeter's Issues

Provide example and explanation about non-blocking scheduling.

Currently, most examples use the delay() function to simulate time.
This is blocking behaviour which makes the examples short and concise, yet impractical.

When studying the examples and explanations, users should be enabled to schedule tasks without blocking behaviour while still being able to start their own project via copy-and-paste.

The calibration example actually provides non-blocking behaviour, but it is the most complex one to understand (and most users don't seem to use it as a baseline for their own work).

Arduino IDE states 'Category in library FlowMeter is not valid'

Expected behavior

Everything is fine while compiling for ESP8266 on the Arduino IDE.

Observed behavior.

Arduino IDE 1.8.5 reports warning:

WARNING: Category 'Device Control Sensors Sensor Measurement Liquid Water Flow Meter' in library FlowMeter is not valid. Setting to 'Uncategorized'

problem with library

Description
there are a problem with the reset of meter i have a Yf s402 sensor i have make some calibration for it but it in first filling gives required quantity second it is wrong with minus

Question: Using this with WM-PD Water Meter

I'm wanting to use this library with the following meter:
https://www.flows.com/wm-pd-series-low-flow-water-meter/
https://www.flows.com/content/literature/Datasheets/WM-PD%20Datasheet%20V2.pdf

The datasheet states .05 pulses per gallon. I was looking at your docs, and I was wondering if that means the kFactor is 0.0881? 20 pulses per gallon or ~5.284 pulses per liter, divide by 60 and then I came to .0881. The datasheet does provide different error calculations for a few different flow rates. Is that something I need to add as well?

Thanks!

Question about the sensor fm-hl3012

I use a sensor fm-hl3012 in a coffee maker.
Here is the datasheet https://datasheet.lcsc.com/szlcsc/1912111437_EPT-TECH-FM-HL3012_C379915.pdf
Based on the datasheet, my settings are
FlowSensorProperties HL3012 = {0.50f, 76.0f, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};
Are the settings correct?
When I check the coffee maker without filters, the measurements are approximately correct.
When I insert the filter even without coffee. Measurements are approximately doubled.
Why such big differences in measurements?
Need a more accurate calibration?

Compile fail with Nano 33 IOT and MKR 1010

Description
FlowMeter example Simple.ino does not compile for Nano 33 IOT (using pin 2 or 3) and MKR 1010 (using pin 4) boards.
Compiles/Verify correctly for Uno and Nano boards.

Reproduction
Steps to reproduce the behavior:

  1. Connect '...'
  2. Measure '...'
  3. Error '...'
  4. FQBN: arduino:samd:nano_33_iot
    Using board 'nano_33_iot' from platform in folder: /Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13
    Using core 'arduino' from platform in folder: /Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13

Detecting libraries used...
/Users/mack/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino NANO 33 IoT" -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated-avr-comp -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/variants/nano_33_iot /private/var/folders/5v/dc3kh_4136g2j560dgjg3vww0000gn/T/arduino/sketches/C68A8D46ABA33F055F35B22017641534/sketch/Simple.ino.cpp -o /dev/null
Alternatives for FlowMeter.h: [[email protected]]
ResolveLibrary(FlowMeter.h)
-> candidates: [[email protected]]
/Users/mack/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino NANO 33 IoT" -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated-avr-comp -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/variants/nano_33_iot -I/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src /private/var/folders/5v/dc3kh_4136g2j560dgjg3vww0000gn/T/arduino/sketches/C68A8D46ABA33F055F35B22017641534/sketch/Simple.ino.cpp -o /dev/null
/Users/mack/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino NANO 33 IoT" -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated-avr-comp -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/variants/nano_33_iot -I/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src /Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp -o /dev/null
Generating function prototypes...
/Users/mack/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON -DUSB_MANUFACTURER="Arduino LLC" -DUSB_PRODUCT="Arduino NANO 33 IoT" -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated-avr-comp -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/variants/nano_33_iot -I/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src /private/var/folders/5v/dc3kh_4136g2j560dgjg3vww0000gn/T/arduino/sketches/C68A8D46ABA33F055F35B22017641534/sketch/Simple.ino.cpp -o /private/var/folders/5v/dc3kh_4136g2j560dgjg3vww0000gn/T/4284101656/sketch_merged.cpp
/Users/mack/Library/Arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /private/var/folders/5v/dc3kh_4136g2j560dgjg3vww0000gn/T/4284101656/sketch_merged.cpp
Compiling sketch...
/Users/mack/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON "-DUSB_MANUFACTURER="Arduino LLC"" "-DUSB_PRODUCT="Arduino NANO 33 IoT"" -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated-avr-comp -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/variants/nano_33_iot -I/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src /private/var/folders/5v/dc3kh_4136g2j560dgjg3vww0000gn/T/arduino/sketches/C68A8D46ABA33F055F35B22017641534/sketch/Simple.ino.cpp -o /private/var/folders/5v/dc3kh_4136g2j560dgjg3vww0000gn/T/arduino/sketches/C68A8D46ABA33F055F35B22017641534/sketch/Simple.ino.cpp.o
Compiling libraries...
Compiling library "FlowMeter"
/Users/mack/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10607 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON "-DUSB_MANUFACTURER="Arduino LLC"" "-DUSB_PRODUCT="Arduino NANO 33 IoT"" -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/Users/mack/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/deprecated-avr-comp -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino -I/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/variants/nano_33_iot -I/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src /Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp -o /private/var/folders/5v/dc3kh_4136g2j560dgjg3vww0000gn/T/arduino/sketches/C68A8D46ABA33F055F35B22017641534/libraries/FlowMeter-master/FlowMeter.cpp.o
/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp: In constructor 'FlowMeter::FlowMeter(unsigned int, FlowSensorProperties, void ()(), uint8_t)':
/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:18:83: error: no matching function for call to 'attachInterrupt(unsigned int&, void (
&)(), uint8_t&)'
attachInterrupt(this->_pin, this->_interruptCallback, this->_interruptMode);
^
In file included from /Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/Interrupts.h:8:0,
from /Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/ArduinoAPI.h:29,
from /Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/Arduino.h:23,
from /Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:5:
/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/Common.h:111:6: note: candidate: void attachInterrupt(pin_size_t, voidFuncPtr, PinStatus)
void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode);
^~~~~~~~~~~~~~~
/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/Common.h:111:6: note: conversion of argument 3 would be ill-formed:
/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:18:69: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'PinStatus' [-fpermissive]
attachInterrupt(this->_pin, this->_interruptCallback, this->_interruptMode);
~~~~~~^~~~~~~~~~~~~~
In file included from /Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/ArduinoAPI.h:29:0,
from /Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/Arduino.h:23,
from /Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:5:
/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/Interrupts.h:38:27: note: candidate: template void arduino::attachInterrupt(pin_size_t, arduino::voidTemplateFuncPtrParam<T*>, PinStatus, T*)
template void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam<T*> userFunc, PinStatus mode, T* param) {
^~~~~~~~~~~~~~~
/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/Interrupts.h:38:27: note: template argument deduction/substitution failed:
/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:18:83: note: candidate expects 1 argument, 0 provided
attachInterrupt(this->_pin, this->_interruptCallback, this->_interruptMode);
^
In file included from /Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/ArduinoAPI.h:29:0,
from /Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/Arduino.h:23,
from /Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:5:
/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/Interrupts.h:21:27: note: candidate: template void arduino::attachInterrupt(pin_size_t, arduino::voidTemplateFuncPtrParam, PinStatus, T&)
template void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam userFunc, PinStatus mode, T& param) {
^~~~~~~~~~~~~~~
/Users/mack/Library/Arduino15/packages/arduino/hardware/samd/1.8.13/cores/arduino/api/Interrupts.h:21:27: note: template argument deduction/substitution failed:
/Users/mack/Documents/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:18:83: note: candidate expects 1 argument, 0 provided
attachInterrupt(this->_pin, this->_interruptCallback, this->_interruptMode);
^

Using library FlowMeter at version 1.2.0 in folder: /Users/mack/Documents/Arduino/libraries/FlowMeter-master
exit status 1

Compilation error: exit status 1

Hardware (please complete the following information):

  • Board type Nano 33 iot
  • Sensor type
  • Pins used

Software (please complete the following information):

  • OS 12.7.2
  • IDE2.2.1
  • Other libraries

Minimal example to reproduce (please complete the following information):

  • Code to reproduce Simple.ino
  • Wiring to reproduce

Additional context
Add any other context about the problem here.

How to place your M-Factor Values right in the String ?

Description
I am using an 10mm flow sensor connected to a tap line, the water flow is controlled by the Tap, However the tap is supper sensitive and reaches its max in a 40% turn. The max flowrate i am able to record is 5.5L /pm. We are able to measure the the max flowrate by tweaking our K-factor as a start, hence the nominal is just right, then i go about measuring different flowrates for the mfactor values. We have now 7 intervals ( 7 M-factors values, we start with 1 for all 10 Mfactor values and do actual/nominal to the right mfactor values )

How do we decide which interval value should correspond to the M factor value ?
When we put the first 6 values as we have and 1 for remaining, its not giving us right output.
We tried different combinations, its no results. What would be the logic behind how we place the Mfactor values ?

I am able to get the updated values, but dont know how to how place them correctly in the Mfactor String.

Could anyone perhaps shed some light on this ?

ESP32 example

I had to change the example slightly, and use digitalPinToInterrupt, to make it work on ESP32 using arduino framework:

int pin = 21;
attachInterrupt(digitalPinToInterrupt(pin), TestSR, RISING);
// vs attachInterrupt(INT0, TestSR, RISING);

Improve support of saving and restoring to memory

Currently the flow meters can only be saved and restored partially (and only manually).

In applications that power down between measurements, users should be enabled to continue using a flow meter without losing prior measurement statistics and sensor properties.

In short: an improved serialize and unserialize capability that directly supports dynamically saving and restoring the full state of a flow meter.

.getCurrentVolume reset every request

I am having some trouble monitoring pumped volumes using .getCurrentVolume .

This is a section of my code that runs in a subroutine called from the loop as needed.

 unsigned int targetTotal =  Ml; //millilitres to be dispensed, Ml is passed when the dispense function is called.
  flowMeter.reset();
  double aliquot = 0;
  
  while ((flowMeter.getCurrentVolume() * 1000) < targetTotal) {       //*1000 to get Millilitres,,
    flowMeter.tick(flowMeterPeriod);             //flowMeterPeriod is 1000
    aliquot = flowMeter.getCurrentVolume() * 1000;
    lcd.setCursor(12, 3);
    lcd.print(aliquot);
    Serial.println(aliquot);
    if (digitalRead(setPin) == LOW) {  //hardware switch to cancel dispensing
      break;
    }

    currentTime = millis();  
    if ((currentTime - startTime) > timeOut) {  //Time-out function timeOut set by volume of requested dispense
      lcd.setCursor(11, 3);
      lcd.print("T");
      timedOut = true;
      break;
    }
    delay(flowMeterPeriod);  // blocking behaviour ok in this function?
  }

I expect to see the value of current volume in the variable "aliquot" incremented every second giving a total of the volume dispensed during this dispense cycle, after the reset instruction, ie counting from 0 up.

What I actually see is the volume dispensed in a second displayed every second and not incrementing. ie 5.1, 5.1, 5.3, 5.0 etc.

The totalVolume function works as anticipated and shows the total volume incremented by the dispensed volume at the end of the dispense function.

I am using an Arduino nano.

I've been stuck on this for a while but apologise for any stupidity on my own part in advance

YF-B5 unstable pulses, huge difference between actual and nominal values

Hello, recently I've tried to calibrate my YF-B5 sensor, but when I launch the program for calibration, I face two issues:

  1. The current flow rate is shown abnormally huge, also the difference between real & nominal values are somewhat doubled or tripled. As example: filling the cup of 500 millilitres shows a nominal value of around 1L. When opening the tap all the way, it's showing 60-120 l/min, even though my sensor is max at 30 l/min as per documentation (also I've tested with the bucket, I can fill around 15L per minute with the tap all the way). Is this supposed to be like that with the big difference between real/nominal values? Should I continue calibrate and mark (as per first example of 500 millilitres) a proportion as 0.5? Thanks.
  2. I cannot get the stable reading of water flow. Whenever I open the tap on the same level, the flow rate just starts jumps, leaving a +- 2 litres gap. For example, it could be showing 2.19 l/min, 3.45 l/min or 5.41 l/min (when tap running slow, approx. 2L/min). Is there anything I can do? Or should I just approximate this example as, let's say, 3 l/min as it would be 5 percent of my capacity, mark the real & nominal values and continue calibrating?
  3. If my template's flow rate columns are 3, 6, 9... 30, how to correctly carry out this calibration, when (looking at my first issue) the flow rate is too big comparing to the real one. The tap all the way showing 60-120L/min.

My sensor's properties at the beginning of calibration:
FlowSensorProperties MySensor = {30.0f, 6.6f, {0.4, 0.25, 0.2, 1, 1, 1, 1, 1, 1, 1}};

Sensor's datasheet (not sure if this this authenticate and really true, but the flow model is correct):
https://media.digikey.com/pdf/Data%20Sheets/Seeed%20Technology/114991175_Web.pdf

image

Thanks for the help.

Compile for ESP8266?

Very new to programming. Thanks for this great library, I used it to make a great flow rate meter with totalizer. I wanted to re build the sketch and compile it for use with a Huzzah esp8266 module and send data to my Adafruit Io panel.. I have successfully complete this task with other sensors, but the flowmeter.cpp file is throwing me for a loop. The .cpp file seems to drop many issues for the Esp8266 compiling. Adruino IDE 1.8.1
Any help would be appreciated. hopefully the code is attached.

/* hookup instructions::  
Compiled for Arduino NANO V3.1  rebuilt for Adafruit Huzzah ESP8266
The meter were using is a FS300A
meter pins:  Black to GND, Red to +5v, yellow or signal to D2
reset switch pins: one side of momentary switch to GND the other to D4
power in :  gnd and + 5v 
Displays: Adafruit .56" 7 segment displays with backpack.  I2C 
Display I2C pins:  VCC - +5v, GND to gnd, SCL to A5 and SDA to A4  -------*/

// Libraries
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_7segment matrix1 = Adafruit_7segment();
Adafruit_7segment matrix2 = Adafruit_7segment();
#include <FlowMeter.h>                 

// WiFi parameters
#define WLAN_SSID       "***enter here*****"
#define WLAN_PASS       "***enter here**********"

// Adafruit IO
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "**username**"
#define AIO_KEY         "**user key**"

// define the sensor characteristics here
const double cap = 60.0f;  // l/min
const double kf = 5.5f;     // Hz per l/min
const int pin = 2;         // INT0 pin on most Arduinos
const int ResetButton = 4;      //pin that reset switch is attached to
int ResetNow;

// let's provide our own sensor properties (without applying further calibration)(FS300A)
FlowSensorProperties MySensor = {60.0f, 5.5f, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};

// now initialize the flow meter with the pin and sensor settings
FlowMeter Meter = FlowMeter(pin, MySensor);

// set the measurement update period to 1s (1000 ms)
const unsigned long period = 1000;
float FlowrateGallons = 0;
float VolumeGallons = 0;

// define an 'interrupt service handler' (ISR) for every interrupt pin you use
void MeterISR() {
  // let our flow meter count the pulses
  Meter.count();
} 

// Functions
void connect();
void publish();
long time = 0;
long sendTime = 30000;

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

// Setup feeds for publishing data  totalgallons and flowrate
Adafruit_MQTT_Publish totalGallons = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/basement.total-gallons");
Adafruit_MQTT_Publish flowRate = Adafruit_MQTT_Publish(&mqtt,  AIO_USERNAME "/feeds/basement.flow-rate");

/*************************** Sketch Code ************************************/

void setup() {
  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  delay(10);
  Serial.print(F("Connecting to "));
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println();

  Serial.println(F("WiFi connected"));
  Serial.println(F("IP address: "));
  Serial.println(WiFi.localIP());

  // connect to adafruit io
  connect();
  
  pinMode(ResetButton, INPUT_PULLUP);
  ResetNow = HIGH;
  
  // prepare serial communication
  Serial.begin(115200);
  matrix1.begin(0x70);
  matrix2.begin(0x72);    //  (0x74) if need be
  
  // enable a call to the 'interrupt service handler' (ISR) on every rising edge at the interrupt pin
  // do this setup step for every ISR you have defined, depending on how many interrupts you use
  attachInterrupt(pin, MeterISR, RISING);

  // sometimes initializing the gear generates some pulses that we should ignore
  Meter.reset();
  
}

void loop() {
  // ping adafruit io a few times to make sure we remain connected
  if(! mqtt.ping(3)) {
    // reconnect to adafruit io
    if(! mqtt.connected())
      connect();
  }
  
  // wait between output updates
  delay(500);
 
  // process the (possibly) counted ticks
  Meter.tick(period);

   // convert system variables to Gallons  .264 gallon / litre
  FlowrateGallons = (Meter.getCurrentFlowrate() / 3.78541178);
  VolumeGallons = (Meter.getTotalVolume() / 3.78541178);

  // output result to serial monitor for debugging
  // uncomment next 2 lines to see results in serial monitor
  //Serial.println("Currently " + String(Meter.getCurrentFlowrate()) + " l/min, " + String(Meter.getTotalVolume())+ " l total.");
  //Serial.println("Currently " + String(FlowrateGallons) + " G/min, " + String(VolumeGallons)+ " Gal total.");

  // if a preset time has elapsed then publish the data to adafruit io
  if(millis() - time > sendTime) {
    publish();
    time = millis();
  }

  // print result to 7 segment display
  matrix1.setBrightness(10);
  matrix1.print(FlowrateGallons);
  matrix1.writeDisplay();
  delay(10);
  matrix2.setBrightness(5);
  matrix2.print(VolumeGallons);
  matrix2.writeDisplay();
  
  // reset button function, will reset meter if pressed
  ResetNow = digitalRead(ResetButton);
   if(ResetNow == LOW){
    Meter.reset();
   }
}

// Publish data to adafruit IO
void publish() {
  if (! totalGallons.publish(VolumeGallons))
    Serial.println(F("Failed to publish Total Gallons"));
  else
    Serial.println(F("Total Gallons published!"));
    Serial.println(VolumeGallons);
    
  if (! flowRate.publish(FlowrateGallons))
    Serial.println(F("Failed to publish Flow Rate"));
  else
    Serial.println(F("Flow Rate published!"));
    Serial.println(FlowrateGallons);
}

// connect to adafruit io via MQTT
void connect() {

  Serial.print(F("Connecting to Adafruit IO... "));

  int8_t ret;

  while ((ret = mqtt.connect()) != 0) {

    switch (ret) {
      case 1: Serial.println(F("Wrong protocol")); break;
      case 2: Serial.println(F("ID rejected")); break;
      case 3: Serial.println(F("Server unavail")); break;
      case 4: Serial.println(F("Bad user/pass")); break;
      case 5: Serial.println(F("Not authed")); break;
      case 6: Serial.println(F("Failed to subscribe")); break;
      default: Serial.println(F("Connection failed")); break;
    }

    if(ret >= 0)
      mqtt.disconnect();

    Serial.println(F("Retrying connection..."));
    delay(5000);

  }

  Serial.println(F("Adafruit IO Connected!"));

}

HERE are the error messages::::*******************

Arduino: 1.8.1 (Mac OS X), Board: "Adafruit HUZZAH ESP8266, 80 MHz, 4M (1M SPIFFS), v2 Prebuilt (MSS=536), Disabled, None, 115200"

Build options changed, rebuilding all
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp: In member function 'void FlowMeter::tick(long unsigned int)':
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:41:31: error: 'SREG' was not declared in this scope
unsigned int interrupts = SREG; //!< save the interrupt status
^
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:49:99: error: no matching function for call to 'min(unsigned int&, int)'
this->_currentCorrection = this->_properties.kFactor / this->_properties.mFactor[min(decile, 9)]; //!< combine constant k-factor and m-factor for decile
^
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:49:99: note: candidates are:
In file included from /Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:62:0,
from /Users/user/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/Arduino.h:240,
from /Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:7:
/Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4226:5: note: template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare)
min(initializer_list<_Tp> __l, _Compare __comp)
^
/Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4226:5: note: template argument deduction/substitution failed:
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:49:99: note: mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
this->_currentCorrection = this->_properties.kFactor / this->_properties.mFactor[min(decile, 9)]; //!< combine constant k-factor and m-factor for decile
^
In file included from /Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:62:0,
from /Users/user/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/Arduino.h:240,
from /Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:7:
/Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4221:5: note: template _Tp std::min(std::initializer_list<_Tp>)
min(initializer_list<_Tp> __l)
^
/Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4221:5: note: template argument deduction/substitution failed:
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:49:99: note: mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
this->_currentCorrection = this->_properties.kFactor / this->_properties.mFactor[min(decile, 9)]; //!< combine constant k-factor and m-factor for decile
^
In file included from /Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:61:0,
from /Users/user/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/Arduino.h:240,
from /Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:7:
/Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:239:5: note: template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:239:5: note: template argument deduction/substitution failed:
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:49:99: note: deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'int')
this->_currentCorrection = this->_properties.kFactor / this->_properties.mFactor[min(decile, 9)]; //!< combine constant k-factor and m-factor for decile
^
In file included from /Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/algorithm:61:0,
from /Users/user/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/Arduino.h:240,
from /Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:7:
/Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:193:5: note: template const _Tp& std::min(const _Tp&, const _Tp&)
min(const _Tp& __a, const _Tp& __b)
^
/Users/user/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:193:5: note: template argument deduction/substitution failed:
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:49:99: note: deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'int')
this->_currentCorrection = this->_properties.kFactor / this->_properties.mFactor[min(decile, 9)]; //!< combine constant k-factor and m-factor for decile
^
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp: In member function 'void FlowMeter::reset()':
/Users/user/Dropbox/Personal/Arduino/libraries/FlowMeter-master/src/FlowMeter.cpp:68:31: error: 'SREG' was not declared in this scope
unsigned int interrupts = SREG; //!< save interrupt status
^
exit status 1
Error compiling for board Adafruit HUZZAH ESP8266.

Split up flow sensor and flow meter into different classes and files.

Currently the sensing and the metering functions are merged into one class/object, requiring users to deal with the complexity of the metering interface even if all they need is a simple flow rate value.

When connecting one or multiple sensors, users should have the choice between a lightweight interface to their hardware and a sophisticated metering solution.

Connecting multiple flow meters

I tried to connect two flow meters on pins 2 & 3 of an Uno but it only shows the total for the first meter when polled using String(Meter1.getTotalVolume())

I used the simple example and set it up like this:
FlowMeter Meter1 = FlowMeter(2); FlowMeter Meter2 = FlowMeter(3);

Software Debounce

I’m using EKM flow meters for a project that use a reed switch for triggering the pulses from the wheel. It would be nice to be able to supply a debounce interval to work with reed switches over hall sensors.

Question on Digiten G1 - Probably FS400A

Hi,

First of all, thanks for the great work on this library! I had a question on sensor calibration in general, and I was hoping you could help since you have a lot of knowledge on this subject.

I'm trying to measure flow/consumption in my garden which uses drip irrigation. I'm using the following sensor on Amazon. I think the sensor has the same specs as the FS400A; however, the constant value is 4.8 on Amazon which I think is too high anyways (4.5 seems more reasonable).

I've hooked up a few flow meters on the supply line to try and verify the results of the sensor from Amazon. I also hooked in a digital flow meter as well in earlier tests.

Onto my question :) In 10 minutes, I see around 4.5 gallons consumed at the water flow meters; however, my Digiten sensor is only showing 1.2 gallons or so. I debugged the output, and I do see around 2 pulses per second which indeed equates to around 4.6L ~ 1.2gal.

If the Flow Meters are measuring flow accurately, it equates to 1.7 L/m which is within spec of 1-60; however, the error is so high! Is there something that I'm doing wrong? Is there a better sensor that yields more accurate results at low flow rates? Thanks so much!!

***EDIT
It's also possible that the sensor is reading a correct value while the other 2 flow meters are incorrect. I saw the Flows.com meter has a min of 6.6 GPH which is still within spec of the 1.2 GPM (7.2 GPH). If the Digiten is correct, then it's out of spec since that ends up being around 0.5L/m. Ahhh!

YF-DN32

Anyone using the YF-DN32 flow sensor ?
I can't find any reliable specs, some sites tell k=0.45*Q, other 4.5Q, other 0.45Q = l/m and so on

which one is the correct value ?

atm, i'm using the following:

  FlowSensorProperties YF_DN32 = {120.0f, 0.45f, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}};

but don't know if correct

Support for Arduino Uno Wifi Rev2

Hi Sebastian,

thanks for your work to put this together.

I am running a hydroponic system in my office growing lettuce based on the Uno Wifi Rev2 with lots of sensors on it. I bought a flowmeter and was happy to find this library. It seems as if its not supporting the Uno Wifi Rev2. When trying to compile your sample sketch in the web editor or also desktop client, me and a friend got the same error on different computers. When we switch to older Arduino versions through Tools->Boards it works. We could not get it to work on our own. Would be great if you would consider supporting the Rev2 or if you could give a hint how to solve it :)

Best regards
Philipp

Error Message:
Bildschirmfoto 2021-05-07 um 17 41 34

Gicar flowmeter unstable doses

Hi I tried so hard to calibrate my flowmeter from gicar.has 1 mm Ziegler and I can’t set it up properly all the time so different values .if it is possible can we see the pulses from the flowmeter?that it can help much more
31380E3F-CA85-4EE4-B03C-4FD7DFE93E4A

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.