# Measure the Pulse duration of input Signal

**URL:** <https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894>\
**Category:** General\
**Created:** [12 March 2019 20:27 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894 "2019-03-12T20:27:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![drikos\_pag](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@drikos\_pag](https://discourse.nodered.org/u/drikos_pag)\
**Post date:** [12 March 2019 20:27 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/1 "2019-03-12T20:27:10Z")

</div>

Hello to Everybody,

I'm new in the Rode red community .

My setup is a raspberry pi 3 B+ with the automation hat shield.

Im trying to find a way to measure the pulse duration of an input signal.

I would like to know how many time an input stay High and to pass this data or directly to a dashboard.

Could anyone give me a help?

Regards

Andreas

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [12 March 2019 20:31 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/2 "2019-03-12T20:31:00Z")

</div>

Welcome to the forum! What lengths of time do you want to measure? Seconds, minutes etc.

---

<div class="post-metadata">

**Author:** ![drikos\_pag](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@drikos\_pag](https://discourse.nodered.org/u/drikos_pag)\
**Post date:** [12 March 2019 20:33 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/3 "2019-03-12T20:33:50Z")

</div>

Hey ghayne,

I would like to measure from seconds up to hours.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [12 March 2019 20:46 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/4 "2019-03-12T20:46:17Z")

</div>

this flow in the cookbook shows how to store a value to use in a different flow  
So you could save the time when your signal went high/low  
and then work out the time difference when it changes

[https://cookbook.nodered.org/basic/route-on-context](https://cookbook.nodered.org/basic/route-on-context)

---

<div class="post-metadata">

**Author:** ![drikos\_pag](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@drikos\_pag](https://discourse.nodered.org/u/drikos_pag)\
**Post date:** [12 March 2019 21:06 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/5 "2019-03-12T21:06:39Z")

</div>

Thank you ukmoose for your hint,

I have already checked this the important think is that I need a solution with real time results I mean when the input goes high to start a time counter.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [12 March 2019 21:27 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/6 "2019-03-12T21:27:03Z")

</div>

Don't forget that Node-Red is not a "Real time" system, the shorter the periods you want to measure the more inaccurate the results will be. If you want to measure short periods accurately you would be better off using an Arduino or ESP8266 dedicated to measuring the times and pass the results to node red for display and/or evaluation.

---

<div class="post-metadata">

**Author:** ![drikos\_pag](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@drikos\_pag](https://discourse.nodered.org/u/drikos_pag)\
**Post date:** [12 March 2019 21:29 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/7 "2019-03-12T21:29:36Z")

</div>

not I don't want to measure with accuracy the seconds, this input indicate the working time of a machine.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [12 March 2019 21:48 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/8 "2019-03-12T21:48:35Z")

</div>

you can detect when an input goes high. Getting the current time in a javascript function is a simple bit of javascript. Google will be your friend  
then store that as the context valie

---

<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:** [12 March 2019 22:21 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/9 "2019-03-12T22:21:32Z")

</div>

The node node-red-contrib-interval-length will measure the time between messages. Feed the state change messages to it and each time it switches it will tell you how long since it last changed.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [12 March 2019 22:23 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/10 "2019-03-12T22:23:10Z")

</div>

@colin,  
Indeed I developed that [node-red-contrib-interval-length](https://github.com/bartbutenaers/node-red-contrib-interval-length) node for this kind of use cases. Thanks for the advertisement 😉

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [12 March 2019 22:25 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/11 "2019-03-12T22:25:38Z")

</div>

I made a little flow for you to get you on the path of thinking how the things work here in Node-RED.  
[flows.json](https://discourse.nodered.org/uploads/short-url/o4xqmoev8dyG80OvNnkDiUOh6Dj.json) (3.0 KB)  
Explore it and ask a lot of questions. 🙂

---

<div class="post-metadata">

**Author:** ![drikos\_pag](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@drikos\_pag](https://discourse.nodered.org/u/drikos_pag)\
**Post date:** [13 March 2019 00:01 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/12 "2019-03-13T00:01:10Z")

</div>

Hey hotNipi,

Your flow help me a lot.

the thing is that I want to have in a dashboard a timer that will start to count the after the input goes high. and not to wait until the input goes low and calculate the difference.

has anyone any idea about that?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [13 March 2019 11:19 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/13 "2019-03-13T11:19:21Z")

</div>

Question should be have you any idea? 🙂  
I definitely have some ideas but I'd like to follow yours. Because of you are doing it and when it is ready, it will be your solution. The best one in the world. And we are happy to help you to achieve this.  
So start experiments and when you are stuck then you have specific questions about it. And we are happy to help on such.

To not let you empty handed right now, here is something you can think about to get the things moving again - In addition what you already have (a bit modifications of course needed) you should do something like this:

 ![pulseduration-display](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a0a63d7c7f6bdcdd30570599421599025c5fe1a2.jpeg)

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [13 March 2019 15:27 UTC](https://discourse.nodered.org/t/measure-the-pulse-duration-of-input-signal/8894/14 "2019-03-13T15:27:20Z")

</div>

> [@drikos\_pag](#):
>
> I want to have in a dashboard a timer that will start to count the after the input goes high. and not to wait until the input goes low and calculate the difference.

The `node-red-contrib-interval-length` node mentioned earlier (thanks @BartButenaers) can be made to do this, but it needs a bit of extra logic to work as a start/stop timer. This flow could get you started, although you might want to delay the reset message when stopping. One of the `debug` nodes is just to show the start and stop messages, and the other would be replaced by your dashboard node(s). The flow should work for multiple timers (topics), but I haven't checked.

```auto
[{"id":"2dd7f10a.e9a46e","type":"interval-length","z":"7de47013.a039d","format":"human","bytopic":false,"minimum":"","maximum":"","window":"","timeout":false,"msgTimeout":"2","minimumunit":"msecs","maximumunit":"msecs","windowunit":"msecs","msgTimeoutUnit":"secs","reset":true,"startup":false,"msgField":"payload","timestampField":"timestamp","repeatTimeout":true,"name":"","x":480,"y":400,"wires":[["df192dd9.00dd2"],["df192dd9.00dd2"]]},{"id":"85f43934.99e8d8","type":"inject","z":"7de47013.a039d","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":400,"wires":[["bbdf10aa.c2cb7"]]},{"id":"df192dd9.00dd2","type":"debug","z":"7de47013.a039d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":400,"wires":[]},{"id":"dc1a9f5.756276","type":"inject","z":"7de47013.a039d","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":460,"wires":[["6ceba346.52589c","2dd7f10a.e9a46e"]]},{"id":"6ceba346.52589c","type":"change","z":"7de47013.a039d","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":460,"wires":[["bbdf10aa.c2cb7"]]},{"id":"bbdf10aa.c2cb7","type":"rbe","z":"7de47013.a039d","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":270,"y":400,"wires":[["2dd7f10a.e9a46e","bcbca1c9.5b84b8"]]},{"id":"bcbca1c9.5b84b8","type":"debug","z":"7de47013.a039d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":470,"y":360,"wires":[]}]

```
