# Time Delay For Pulse Trigger Digital Output

**URL:** <https://discourse.nodered.org/t/time-delay-for-pulse-trigger-digital-output/3317>\
**Category:** General\
**Created:** [21 September 2018 05:46 UTC](https://discourse.nodered.org/t/time-delay-for-pulse-trigger-digital-output/3317 "2018-09-21T05:46:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrizkywiguna](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrizkywiguna/32/32016_2.png) [@mrizkywiguna](https://discourse.nodered.org/u/mrizkywiguna)\
**Post date:** [21 September 2018 05:46 UTC](https://discourse.nodered.org/t/time-delay-for-pulse-trigger-digital-output/3317/1 "2018-09-21T05:46:55Z")

</div>

Hi All,

I'm stuck in delay function for pulse delay signal High and Low. I've tried trigger node, but i cant control the low signal time. So, i want control relay with specific time in high position and low position.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/5af32cb8669b4260e3ccc74912beba2d3cd938d2.png)

`[{"id":"b906ff4d.da3d3","type":"ui_chart","z":"c5964b54.39bb98","name":"","group":"6a67f261.dd3924","order":0,"width":"0","height":"0","label":"Pressure Intake Real","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"4","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":853.0000076293945,"y":269.3333692550659,"wires":[[],[]]},{"id":"7c278af4.03c094","type":"comment","z":"c5964b54.39bb98","name":"0 = ON ; 1=OFF","info":"","x":843.3333740234375,"y":435,"wires":[]},{"id":"1c939f07.8abe49","type":"modbus-read","z":"c5964b54.39bb98","name":"pi","topic":"pi","showStatusActivities":false,"showErrors":false,"unitid":"6","dataType":"InputRegister","adr":"200","quantity":"1","rate":"1000","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"7a22729d.02c024","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":175,"y":348.3333435058594,"wires":[["2e941233.01da86"],["1c33c696.aad3a1"]]},{"id":"1c33c696.aad3a1","type":"modbus-response","z":"c5964b54.39bb98","name":"","registerShowMax":20,"x":415,"y":368.3333435058594,"wires":[]},{"id":"73f55646.e7ef5","type":"rpi-gpio out","z":"c5964b54.39bb98","name":"","pin":"13","set":true,"level":"1","freq":"","out":"out","x":906.3331909179688,"y":662.6666564941406,"wires":[]},{"id":"625f1c8.b974364","type":"ui_text","z":"c5964b54.39bb98","group":"ddeba1c2.c1e0f8","order":0,"width":0,"height":0,"name":"","label":"Pi Real","format":"{{msg.payload}} ","layout":"col-center","x":785,"y":308.3333435058594,"wires":[]},{"id":"33b030d8.49a7d","type":"modbus-response","z":"c5964b54.39bb98","name":"","registerShowMax":20,"x":423.00000762939453,"y":129.33336925506592,"wires":[]},{"id":"322d854c.ff7b72","type":"function","z":"c5964b54.39bb98","name":"Global Variable Declare","func":"global.set(\"pi\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":583.0000076293945,"y":309.3333692550659,"wires":[["625f1c8.b974364","b906ff4d.da3d3","8f82dc90.12a7b"]]},{"id":"89f08e22.6a6ff","type":"modbus-read","z":"c5964b54.39bb98","name":"setpoint","topic":"setpoint","showStatusActivities":false,"showErrors":false,"unitid":"6","dataType":"InputRegister","adr":"130","quantity":"1","rate":"1000","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"7a22729d.02c024","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":175,"y":188.33334350585938,"wires":[["33b030d8.49a7d","46c08db1.a80524"],[]]},{"id":"ab7216fd.84514","type":"function","z":"c5964b54.39bb98","name":"Global Variable Declare","func":"global.set(\"setpoint\",msg.payload);\nreturn msg;\n","outputs":1,"noerr":0,"x":663.0000076293945,"y":189.33336925506592,"wires":[["30e01438.d23794"]]},{"id":"30e01438.d23794","type":"ui_text","z":"c5964b54.39bb98","group":"ddeba1c2.c1e0f8","order":0,"width":0,"height":0,"name":"","label":"Pi Setpoint","format":"{{msg.payload}} ","layout":"col-center","x":863.0000076293945,"y":189.33336925506592,"wires":[]},{"id":"4088fa7.8d1d784","type":"function","z":"c5964b54.39bb98","name":"Raise","func":"var setpoint = global.get(\"setpoint\");\nvar pi=global.get(\"pi\");\n\nif (setpoint > pi)\n{\n return {payload: \"1\"}\n} \n\nelse {\n return {payload: \"0\"}\n}\n\n\n\n","outputs":1,"noerr":0,"x":375,"y":528.3333435058594,"wires":[["7dfda5ad.862a7c"]]},{"id":"b104f6eb.96e69","type":"inject","z":"c5964b54.39bb98","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":195,"y":528.3333435058594,"wires":[["4088fa7.8d1d784"]]},{"id":"7dfda5ad.862a7c","type":"rpi-gpio out","z":"c5964b54.39bb98","name":"","pin":"11","set":true,"level":"1","freq":"","out":"out","x":804.6666259765625,"y":526.0000610351562,"wires":[]},{"id":"5f54d5bb.79f7f4","type":"function","z":"c5964b54.39bb98","name":"Lower","func":"var setpoint = global.get(\"setpoint\");\nvar pi=global.get(\"pi\");\n\nif (setpoint < pi)\n{\n return {payload: \"0\"}\n} \n\nelse {\n return {payload: \"1\"}\n}\n\n\n","outputs":1,"noerr":0,"x":375,"y":668.3333435058594,"wires":[["3c67b48f.361f7c"]]},{"id":"cca7195e.51d7b","type":"inject","z":"c5964b54.39bb98","name":"","topic":"","payload":"","payloadType":"date","repeat":"0.095","crontab":"","once":false,"onceDelay":0.1,"x":195,"y":668.3333435058594,"wires":[["5f54d5bb.79f7f4"]]},{"id":"8e367b36.189f68","type":"comment","z":"c5964b54.39bb98","name":"Condition Setpoint Higher Than Real Value","info":"","x":273.00000762939453,"y":609.3333692550659,"wires":[]},{"id":"111878b3.d0ff97","type":"comment","z":"c5964b54.39bb98","name":"Condition Setpoint Lower Than Real Value","info":"","x":273.00000762939453,"y":469.3333692550659,"wires":[]},{"id":"a88cd6ad.683908","type":"comment","z":"c5964b54.39bb98","name":"Get Pi Modbus Data","info":"","x":215,"y":268.3333435058594,"wires":[]},{"id":"3cbe1437.d2e12c","type":"comment","z":"c5964b54.39bb98","name":"Get Setpoint Modbus Data","info":"","x":235,"y":88.33334350585938,"wires":[]},{"id":"2e941233.01da86","type":"function","z":"c5964b54.39bb98","name":"","func":"msg.payload=msg.payload/10;\nreturn msg;","outputs":1,"noerr":0,"x":235,"y":308.3333435058594,"wires":[["8823440d.bb5bb"]]},{"id":"8f82dc90.12a7b","type":"ui_gauge","z":"c5964b54.39bb98","name":"","group":"6a67f261.dd3924","order":0,"width":"0","height":"0","gtype":"gage","title":"PI Real","label":"Psi","format":"{{value}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":780,"y":346.3333435058594,"wires":[]},{"id":"3961e4f8.9e12a4","type":"ui_text","z":"c5964b54.39bb98","group":"523f1271.dae8dc","order":0,"width":0,"height":0,"name":"","label":"Set Point Pi","format":"{{msg.payload}}","layout":"row-spread","x":453.38885498046875,"y":938.4445190429688,"wires":[]},{"id":"53d90ff9.284838","type":"modbus-write","z":"c5964b54.39bb98","name":"","showStatusActivities":false,"showErrors":false,"unitid":"6","dataType":"HoldingRegister","adr":"130","quantity":"1","server":"7a22729d.02c024","x":435.3888397216797,"y":880.4444932937622,"wires":[[],["97206510.d28e9"]]},{"id":"97206510.d28e9","type":"modbus-response","z":"c5964b54.39bb98","name":"","registerShowMax":20,"x":660.3888549804688,"y":884.1112670898438,"wires":[]},{"id":"8823440d.bb5bb","type":"function","z":"c5964b54.39bb98","name":"","func":"msg.payload = msg.payload.toFixed(0);\nreturn msg;","outputs":1,"noerr":0,"x":383.00000762939453,"y":309.3333692550659,"wires":[["322d854c.ff7b72"]]},{"id":"46c08db1.a80524","type":"function","z":"c5964b54.39bb98","name":"","func":"msg.payload=msg.payload/1;\nreturn msg;","outputs":1,"noerr":0,"x":323.00000762939453,"y":189.33336925506592,"wires":[["c950d572.732178"]]},{"id":"c950d572.732178","type":"function","z":"c5964b54.39bb98","name":"","func":"msg.payload = msg.payload.toFixed(0);\nreturn msg;","outputs":1,"noerr":0,"x":443.00000762939453,"y":189.33336925506592,"wires":[["ab7216fd.84514"]]},{"id":"6a982d0.343fb54","type":"ui_text_input","z":"c5964b54.39bb98","name":"","label":"Set Pi","group":"523f1271.dae8dc","order":0,"width":0,"height":0,"passthru":true,"mode":"text","delay":"300","topic":"","x":102.99994659423828,"y":891.0000867843628,"wires":[["53d90ff9.284838","3961e4f8.9e12a4"]]},{"id":"19f386b9.bdcdd1","type":"inject","z":"c5964b54.39bb98","name":"","topic":"","payload":"100","payloadType":"str","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":135.83334350585938,"y":143.33334350585938,"wires":[["46c08db1.a80524"]]},{"id":"6a604045.cbf21","type":"inject","z":"c5964b54.39bb98","name":"","topic":"","payload":"10","payloadType":"str","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":142.22222900390625,"y":402.22222900390625,"wires":[["2e941233.01da86"]]},{"id":"3c67b48f.361f7c","type":"delay","z":"c5964b54.39bb98","name":"","pauseType":"delay","timeout":"0.095","timeoutUnits":"seconds","rate":"1","nbRateUnits":"0.1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":609.166748046875,"y":669.4443664550781,"wires":[["73f55646.e7ef5"]]},{"id":"f15a88f.6b73178","type":"inject","z":"c5964b54.39bb98","name":"","topic":"","payload":"0","payloadType":"str","repeat":"10","crontab":"","once":false,"onceDelay":0.1,"x":392.5000305175781,"y":711.6666259765625,"wires":[["a5bd8b10.0fd9a8"]]},{"id":"a5bd8b10.0fd9a8","type":"delay","z":"c5964b54.39bb98","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":598.888916015625,"y":710.5554504394531,"wires":[["73f55646.e7ef5"]]},{"id":"6a67f261.dd3924","type":"ui_group","z":"","name":"Chart Realtime","tab":"178311c4.46912e","disp":true,"width":"6","collapse":false},{"id":"7a22729d.02c024","type":"modbus-client","z":"","name":"GDM Tipe B","clienttype":"simpleser","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"6","commandDelay":"1","clientTimeout":"1000","reconnectTimeout":"2000"},{"id":"ddeba1c2.c1e0f8","type":"ui_group","z":"","name":"Downhole Sensor Realtime Data","tab":"178311c4.46912e","disp":true,"width":"6","collapse":false},{"id":"523f1271.dae8dc","type":"ui_group","z":"","name":"Pressure Intake Real Time","tab":"178311c4.46912e","disp":true,"width":"6","collapse":false},{"id":"178311c4.46912e","type":"ui_tab","z":"","name":"Downhole Sensor","icon":"dashboard"}]`

Regards,  
wiguna

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [21 September 2018 06:25 UTC](https://discourse.nodered.org/t/time-delay-for-pulse-trigger-digital-output/3317/2 "2018-09-21T06:25:03Z")

</div>

here's a couple of examples to produce pulses of defined 1/0 times

the top one will produce a 1 for 3 secs and a 0 for 1 sec

the bottom one will produce a continuous train of pulses like that

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3fc03115a10b466385504b38ff86dfb48fcd8f03.png)

```
[{"id":"43eda91e.221358","type":"inject","z":"e4e1f6c6.d50648","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":180,"wires":[["6c4ea6e1.a2d528","474d7dbb.e90f64"]]},{"id":"6c4ea6e1.a2d528","type":"trigger","z":"e4e1f6c6.d50648","op1":"1","op2":"0","op1type":"num","op2type":"num","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":480,"y":160,"wires":[["d64ef6b.74d3908"]]},{"id":"474d7dbb.e90f64","type":"trigger","z":"e4e1f6c6.d50648","op1":"","op2":"finished","op1type":"nul","op2type":"str","duration":"4","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":480,"y":220,"wires":[["d64ef6b.74d3908"]]},{"id":"d64ef6b.74d3908","type":"debug","z":"e4e1f6c6.d50648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":180,"wires":[]},{"id":"cf90e92d.32c6a8","type":"inject","z":"e4e1f6c6.d50648","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":380,"wires":[["80fd4145.02be7"]]},{"id":"80fd4145.02be7","type":"trigger","z":"e4e1f6c6.d50648","op1":"1","op2":"0","op1type":"num","op2type":"num","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":620,"y":380,"wires":[["3e263cde.16c344","95500936.6dd878"]]},{"id":"3e263cde.16c344","type":"debug","z":"e4e1f6c6.d50648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":380,"wires":[]},{"id":"14cfbea5.9851f1","type":"delay","z":"e4e1f6c6.d50648","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":460,"wires":[["80fd4145.02be7"]]},{"id":"95500936.6dd878","type":"switch","z":"e4e1f6c6.d50648","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":730,"y":460,"wires":[["14cfbea5.9851f1"]]},{"id":"1bfc8878.37cde8","type":"inject","z":"e4e1f6c6.d50648","name":"reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":460,"wires":[["4b2947a2.e420f8"]]},{"id":"4b2947a2.e420f8","type":"change","z":"e4e1f6c6.d50648","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":460,"wires":[["80fd4145.02be7","14cfbea5.9851f1"]]}]
```

---

<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:** [21 September 2018 08:11 UTC](https://discourse.nodered.org/t/time-delay-for-pulse-trigger-digital-output/3317/3 "2018-09-21T08:11:11Z")

</div>

Errr. why not just use a repeating inject set for the overall period... and single trigger node ?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/5857146713938ed317081fd42d0f780fcf563c55.png)

```auto
[{"id":"fc1d822d.5bd83","type":"inject","z":"dfe4ec36.0a5a5","name":"4 secs","topic":"","payload":"1","payloadType":"num","repeat":"4","crontab":"","once":false,"onceDelay":0.1,"x":550,"y":580,"wires":[["ee6bdd03.70486"]]},{"id":"ee6bdd03.70486","type":"trigger","z":"dfe4ec36.0a5a5","op1":"1","op2":"0","op1type":"num","op2type":"num","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":700,"y":580,"wires":[["7c25a8e4.81d748"]]},{"id":"7c25a8e4.81d748","type":"debug","z":"dfe4ec36.0a5a5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","hideButton":false,"x":870,"y":580,"wires":[]}]

```

---

<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:** [21 September 2018 09:03 UTC](https://discourse.nodered.org/t/time-delay-for-pulse-trigger-digital-output/3317/4 "2018-09-21T09:03:15Z")

</div>

Safety time ⚡

I do like the simplicity of the solution of @dceejay🙂  
But for elementary safety reasons it should never used **directly** in real application with **real equipment**.

There should be some easy way option to stop the timer at any point of time  
If flow is running, the interruption of running timer should be avoided. (inject node allows re-trigger with button)

Safety first 🙂

---

<div class="post-metadata">

**Author:** ![mrizkywiguna](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrizkywiguna/32/32016_2.png) [@mrizkywiguna](https://discourse.nodered.org/u/mrizkywiguna)\
**Post date:** [21 September 2018 14:12 UTC](https://discourse.nodered.org/t/time-delay-for-pulse-trigger-digital-output/3317/5 "2018-09-21T14:12:01Z")

</div>

Hi All,

Thank you for all advice. Now i can make the time for high and low. This signal using to rise/lower frequency variable speed drive, so there is need to setup specific time to make the drive working fine. The minimum length of time for change the frequency is 0.1 ms for trigger and 10 s to make up & down frequency very slow.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/34b7618ee4659e9ffceab84dab7ca07d96dc5cb2.png)

> [@](#):
>
> [{"id":"ba4e00e6.0f922","type":"rpi-gpio out","z":"c5964b54.39bb98","name":"","pin":"13","set":false,"level":"1","freq":"","out":"out","x":858.3332443237305,"y":612.0833377838135,"wires":},{"id":"655cd2e0.eba1ac","type":"function","z":"c5964b54.39bb98","name":"Lower","func":"var setpoint = global.get("setpoint");\nvar pi=global.get("pi");\n\nif (setpoint \> pi)\n{\n return {payload: "1"}\n} \n\nelse {\n return {payload: "0"}\n}\n\n\n","outputs":1,"noerr":0,"x":327.0000534057617,"y":617.7500247955322,"wires":[["31265d1e.b2e7f2"]]},{"id":"c302717e.63c6a","type":"inject","z":"c5964b54.39bb98","name":"hold 10 s","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":false,"onceDelay":0.1,"x":147.00005340576172,"y":617.7500247955322,"wires":[["655cd2e0.eba1ac"]]},{"id":"31265d1e.b2e7f2","type":"delay","z":"c5964b54.39bb98","name":"low\_delay","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"0.1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":551.1668014526367,"y":618.861047744751,"wires":[["ba4e00e6.0f922"]]},{"id":"4d549952.2d5948","type":"delay","z":"c5964b54.39bb98","name":"high\_delay","pauseType":"delay","timeout":"0.1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":560.8889694213867,"y":659.972131729126,"wires":[["ba4e00e6.0f922"]]},{"id":"e14c866e.f75b88","type":"inject","z":"c5964b54.39bb98","name":"","topic":"","payload":"0","payloadType":"str","repeat":"0.1","crontab":"","once":false,"onceDelay":0.1,"x":344.50008392333984,"y":661.0833072662354,"wires":[["4d549952.2d5948"]]}]
