Pulse counter ESP32 with YF-B10 - I cant calibrate

Pulser counter ESP32 with YF-B10

I have assembled a YF-B10 flowmeter and doing tests to perform the calibration I have realized that it measures differently depending on the flow that I tap.
I have filled a 0.5 liter bottle by opening the tap with a slow and fast flow.
But the equipment does not repeat the number of pulses that it counts for every 0.5 liters.

Can you tell me if something is missing or is the equipment not working well?I pass you the records of the number of pulses that it registers in 60 seconds, reaching 0.5 liters at different filling speeds.

test 1: 0,5liters ā†’ 19 pulsos (tap 25% open)
test 2: 0,5liters ā†’ 82 pulsos (tap 100% open)
test 3: 0,5liters ā†’ 36 pulsos (tap 50% open)
test 4: 0,5liters ā†’ 54 pulsos (tap 50% open)
test 4: 0,5liters ā†’ 28 pulsos (tap 25% open)
test 4: 0,5liters ā†’ 69 pulsos (tap 100% open)

With this variation of pulses depending on the demand, how can I calibrate the equipment to measure correctly?

  - platform: pulse_counter
    name: "consumo agua litros"
    pin:
      number: GPIO2
      mode: INPUT_PULLUP
    unit_of_measurement: "pulsos"
    icon: "mdi:water"

Thanks

'[09:44:03][D][pulse_counter:160]: 'consumo agua litros': Retrieved counter: 19.00 pulses/min
[09:44:03][D][sensor:113]: 'consumo agua litros': Sending state 19.00000 pulsos with 2 decimals of accuracy

[09:45:03][D][pulse_counter:160]: 'consumo agua litros': Retrieved counter: 82.00 pulses/min
[09:45:03][D][sensor:113]: 'consumo agua litros': Sending state 82.00000 pulsos with 2 decimals of accuracy

[09:48:03][D][pulse_counter:160]: 'consumo agua litros': Retrieved counter: 36.00 pulses/min
[09:48:03][D][sensor:113]: 'consumo agua litros': Sending state 36.00000 pulsos with 2 decimals of accuracy

[09:51:03][D][pulse_counter:160]: 'consumo agua litros': Retrieved counter: 54.00 pulses/min
[09:51:03][D][sensor:113]: 'consumo agua litros': Sending state 54.00000 pulsos with 2 decimals of accuracy

[09:53:03][D][pulse_counter:160]: 'consumo agua litros': Retrieved counter: 28.00 pulses/min
[09:53:03][D][sensor:113]: 'consumo agua litros': Sending state 28.00000 pulsos with 2 decimals of accuracy

[09:56:03][D][pulse_counter:160]: 'consumo agua litros': Retrieved counter: 69.00 pulses/min
[09:56:03][D][sensor:113]: 'consumo agua litros': Sending state 69.00000 pulsos with 2 decimals of accuracy'

0.5L in one minute is below the specified minimum flow rate for this sensor:

Flow rate : 2~50L/min

You are right, I have calibrated it with 5L / min and the measurement seems to stabilize.

For the one that interests you, I get the following result:
1 liter = 373 pulses (YF-B10)

If there is someone that does not come out similar to indicate it

This function indicates the manufacturer (6 * Q-8) Q) what is it for, once you have it calibrated?

Thanks

If Q is the number of pulses then then from that equation the number of pulses is not linearly proportional to the flow rate, as assumed by the pulse counter. You will have to apply this:

https://esphome.io/components/sensor/index.html#calibrate-polynomial

I understand what you are saying, but I donā€™t see much sense that since the flow is not linear, does the formula say that multiplies the flow by 8 and subtracts 6?

new pulses/min= (6 * Q-8)
It does not say under what circumstances to push the regression.

Do you have any examples of similar equipment?

No. Expanded out the formula says flow (L/min) = 6QĀ² - 8Q.

Itā€™s a quadratic. Hence you need to use calibrate_polynomial, not calibrate_linear.

Use degree 2 as the biggest power is Q squared.

  filters:
    - calibrate_polynomial:
       degree: 2
       datapoints:
        # Map from sensor to true value, use your measurements not this example.
        - 0.0 -> 0.0
        - 10.0 -> 12.1
        - 13.0 -> 14.0

The more data points you have the better. One point is not enough to calibrate a polynomial.

Or you could use a lambda filter expressing the equation:

https://esphome.io/components/sensor/index.html#lambda

filters:
  - lambda: return x * (6 * x - 8);

That would be easier.

1 Like

I understand how the polynomial works, which seems to me that the polynomial indicated by the manufacturer is not well formulated.

Iā€™ll look at it anyway.

Thank you so much

Hello
I am considering purchasing the YF-B10 to account for water flow. Did you manage to get yours working? Are the measurements reliable?

@fmmsfz donā€™t expect any answer the next 100 days or even after thatā€¦

image

better than resuscitate old threads is just making use of the (free) search :mag: function this forum offers :+1:

this feels like an old thread, and i might be a little of topic here, but i came across it as it was the closes to what i am looking for.

i just started implementing the same sensor (not sure about the exact same ā€œpulse counterā€ in it, as mine says its Flow rate : 1~30L/min), and need some help with the calibrations.

can someone share the steps for the calibration?
how do i figure my ā€œlambda returnsā€ filter equation?

i got this sensor of aliexpress, and surprisingly enough - seller does not have any other info to give me as far as ā€œQā€ goes. honestly - not really sure what it means myselfā€¦ so donā€™t really know what to ask him to find out for meā€¦
so i figured ill try our community instead, and figure this out for ourselvesā€¦
:crossed_fingers:

cheers

1 Like

Would be interested too in some more information

Hi @tom_l
Thank you for that solution! If I write the lambda, I donā€™t need to do the measurement and write the calibration lines? Right now, I find crazy values ! Like 155 billion liters per minute with the lambda formula you gave.
What happens if the flow is getting more than 50 L per minute ? It is just imprecise but should stay more or less on the same curve, no?

No. The manufacturer has only specified an equation for the range 2-50 L/min. Outside that range it is uncharacterised. It could even stop being proportional.

also about to try and get this flow sensor working

1 Like

Hi,
Iā€™, also struggeling with calibration of that device for some time. I follewd approach suggested by @tom_l .
y=Q(6Q-8).
I adapted it to my own project on Arduino as:

return (calibrationDifference+sqrt(pow(calibrationDifference,2)-4*calibrationFactor*(-freqency)))/(2*calibrationFactor);

Pllase just note that for ā€˜calibrationDifferenceā€™ > 0, reading will be > 0 even if no pulse given, so be sure to filter it out.

Itā€™s pretty promissing as Iā€™m getting pretty accurate readings. I can publish the whole code on my GitHub if needed.

There seems to be 2 variants of the sensor: one with f=6xQ-8, the other one with f=8xQ-4.

f is the pulse frequency (pulses/second) and Q is the water flow in liters/minute.

For a water flow of 10 liters/minute you get 6x10-8=52 pulses/second or 3,120 pulses/minute, i.e. 312 pulses per liter. For the other variant itā€™s 456 pulses per liter.

Somewhere, I also saw 476 pulses/liter (which is within the 5% margin of error of 456).

Deviding pulses/minute or the number of total pulses by this number gives you Liter/minute or total liter.

By the way, my sensor also works with 3.3 V input voltage (not to overload the ESP32). My (unprofessional) measurements were 470 pulses per liter, independent of the flow speed or flow/minute.

1 Like

@Marc77 I got the YF-B10 and in the description of aliexpress it states:
F = 8Q - 4 and 476 pulses per liter.

Which formula did you use in your yaml?
Actually Iā€™m using:

return (x + 4)/8/60;

I also read and saw that if I have X=0, the function doesnā€™t go to 0. A solution that I read is to put this condition to take in account the fact the range is 2-50 l/min

      - lambda: !lambda |-
          if (x < 240) return (x / 120);
          return (x + 4)/8/60;

but Iā€™m not sure about the 240: from what I understand 240 pulses should be around 0.5 liters and not the 2. Should I modify it to 476*2?

Unfortunately, the documentation of these items is horrible and not very clear

I just need the number of liter. I therefore use a puls counter and multiply the number of pulses by 1/476.

- platform: pulse_counter
  pin: x
  unit_of_measurement: "l/min"
  name: "Liter per minute"
  filters:
    - multiply: 0.0021008403361 #1/476 pulses/min -> liter/min
  total:
    unit_of_measurement: "l"
    name: "Total no of Liter"
    filters:
      - multiply: 0.0021008403361 #1/476 pulses -> liter

HI all. Just to be sureā€¦ if the manual says 596 pulse x mini

If im not wrong.
"filters:

  • lambda: return (x+4)/10/60;

lambda: return (x+4)/10/60;
x= 565
(565+4)/10 = 60 / 60 = 1 Ltā€¦

  • platform: pulse_counter
    pin: x
    unit_of_measurement: ā€œl/minā€
    name: ā€œLiter per minuteā€
    filters:
    • multiply: 0.001680672269
      total:
      unit_of_measurement: ā€œlā€
      name: ā€œTotal no of Literā€
      filters:
      • multiply: 0.001680672269

Its not very accurate in my case:(

Stream range: 2~50L|MIN$5%

Specification

Model: YF-B10

Interface size: G1

Rated voltage: DC3.5~24V

Inner/Outer Diameter: 24.38mm/32.9mm

Thread length: 13mm

Material: Stainless steel

Water pressure resistance: >1.75MPa

Output pulse high level: >DC4.7V (input voltage DC5V)

Output pulse duty cycle: 50%10%

Insulation resistance: >100M2

Stream range: 2~50L|MIN$5%

Airtightness: close each hole, add 1.7Mpa water pressure test for 1 minute without leakage and deformation Stream pulse characteristics: F=(10*Q-4)Ć·5%, F is the frequency Q is L/Min, that is, 595 pulses per liter of water