0

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?

SamGibson
  • 17,231
  • 5
  • 37
  • 58
smeeb
  • 787
  • 3
  • 13
  • 32
  • 1
    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. – brhans Oct 03 '17 at 13:44
  • 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? – Tony Stewart EE75 Oct 03 '17 at 14:10
  • I've added the "debounce" tag - see here: [tag:debounce] - which is a topic you need to research. See previous questions with this tag, including [this](https://electronics.stackexchange.com/questions/6884/debouncing-buttons) old question, and many others. – SamGibson Oct 03 '17 at 15:34

1 Answers1

1

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.

Michel Keijzers
  • 13,867
  • 18
  • 69
  • 139
  • However, the GPIO might not be capable of driving the LED. Rule of thumb is 3 mA per GPIO. – Jeroen3 Oct 03 '17 at 14:09
  • 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! – smeeb Oct 03 '17 at 14:28
  • 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: https://programmingelectronics.com/tutorial-19-debouncing-a-button-with-arduino-old-version/ – Michel Keijzers Oct 03 '17 at 14:44
  • Ahhh, so the bouncing algorithm is something implemented at the software layer then? – smeeb Oct 03 '17 at 14:52
  • Yes, maybe there also buttons which have it implemented in hardware, but it might be costlier ... most do it in software, also easier to adapt to your preferences. – Michel Keijzers Oct 03 '17 at 14:54
  • 1
    @Michel - The techniques / algorithms needed are called **de**bouncing, 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. :-) – SamGibson Oct 03 '17 at 15:23
  • 1
    @SamGibson completely true ... thanks for the comment and I updated my answer. – Michel Keijzers Oct 03 '17 at 15:27