# How to use push button to toggle Led in raspberry pi?

**URL:** <https://discourse.nodered.org/t/how-to-use-push-button-to-toggle-led-in-raspberry-pi/51444>\
**Category:** General\
**Created:** [23 September 2021 15:00 UTC](https://discourse.nodered.org/t/how-to-use-push-button-to-toggle-led-in-raspberry-pi/51444 "2021-09-23T15:00:33Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [23 September 2021 21:21 UTC](https://discourse.nodered.org/t/how-to-use-push-button-to-toggle-led-in-raspberry-pi/51444/3 "2021-09-23T21:21:09Z")

</div>

> [@JasonV](#):
>
> But my intention that I very much would like to do is to turn on and off the LED light by PRESSING the button instead of releasing.

Near as I can tell, Node-Red's `ui_button` **only**"triggers" on release - as I discovered when working on this topic...

> [@Can ui-button respond to double-click](https://discourse.nodered.org/t/can-ui-button-respond-to-double-click/50783/6):
>
> Actually, it doesn't trigger on the "press", rather it triggers on the "release"... strange that I never noted that before. It clearly detects the press visually, so why not trigger on both?

However there are some solutions - such as creating your own button ...

> [@Press button state](https://discourse.nodered.org/t/press-button-state/50817/2):
>
> Hello Ali .. you could use the ui\_template node and take advantage of javascripts mousedown and mouseup eventlisteners on the button. Example Flow [{"id":"81fc920712f2501c","type":"ui\_template","z":"4895ea10b4ee9ead","group":"e68f0343d6bbfce5","name":"","order":0,"width":0,"height":0,"format":"\<button id=\"myBtn\"\>Click Me\</button\>\n\n\<script\>\n(function(scope) {\n\nlet myBtn = document.getElementById('myBtn')\n\nmyBtn.addEventListener('mousedown', e =\> {\nscope.send({payload: 1})\n});\n\nmyB…

---

_[View the full topic](https://discourse.nodered.org/t/how-to-use-push-button-to-toggle-led-in-raspberry-pi/51444)._
