0
\$\begingroup\$

I'm looking for a momentary switch (like this one) that can be safely driven by the GPIO pins on a Raspberry Pi 1 Model A (hereafter RPi). This model of the RPi can sustain 3.3V and up to 16mA safely on its input pins.

The idea is that the switch will be open by default, but if a person is pushing down the momentary switch, it will send a signal to a GPIO input pin and reacted to at the software layer. The moment the person releases pressure on the switch, it opens again and stops sending the signal. Additionally it would be wonderful if the switch illuminates while it is being pressed.

Can a momentary switch like this be wired to safely work with this particular of RPI? If not, why? If so, what types of support devices (transistors, receivers, capacitors, etc.) would need to be put in place?

\$\endgroup\$
  • 1
    \$\begingroup\$ I'm confused. A switch is an input device. It sends a signal to your RPi. It is not driven by your RPi as there's nothing to be driven. \$\endgroup\$ – brhans Oct 3 '17 at 13:44
  • \$\begingroup\$ Why would you want a bouncing switch to enable GPIO without suitable debouncing? and careful wiring to support the speed of the signal and risetime? \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 Oct 3 '17 at 14:10
  • \$\begingroup\$ I've added the "debounce" tag - see here: debounce - which is a topic you need to research. See previous questions with this tag, including this old question, and many others. \$\endgroup\$ – SamGibson Oct 3 '17 at 15:34
1
\$\begingroup\$

I'm sure you can use it on your RPI.

Note the example you mentioned has no illumination. Probably there are switches with illumination.

In that case it needs multiple GPIO pins, probably one for the switch, and one for the LED (except from GND).

For a switch you don't need a resistor (probably you can use a pull up/down resistor within the RPI).

For the LED you have to calculate the resistor value, this depends on the voltage (3.3 V or 5 V, not sure what RPI uses), the forward voltage of the LED and how bright it should shine.

For the input you need to use a (siimple) debouncing algorithm.

Both GPIO pins can be controlled from the RPI (meaning: the input pin you can check for the value: LOW/HIGH), the pin for the LED can be set.

\$\endgroup\$
  • \$\begingroup\$ However, the GPIO might not be capable of driving the LED. Rule of thumb is 3 mA per GPIO. \$\endgroup\$ – Jeroen3 Oct 3 '17 at 14:09
  • \$\begingroup\$ Thanks @Michel Keijzers (+1) - I understand everything you said except the part about the "bouncing algorithm" ("For the input you need to use a (siimple) bouncing algorithm."). Can you elaborate on what you meant by that, I'm not familiar with it. Thanks again! \$\endgroup\$ – smeeb Oct 3 '17 at 14:28
  • \$\begingroup\$ If you press a button, it will give e.g. a HIGH, however, it will probably go back and forth several times ... the idea is to check the value for some time to see if it is stable, search for Arduino bouncing, for example: programmingelectronics.com/… \$\endgroup\$ – Michel Keijzers Oct 3 '17 at 14:44
  • 1
    \$\begingroup\$ @Michel - The techniques / algorithms needed are called debouncing, not bouncing :-) That's because mechanical switch contacts do bounce, and the effects of that want to be removed. Saying that someone wants a "bouncing algorithm" making it sound like you are adding additional contact bounce, which is the exact opposite of what is required here! I suggest that you change "bouncing" to "debouncing" in your answer text. :-) \$\endgroup\$ – SamGibson Oct 3 '17 at 15:23
  • 1
    \$\begingroup\$ @SamGibson completely true ... thanks for the comment and I updated my answer. \$\endgroup\$ – Michel Keijzers Oct 3 '17 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.