Should be easy, but

Hi All,

I've been making progress with my gate opener, the interface is almost done and I'm getting into the pi itself. I have a button on my N-R dash that I want to use to make a 'short" on my pi. On the actual gate, this is done by shorting two low-volt contacts to make the motor run (could be anywhere from 12v to 3.3v). It's a momentary short and since there's no way to check the amp draw and/or volts, I'll use a relay. This is just for testing, the end result will be clicking a relay not an LED.

[{"id":"82c5c8e1.6687c","type":"ui_button","z":"c199b9b6.017a2","name":"button","group":"40f30843.03128","order":2,"width":2,"height":1,"passthru":false,"label":"OPERATE","tooltip":"","color":"black","bgcolor":"grey","icon":"","payload":"1","payloadType":"num","topic":"","x":570,"y":370,"wires":[["9faf751d.055c28"]]},{"id":"9faf751d.055c28","type":"rpi-gpio out","z":"c199b9b6.017a2","name":"pin 15","pin":"15","set":true,"level":"0","freq":"","out":"out","x":780,"y":370,"wires":[]},{"id":"40f30843.03128","type":"ui_group","z":"","name":"Button","tab":"81831aab.f2f568","order":4,"disp":false,"width":"6","collapse":false},{"id":"81831aab.f2f568","type":"ui_tab","z":"","name":"GTO-500 Gate Opener","icon":"dashboard","disabled":false,"hidden":false}]

So, my "button" node outputs to an "rpi gpio out" node. This node is configured to use pin 15 set to "digital output | intialize pin state | init to low". Pin 15 on the pi is wired to a breadboard grd bus with pin 17 to the hot. An LED resides between the two busses. Whenever I first deploy/reset the flow, the LED is lit but when I touch the button it goes out. From then on, the LED remains out no matter the state of the button. I've played with all the settings and nothing lights the LED other than initial deployment. What gives?



I'm not sure how long you have been here, but that's ok. I am not exactly an expert.

Reading what you said, it is a bit vague. Sorry.

If I am reading what you said correctly you want the button to make the GPIO pin go.... high.

I am worried with the pin numbers you give.

15 is GPIO 22
17 is 3.3 volts.


Though I am not sure you are talking PIN numbers as in from a software point of view or the physical numbers.

First thing: Which numbering system are you using?
Second: Use an OPTO ISOLATOR or a FET to do the switching.
Directly; BIG NO NO! Danger of destroying the I/O.
Relay: Hmmmm....... Maybe too much current needed. And flyback voltages.

Sorry? That doesn't make sense.

But back to what I said: USE AN OPTO-ISOLATOR! (Or FET)

I'm not even going to guess at what to the hot means.

Pin 17 is 3.3 volts. That is a power pin!

Between 15 and 17? That's not really going to do much other than frustrate you as the LED may be sometimes reverse biased.
Not good for the LED and it won't be good if you do hook up a relay as it works irrespective of which way the voltage is connected. So it will never release.

The flow you posted sends a signal to the GPIO pin and it remains in that condition.

Put another button and make one button set the GPIO high and the other one set it low.
Or put a trigger node in so it sends the high then a short time later sends a low signal.
Your choice

Of course you should also use pin 6, 25 or 39 as the other side/end. They are ground.

Unless you want to use inverse logic. Which may be better as the GPIO pins are better at sinking than sourcing power.

That means you make the GPIO pin go low when you want things to happen, and hight when you don't.

All that means is you use pin 17 (your friend from before) or pin 1.
But either way: also include a resistor!

Forget the breadboard and the story, when the button is pressed should the LED light? Even just a momentary blink? To clarify in simplicity: Why is pressing the button node (sending a "1") to pin 15 on the pi, NOT operating the LED? The anode of the LED goes to "hot" which is pin #17. So 3v3 from pin 17 to LED anode, cathode of LED back to pin 15. I have a relay panel that snaps onto the pi, but an opto may be a better device in the end. Far from that point right now...

I'll look into the trigger node. I got frustrated because every single Google search shows only using mechanical buttons, not a single search result showed any info on making a software button.

I do have one opinion, whatever idiot came up with multiple naming conventions for pi pins should be hung by the %#$&*s.

Have you ever had a gate opener? Garage door opener? They all use a momentary short across two terminals to start a "cycle". Once that cycle begins, it takes either one of the two limit stops, or user intervention to shut down that cycle.


How much do you know about electronics?

You are connecting the LED (with resistor) between a +3.3 volt power supply (pin 17) and a GPIO pin (pin 15)

Pin 17 is ALWAYS at 3.3 volts.
Pin 15 can be at either 0 volt/s or 3.3 volts.

If pin 15 is high (or as you call it: hot - cringe) and the LED is between 15 and 17 how do you expect the LED to glow?

You want to make 15 LOW and put the LED with the anode on 17, a small resistor (say 50 ohms) then connect it to 15.

Taking 15 LOW there will be a 3.3 volt difference; the LED is forward biased and it will glow.

How about you start with that and see what you can make.
If it glows only faintly, try a smaller resistor.
You may not need one, but you are risking damaging the RasPi if anything happens by mistake and you draw too much power from EITHER pin. The resistor limits how much power can go in/out of a pin and is there for the board's safety.

The trigger node is used because the button node sets the GPIO pin to a state and it is left at that state.

As there is no physical button on the screen to press, you can NOT have a momentary button.

The trigger node is used to achieve this.
It gets an input. It sends an output, and after a delay sends another output.
(Preferably different to the original.)

Then, you send ON to the trigger node and it sends "HIGH" (true, 1) to the GPIO pin.
Then after a couple of seconds it sends "LOW" (false,0).

This is back to front in the logic levels you need, so you set the tiger node:
send: false
after 2 seconds send: true

Connect that to the GPIO pin and it should work.

Ok, look at the GPIO node and see what it wants to send the GPIO pin high and low.
Do you now understand?

Oh, finally:
If the board is a plug on board for the RasPi, then there should be no problems.
Just use it. You didn't really say it was that in the first post, and I thought - stupid me - you may have been making it yourself.
(Argh.... But if it IS a plug in board, then the problems you are describing are..... weird. You plug it in, set up the GPIO pin to talk to the relay and send it a 1 or a 0 and the relay operates or releases. So 99% of what you are talking about wouldn't/shouldn't happen.)

Not to be too critical but I definitely would not recommend a 50 ohm resistor he needs a bigger one than that. 50 ohms will give him 66 mA which I believe is over the max for a pi pin. I'd suggest a 220 ohm or bigger. However, if he got the LED to light once with no resistor then the pin is probably fried already anyway. If he has a regular relay board built for the pi then that is OK but if he is going to roll his own solution then I would make sure there is an opto isolator on the pin for whatever solution he chooses. As @Trying_to_learn mentioned already there will be a significant reverse EMF over any relay so a clipper diode is a necessity. If you aren't well schooled in electronics rather than roll your own I would highly recommend you stick to ready made relay boards specifically designed for the pi pins, they should be engineered to handle all the nasties in the circuits and not overload the pi's pins.

1 Like

Actually I would maybe get one of those USB - relay boards.

Plug in in the USB port and you have relays.

For instance:

anything factory made, better for longevity and reliability

Thanks for the help (I think). Used to be a guy could come on here and get either help or answers without any derision concerning their lack of knowledge. Guess the board is changing more and more like the outside world, your either special - or not. I'll get it figured...


Hi - sorry for the "help" so far. Let's see if we can sort it out.

The main problem is that the dashboard button is not like a physical button in that it only sends one signal (the payload) - every time you press it you only get a press out... you never get a not pressed - whereas a physical button actually sends two... the make contact on press and break contact on release. - so to simulate that we need to use a trigger node that sends one value first then another a short time later. The duration can be up to you - but needs to be enough to activate your relay/led etc.

Then there is the logic - as you have found by wiring one side of the led to + then the other side should be low for on and high for off - so you need to set the trigger to send 0 at first to turn on the led, then a one shortly after to return to off. You should probably also set the gpio pin to default to 1 at start unless you want to activate whatever it is.

Finally protection - yes the others are trying to stop you blowing up your Pi pins - they can only supply about 20mA max - and LEDs have very little resistance so can easily blow an output if you are unlucky... but the calculation you need is good old ohms law... V=IR or rearranged as R = V/I . In this case the resistance we need is based on the difference between the supply (3.3V) and the forward voltage drop of the LED (typically 2.1V-ish) - so 1.2V and say a current of 10mA is usually enough to light an LED fairly brightly... so R = 1.2/0.01 = 120ohms or so. Obviously the calculation would differ for a relay - and indeed many of those relay boards online may have an opto-isolator built in which may or may not include the resistor (as they are effectively an led inside) so do check.

Thanks again, the trigger node did the trick! Ended up with a 330Ω resistor, and no damage done to the pi. I actually knew this at one time, but at age 67, find myself forgetting more than I learn...

[{"id":"82c5c8e1.6687c","type":"ui_button","z":"c199b9b6.017a2","name":"button","group":"40f30843.03128","order":2,"width":2,"height":1,"passthru":false,"label":"OPERATE","tooltip":"","color":"black","bgcolor":"grey","icon":"","payload":"1","payloadType":"num","topic":"","x":570,"y":370,"wires":[["cd455311.b7c26"]]},{"id":"9faf751d.055c28","type":"rpi-gpio out","z":"c199b9b6.017a2","name":"pin 15","pin":"15","set":true,"level":"1","freq":"","out":"out","x":850,"y":370,"wires":[]},{"id":"cd455311.b7c26","type":"trigger","z":"c199b9b6.017a2","name":"momentary","op1":"0","op2":"1","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":710,"y":370,"wires":[["9faf751d.055c28"]]},{"id":"40f30843.03128","type":"ui_group","z":"","name":"Button","tab":"81831aab.f2f568","order":4,"disp":false,"width":"6","collapse":false},{"id":"81831aab.f2f568","type":"ui_tab","z":"","name":"GTO-500 Gate Opener","icon":"dashboard","disabled":false,"hidden":false}]

Now I'm going to install a physical button on my breadboard to simulate one of the verification switches. One puzzler though. An LED requires a resistor, but a switch (dead short) does not?
Can this be right? Or is it because one can short an input but not an output? Just want to be sure I'm not gonna trash my pi...

Oh, and thanks for the explanation on the TWO inputs of a manual switch, it's often easy to overlook the obvious!


Right, for an input you may need a resistor to stop the input floating. But the pi can actually configure the input with an internal one so you don’t have to. So most people configure them with a pull up resistor and then wire the push button between the pi and ground. So it then pulls the pin low when you press and the resistor pulls it high when you let go.

You can short an input but you probably shouldnt. And @dceejay ís correct about configuring pull ups but you may want to do external ones as í have found the internal ones somewhat fussy and then you can pick the values as well.

I wrote this last month for one of my IoT students - it might be useful to you.
Although it's written for a Wemos D1 Mini it will also apply to to a Raspberry Pi.

One thing I try to avoid, when using a push-button, is connecting an input-pin directly to 0v or 3v3.

Here's a very rough diagram of an 'Active Low or Pull Down' circuit for a push-button and a microswitch.
When the push-button or the microswitch is in the inactive state (i.e. not pushed) there is no path to ground, so the two resistors pull the voltage at Dx (input to the Wemos) towards +3v3 or logic '1'.
When the push-button or microswitch is operated the junction-point of the two resistors is taken to ground, which will pull the voltage on Dx towards ground or logic '0'.

This circuit is also known as an 'Active Low' configuration as when your press the push-button or operate the microswitch, the input level to the Wemos changes from a logic '1' or a High to logic '0' or a Low.
i.e. It is Active Low when a push button is operated

The next diagram is of an 'Active High or Push Up or Pull Up' circuit.


When the push-button or the microswitch is in the inactive state (i.e. not pushed) there is no path to +3v3, so the two resistors pull the voltage at Dx (input to the Wemos) towards 0v or logic '0'. When the push-button or the microswitch is operated the junction-point of the two resistors is taken to +3v3, which will pull the voltage on Dx towards +3v3 or logic '1'.

This circuit is also known as an 'Active High' configuration as when your press the push-button or operate the microswitch, the input level to the Wemos changes from a logic '0' or a Low to logic '1' or a High.
i.e. It is Active High when a push button is operated

Which circuit you need to use depends on what you want to happen, in your computer program, when you press a button or operate a microswitch. If you want a logic '0' to be produced - then use Fig-1 or if you want a logic '1' to be generated - then use Fig-2.

The value of R is not critical. Any value between 470 ohms to 3K3 ohms should work fine.

You also need to remember to configure pin Dx as an 'input' within the sketch/program.


I would not advise using the circuit in Fig 2. It is generally better, or certainly more conventional, to take the 0v signal away to a button rather than taking the 3.3v signal off down a wire. In node red it is trivial to flip the 0/1 level round the other way if more convenient in the flows. Also remember that if you have multiple boards, with relays for example, then some of them will be 3.3v and some may be 5v, so care must be taken not to mix up the different supply lines, whereas all the 0v will be joined together.

Í would think the final mechanism would be the determining factor. But going to positive ör 1 for the output used to be the norm to activate. But then í bought á relay board that was active low. So í had to invert all my output logic. Either way works fine so determine your circuits and choose accordingly, Just remember if you let the smoke out of á circuit there´s no easy way to put it back in.
By the way both of @dynamicdave circuits look pretty good to me. Certainly á real good start

Hi Colin,
Thanks for your comment.
I agree it's more conventional to use a 'pull-down', I was just trying to show how both methods could be wired (and avoid connecting an input-pin directly to 0v or 3v3).

Appreciate the lowdown. My N-R dash button will need to momentarily short two terminals on the gate opener motherboard to start a cycle, the LED is just for function-testing purposes. I can either use a low-draw relay (I have a pi-compatible snap-on relay board) or an optocoupler as previously mentioned.

Another related Q. I need to input two verification signals to the pi from the gate MB, both share a common ground and each supplies 3v3 output. These work a bit differently, "gate open" sees voltage only when verified, "gate closed" is always hot EXCEPT when verified. So that pin can see voltage for (potentially) a much longer duration if that matters.


If you are verifying inputs the pi can certainly monitor pins, but be careful. I've fried more than one circuit thinking there was a common ground. Again, opto isolators are your friend. It's real easy to get current flowing down a ground plane and that causes all sorts of weird issues

One more thought, are the two devices close enough to wire or will you be using MQTT?

The pi will be inside the same enclosure as the gate MoBo so it all can be wired direct. :astonished: Uggh, I somehow "lost" my large breadboard and am having to use one the size of a pack of cigs to build several simulators on.