I have used a YF-B5 - it was pretty accurate on my heating circuit. I used a D1Mini to connect it up. Worked well.
My one word of warning; it’s very noisy!!!
As it has an impeller, it introduces mechanical noise into the water. Water is a great conductor of source.
As I’m using mine on a heating circuit, when my boiler turns on, we can hear the noise in every room in my house. The radiators are acting as speakers I think!
@DeeBeeKay Sorry to trouble you. In your photo of Jun 2019, you mention a resistor, but I cannot see it in the picture. Do you (or anyone else) by any chance, have a simple circuit diagram for the connections from the flow meter to the D1-Mini, so I can see where the resistor should go? Thank you.
I know it’s been a long time since your post.
Typing on phone, so I’ll be short.
I’m struggling here, just as you did. Found out the divider does not work on this setup. I’ll give details later.
But what I’d like to know is how did you get the lambda. Why did you multillied 6.6 to 60 to get the 396. I have the same sensor as you. I think I’m misunderstanding this frequency formula on the specs.
Finally. Let me explain better. Need some help/advice.
This esphome is making me crazy.
I have a canister on my aquarium and installed this YF-B5 on it. It’s nominal flux is 1000L/h.
All details of my project I’m putting in this topic:
So, I programmed the ESPHome on a ESP32 and it was not working. I was getting no signal, no pulses. I tested before on a test circuit using a ESP8266 (d1_mini) and it was working. So I decided to back to D1 mini. It also stopped working, until I remove the divider resistors (5V → 3.3V) and plugged the wire directly on the pin.
Now I have pulses ! But depending on how I configure esphome, I have a different result.
First problem/doubt:
I’ve seen some calculations above, multiplying the factor 6.68 to 60 and getting L/min. My frequency formula is F=6.68*Q.
Considering F = Hz, is it the number of pulses the sensor outputs ? Does it mean L/min ? Because If I get this number and divide by 6.68 I will get the Q=L/min. So I don’tknow why are you multipliyng the factor by 60 and dividing the “x” (the value read from the sensor) by this number.
SECOND doubt:
I made just like you did, but if I change the way I code ESPHOME, I’m getting different results, I don’t know why:
The 396 comes from a different sensor model with a different formula. In our case with YF-B5, it uses F = 6.6 × Q, then dividing by 33 is correct. I hope it helps!
Thank you ! Now it’s clear what you did. Everything depends on the time delta the pulses are gotten.
But even this I`m getting strange results:
Getting about 300.000 pulses/min.
Teoretically, the result of Q should be L/min, but it seems to be in L/h. My canister has a nominal flux of 1000L/hr.
My colect timer is set to 60s.
Flux Hour 45.990,1 L/h
Flux Min. 766,5 L/min
Pulses / min 307.214 pulses
An interesting site I found some time ago is the one below. The update interval of his setup is 1s and his formula is x/400 for L/min (x / 6.68 * 60). So confusing… https://tecnoyfoto.com/sensor-de-flujo-de-agua-yf-b5
Your logic is mostly correct, but there’s a small mistake in the way the flow rate is being calculated. The issue is that you’re already collecting pulses per minute, yet you’re treating the result as if it’s per second.
You have:
update_interval: "${flux_time}s"
where flux_time = 60.
This means you’re already counting pulses per minute, so there’s no need to divide by 60 again when calculating liters per hour.
Thanks, I think I started understanding, but the code didn’t work. Both formulas are the same, for min and for hr.
I multiplied the hr calculation by 60, but I’m getting 1.400L/min on the other. There’s still something odd.
Initially, I just adjusted your formula substituting the 5s to 60s from mine.
EDIT: I’m getting some weird readings. 2.400 pulses/min (I was getting over 300.000!)
Please tell me: the F (frequency) is the reading the sensor returns, right (the X)?
If yes, then if I have a flux of 800l/h, that gives me 800/60 that is: 13.3 L/min. So, the number of pulses I should get should be F /60 = 6.68 * 13.33 = 5.343 pulses/min.
I don’t know if it right. I’m getting 2.400 pulses. This could be right, but the 300.000 I was getting before seems strange.
Of course, I’m assuming the F will be the reading x I get on ESPHome.
Your ESPHome pulse_counter is already measuring pulses per minute because the update_interval is set to 60 seconds (flux_time = 60). To convert pulses per minute to liters per minute, you must divide by the pulse-to-flow conversion factor (id(freq_fluxo)), and to convert liters per minute to liters per hour, you must multiply by 60.
Good morning everyone…
I have build one of these discussed waterflow meters with the YF-B5 and so far it seems to work, but the devider is not correct…396 is not giving back enough flow…
Now before i start inching single digits wise towards the right value, i thought i could steal some code from another d1 min project i have where i can calibrate my sd30 co2 sensor right from the web page…
Can someone tell me if this could work and how i can fix this error?
I am not so into the lambda
/config/esphome/waterflowmeter.yaml:108:27: warning: character constant too long for its type
108 |
| ^
/config/esphome/waterflowmeter.yaml: In lambda function:
/config/esphome/waterflowmeter.yaml:108:20: error: 'lambda' was not declared in this scope
108 |
| ^
/config/esphome/waterflowmeter.yaml:108:26: error: expected ')' before '\x6174653b'
108 |
| ^
| )
*** [.pioenvs/waterflowmeter/src/main.cpp.o] Error 1
Thanks to all for making this so easy, it’s like LEGO. I found a steel case NPT meter here:
I connected it directly to the inlet side of my sprinkler master valve (which is 1"). I’ve wired it to an XIAO ESP32C3 and a 26V AC to 5V converter since that’s what’s available where the sprinkler valves are. The 3.3V/pulse/gnd are wired directly to the esp32 and the 5V/Gnd from the power converter are wired to the 5V/gnd of the esp32.
sensor:
- platform: pulse_counter
id: flow_rate
pin: GPIO10
name: "Flow rate"
update_interval: 1s
unit_of_measurement: "L/hr"
device_class: volume_flow_rate
# Flow formula F = (5Q – 3) ±10%
# * F is the pulse frequency in Hz
# * Q is the flow in l/min
# Input (x) is "pulses/min"
filters:
- lambda: 'return x > 0 ? (x / 5.0 + 36.0) : 0;'
- platform: integration
name: "Total volume"
sensor: flow_rate
time_unit: h
unit_of_measurement: "L"
device_class: water
restore: true
state_class: total_increasing
- platform: template
name: "Flow rate (gpm)"
unit_of_measurement: "gal/min"
device_class: volume_flow_rate
update_interval: 1s
lambda: return id(flow_rate).state * 0.004402867;
Note the ternary in the lambda. A naive usage of the flow equation would log a constant non-zero flow. Additionally because this makes the relation non-linear, I use an integration for total volume rather than relying on pulses. A GPM sensor is added but not a total gallons as HA does that conversion itself in the UI (depending on your units).
I did a test by running about 2.5 gallons through the system into a bucket and weighing the bucket. It was within about 1%.
Now if I could just figure out some automated integration with sprinkler, such as watering by volume rather than by time.