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

Hello my name is Jason,

I have a question about how to set a push button as on/off function.
I already started to construct a push button which functions quite nicely as long as I push and release the button. It then changes from 1 to 0. 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.

Kind regards,


Is it a physical button connected to a GPIO or a Node-RED dashboard button?

Can you paste a picture of your flow?

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

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

Hi Jason,

Have a look at the node-red-contrib-toggle
It will do the job.

Dear Cymplecy

Yes it is a physical button connected to a GPIO of a raspberry pi( Ground -> GPIO 26) and a LED to the pins ( ground -> GIO 16)

When i push the button the state from the button change to 0 en the led turns off and when i release the button the state change back to 1

( when I press the push button )

( when I release the push button )

I would like that the LED stay on when the push button is released and goes back out when I press again

Try this:


and then make sure that the topic of this:

is set to: toggle


I tried but then the led doesn't work anymore it just stays on

Settings Input

Toggle node

Add this before the Toggle node:


Edit it to look like this:


Thx !!!

this did the job

Or a basic change node :slight_smile:

No need for any JS :slight_smile:

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