# YF-S201 Water Flow Sensor - Help with Require

**URL:** https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587
**Category:** General
**Created:** [23 July 2020 07:34 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587 "2020-07-23T07:34:06Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2020 09:35 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/21 "2020-07-27T09:35:57Z")

</div>

Further to @Steve-Mcl's suggestion, what does this command show?  
` npm list epoll`

I see

```auto
tigger@1.0.0 /home/colinl/.node-red
└─┬ water-flow-sensor@1.0.1
  └─┬ onoff@1.2.0
    └── epoll@1.0.2 

```

which does suggest that they are correctly installed.

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 09:37 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/22 "2020-07-27T09:37:29Z")

</div>

```auto
pi@raspberrypi:~/.node-red $ npm list epoll
node-red-project@0.0.1 /home/pi/.node-red
└─┬ water-flow-sensor@1.0.1
  └─┬ onoff@1.2.0
    └── epoll@1.0.2

```

The last line is orange colored.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [27 July 2020 09:46 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/23 "2020-07-27T09:46:18Z")

</div>

I wonder if this is node version related?

What does `node -v` give you (what node -v are you using @colin)

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 09:47 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/24 "2020-07-27T09:47:06Z")

</div>

Mine is v12.18.2

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2020 09:55 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/25 "2020-07-27T09:55:38Z")

</div>

I am on 10, but also not on a pi, but that shouldn't make any difference. The actual error says it can't find libnode.so.64 which seems very odd.  
I have a pi running node 12 I will try it on that.

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 09:59 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/26 "2020-07-27T09:59:46Z")

</div>

Okay. I'll wait for that.

Also, if this doesn't work at all, I can use an Arduino to get the values and somehow communicate it with Node-Red. I saw a guy doing that with DS18B20. I couldn't even make an LED blink. It was too weird for me. Couldn't understand much about Firmata protocol.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2020 10:01 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/27 "2020-07-27T10:01:46Z")

</div>

That is odd, I can't install it on node 12. Did you update nodejs at some point possibly?

[Edit] Whatever the answer to that, run this and post the result please

```auto
npm remove water-flow-sensor
npm install water-flow-sensor

```

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 10:09 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/28 "2020-07-27T10:09:28Z")

</div>

I got so many errors. I was using the built-in Node-Red at first. I must have downloaded it before I updated Node-Red. Without the update, there were no settings.js file. I had to update it.

I can't even post the terminal lines. Limit is 32 thousand characters, and with that, it reaches over 33 thousand characters.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2020 10:36 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/29 "2020-07-27T10:36:47Z")

</div>

At the end does it say it failed? If so then that corresponds to what I am seeing. It seems that it is not compatible with nodejs 12. I see that it has disappeared from github (as noted by @Steve-Mcl) so has he says this is probably a dead end.  
Looking at the device it seems that all you need to do is to measure the rate that the pulses are coming in, and the rate is fairly low, so you can probably do it quite simply in node-red.

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 10:39 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/30 "2020-07-27T10:39:19Z")

</div>

I have no idea how I can this kind of work without a package, or a node made by someone else. Yes, I just need the rate. If it is below a certain value, I will give a warning about it. Also, this value will be used with your PID node, to control a water pump. Can you help me get the flow rate?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2020 11:17 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/31 "2020-07-27T11:17:40Z")

</div>

Have you already worked out how to connect it to the Pi?  
After connecting it then you should be able to use a GPIO In node to see the pulses. Get that working first.

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 12:31 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/32 "2020-07-27T12:31:38Z")

</div>

I was on lunch break. I shut the Pi down before I left. Now, I got this on the Node-Red Terminal:

```auto
Start Node-RED
 
Once Node-RED has started, point a browser at http://192.168.1.2:1880
On Pi Node-RED works better with the Firefox or Chrome browser
 
Use node-red-stop to stop Node-RED
Use node-red-start to start Node-RED again
Use node-red-log to view the recent log output
Use sudo systemctl enable nodered.service to autostart Node-RED at every boot
Use sudo systemctl disable nodered.service to disable autostart on boot
 
To find more nodes and example flows - go to http://flows.nodered.org
 
Starting as a systemd service.
Error loading settings file: /home/pi/.node-red/settings.js
nodered.service: Succeeded.

```

This was filled with more errors and lines before I shut it down. Now, only this.

I am going to connect the sensor in a few minutes.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2020 12:41 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/33 "2020-07-27T12:41:49Z")

</div>

It is no use proceeding while still getting the setttings error. If you want to do it without the node then remove it and take your mod out of settings.js  
`npm remove water-flow-sensor`

How are you connecting it? I see that it has a 5V output so you can't connect that direct to the GPIO pin without at least a voltage divider.

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 12:56 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/34 "2020-07-27T12:56:48Z")

</div>

I have a setup ready for that. I'll delete the node. Deleted the line in settings.js too.

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 13:25 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/35 "2020-07-27T13:25:41Z")

</div>

I connected it and saw 0 and 1 values keep changing rapidly as I blow into it the sensor. What can I do with this knowledge? Somehow capture the time it changes and make some calculations from that?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [27 July 2020 13:29 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/36 "2020-07-27T13:29:17Z")

</div>

plenty of examples on that...  
[https://flows.nodered.org/search?term=counter](https://flows.nodered.org/search?term=counter)

you should be able to adapt one of these flows / nodes to achieve a pulse count

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2020 13:33 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/37 "2020-07-27T13:33:52Z")

</div>

This one might do the job, I have not used it but it appears you could configure it to give you a total count of messages every 5 seconds (or whatever) which you can then use to get the flow rate. Don't forget you will get two messages for each pulse (1 and 0) so you will get twice the message rate you would get if you were counting pulses. The datasheet tells you the flow for each pulse I think.

> **[node-red-contrib-timed-counter](https://flows.nodered.org/node/node-red-contrib-timed-counter)**
>
> A Node-RED node that counts messages received in a specified time limit

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 13:38 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/38 "2020-07-27T13:38:49Z")

</div>

Another question. I wrote a function to compare temperature values. This function was connected to a trigger, and trigger was connected to a button. I learned that this part must be running at all times, without the button press. So, I put a timestamp before it. Now, I sometimes read values like these:

```auto
{ payload: 1595856943673, topic: "", _msgid: "661b8566.10c17c" }
7/27/2020, 4:35:47 PMnode: 7be3371.28d15c8
msg : Object
{ payload: 29, topic: "", _msgid: "8dfcb019.41d8a" }
7/27/2020, 4:35:51 PMnode: 7be3371.28d15c8
msg : Object
{ payload: 29, topic: "",

```

Now, it kept repeating reading that huge value for 10+ times. This is making the system use PID in a wrong way. How can I solve this? Should I just add a if statement where the value is below 50 or something, or is there a better way to run something all the time without any interaction from the user?

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [27 July 2020 13:40 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/39 "2020-07-27T13:40:26Z")

</div>

this is off topic & not enough detail to solve - you should start a new thread with appropriate title so others familiar with your issue can assist.

---

<div class="post-metadata">

### Author: ![oncdastan](https://avatars.discourse-cdn.com/v4/letter/o/34f0e0/32.png) [@oncdastan](https://discourse.nodered.org/u/oncdastan)
#### Post date: [27 July 2020 13:45 UTC](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587/40 "2020-07-27T13:45:22Z")

</div>

I read stuff like this when I debug msg.topic:

```auto
msg : string[24]
"Creating handler for all"
7/27/2020, 4:44:39 PMnode: 719343f1.236b2c
pi/37 : msg.topic : string[5]
"pi/37"
7/27/2020, 4:44:40 PMnode: 719343f1.236b2c
pi/37 : msg.topic : string[5]
"pi/37"

```

Edit: I checked msg.count, now I can see it.

[Previous page](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587.md?page=1)

[Next page](https://discourse.nodered.org/t/yf-s201-water-flow-sensor-help-with-require/30587.md?page=3)
