Measure the Pulse duration of input Signal

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?



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

Hey ghayne,

I would like to measure from seconds up to hours.

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

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.

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.

1 Like

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

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

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.

Indeed I developed that node-red-contrib-interval-length node for this kind of use cases. Thanks for the advertisement :wink:

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 (3.0 KB)
Explore it and ask a lot of questions. :slight_smile:

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?

Question should be have you any idea? :slight_smile:
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:

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.