1

I have little to no background in electricity apart from a few YouTube tutorials I've watched, and I'm wondering if the following circuit would work: Circuit 1

Basically, I want a few switches to toggle their respective LEDs and be read as inputs on my Raspberry, without using extra Pins and extra code (as in toggling it when the button is pressed). I'm sorry if this question is trivial, I'm really new to this. What if the Voltage my LED needs is below the threshold for logical HIGH on the GPIOs?

Another thing I've found a lot on the internet is the following method of reading if a button is pressed: enter image description here I don't quite understand how this works (how does the current know "which way" to go, or does it simply go to GND and to the GPIOs).

2

Basically, I want a few switches to toggle their respective LEDs and be read as inputs on my Raspberry

The first schematic will not work if the GPIOs are set as inputs as there needs to be a path to ground, and an input cannot provide that (they are in a high impedance floating state). It will work if they are set as outputs set low (0V), but then of course you cannot detect when the button is pressed.

The second schematic is what you want.

I don't quite understand how this works (how does the current know "which way" to go, or does it simply go to GND and to the GPIOs).

Yes. More specifically, it will go to ground, but along the way it will affect the state of the high-Z floating input GPIOs.

WRT "floating": This is akin to a disconnected wire, except there is some clever circuitry involved to sense whether the disconnected wire is in fact connected to something with voltage. Going with a water analogy, if you have a dead end pipe connected to another pipe through which water flows, pressure will mean the water will likely fill the dead end pipe even though it cannot go anywhere (which is why it has "high impedance"). Hence a sensor in the dead end pipe can detect the pressure in the system overall.

If you are careful to make sure the GPIOs are never set as outputs driven low, you can do without R1 - R3 & R8.

  • Thanks for the quick response, so can I simply put the LED's after each resistor on each wire to GND? If so, do I need to use Ohm's law for each LED individually here, or do I need to calculate the resistance with the formula for parallel resistors? – Fabian Jun 30 '17 at 19:46
  • You can just use Ohm's law normally. The in-parallel formulas are for calculating total resistance and total current for the circuit, i.e., how much is potentially sunk from the singular voltage source. – goldilocks Jun 30 '17 at 19:54

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.