# Counting Pulses from an RPM Sensor

**URL:** https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918
**Category:** General
**Created:** [10 January 2021 18:58 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918 "2021-01-10T18:58:22Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Marty\_B](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty_b/32/30269_2.png) [@Marty\_B](https://discourse.nodered.org/u/Marty_B)
#### Post date: [10 January 2021 18:58 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/1 "2021-01-10T18:58:22Z")

</div>

Hi All,  
I am considering connecting a raspberry PI 3B+ to a gate controller's RPM sensor. This sensor outputs a square wave at about 100 Hz at its maximum speed. My question is, how can I count these using node-red?

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [10 January 2021 20:05 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/2 "2021-01-10T20:05:58Z")

</div>

You will need the `GPIO` node and set a pin as an input.

When the pin sees something change at its input it makes a message.

I'm not saying this will work, but....

Then install this guy: [A handy node.](https://flows.nodered.org/node/node-red-contrib-msg-speed)

Take its output and see what you get.

---

<div class="post-metadata">

### Author: ![Marty\_B](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty_b/32/30269_2.png) [@Marty\_B](https://discourse.nodered.org/u/Marty_B)
#### Post date: [10 January 2021 22:06 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/3 "2021-01-10T22:06:47Z")

</div>

Thanks. That node might be useful. My goal is to count the pulses, then determine the position of the gate by the pulse count. I guess my main question is, can node red see and count pulses at a GPIO pin at 100 Hz without missing pulses? I know that a Raspberry Pi can see pulses at a much faster rate, but not sure about node red.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [10 January 2021 23:04 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/4 "2021-01-10T23:04:35Z")

</div>

I suspect that may be pushing it. You would probably be better to either run a dedicated app in a separate thread that reported back to Node-RED or use dedicated hardware like an esp chip that runs more realtime and report via network or serial etc..

Worth a try though, may work on the faster pi

---

<div class="post-metadata">

### Author: ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)
#### Post date: [11 January 2021 00:30 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/5 "2021-01-11T00:30:23Z")

</div>

Why not put the logic in the Pi to count the pulses and have it report the controller's position to NR? You don't say what position(s) you are interested in but it seems to me that you could count/calculate the number of pulses between each and report those positions.

---

<div class="post-metadata">

### Author: ![Marty\_B](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty_b/32/30269_2.png) [@Marty\_B](https://discourse.nodered.org/u/Marty_B)
#### Post date: [11 January 2021 01:10 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/6 "2021-01-11T01:10:58Z")

</div>

I was hoping do everything in node-red if possible. I have limited experience in Python and am not sure how I would interface the python script to node-red. Its starting to look like it might be the best way.

---

<div class="post-metadata">

### Author: ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)
#### Post date: [11 January 2021 01:20 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/7 "2021-01-11T01:20:15Z")

</div>

> [@Marty\_B](#):
>
> I have limited experience in Python

Are you saying that is the only language you have experience with? Or that you think it's the only option on the Rpi? You can actually use any language on the Rpi.

> [@Marty\_B](#):
>
> not sure how I would interface the python script to node-red.

I personally use shell scripts to publish to an MQTT broker and then I subscribe to those topics with the MQTT nodes in NR. My needs in this area are simple and the scripts are only a few lines. YMMV

---

<div class="post-metadata">

### Author: ![Marty\_B](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty_b/32/30269_2.png) [@Marty\_B](https://discourse.nodered.org/u/Marty_B)
#### Post date: [11 January 2021 01:38 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/8 "2021-01-11T01:38:51Z")

</div>

I am not a professional programmer. I don't know what MQTT is. I don't know what YMMV is. I have some C++ experience from many years ago. I have written a few python scripts. I am using node-red to avoid programming. That's what I thought it was for. Thanks for the help. 🙂

---

<div class="post-metadata">

### Author: ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)
#### Post date: [11 January 2021 02:09 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/9 "2021-01-11T02:09:32Z")

</div>

> [@Marty\_B](#):
>
> MQTT

It's a publish/subscribe messaging system. Quite simple actually and widely used in both home and industrial environments. I don't want to overload you so I'll leave it at that.

> [@Marty\_B](#):
>
> YMMV

Your Mileage May Vary 😉

---

<div class="post-metadata">

### Author: ![Marty\_B](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty_b/32/30269_2.png) [@Marty\_B](https://discourse.nodered.org/u/Marty_B)
#### Post date: [11 January 2021 02:39 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/10 "2021-01-11T02:39:21Z")

</div>

Thanks, I have some reading to do. And I am not a complete dumbass, really. 😊

---

<div class="post-metadata">

### Author: ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)
#### Post date: [11 January 2021 04:37 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/11 "2021-01-11T04:37:50Z")

</div>

> [@Marty\_B](#):
>
> complete dumbass

Certainly not! You asked the question...a fool would not.

---

<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: [11 January 2021 08:07 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/12 "2021-01-11T08:07:54Z")

</div>

Marty, I see this a lot - folk shying away from MQTT because they "dont know it".

It is super simple and most definitely worth taking 5 minites to have a play. Seriously, if you have any knowledge of computers and programming, you will pretty much grasp the basics of MQTT in 5 minutes.

check out [this post](https://discourse.nodered.org/t/linking-2-or-more-instances-on-a-local-network/24879/3) I did for someone else.

Once you have the basic understanding of publish (sending something) and subscribe (receiving something), it is worth reading up on MQTT to understand the finer points (like topic naming conventions etc) but I just want to say, dont shy away - it really is very very simple to utilise.

---

<div class="post-metadata">

### Author: ![Marty\_B](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty_b/32/30269_2.png) [@Marty\_B](https://discourse.nodered.org/u/Marty_B)
#### Post date: [11 January 2021 15:56 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/13 "2021-01-11T15:56:43Z")

</div>

Thanks guys. I will give it a look. Thanks again for your help.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [12 March 2021 15:56 UTC](https://discourse.nodered.org/t/counting-pulses-from-an-rpm-sensor/38918/14 "2021-03-12T15:56:44Z")

</div>

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