circuit to turn an LED off while button is pressed

I’m an absolute amateur when it comes to electronics, so this post is probably riddled with incorrect assumptions- I would appreciate being corrected where possible!

I’m trying to drive an LED+button ( https://www.amazon.com/EG-STARTS-Illuminated-Joystick-Raspberry/dp/B06Y29LBJ4/ ) from ~10ft away.

There are 4 pins available to me- the annode/cathode of the LED, and then the two pins of the button.

I’m reading the button from an arduino nano with an INPUT_PULLUP pin (aka, a built-in 20k pullup resistor), so the pin should go LOW when the button is pressed.

The LED is actually 2 small LEDs in parallel, preceded by a single 201 ohm resistor in series.

What I want to do is

  1. Not compromise the accuracy of the button input readings, and
  2. have the LED on when the button is unpressed, and off while the button is pressed.

Is there a simple way to only send 2 wires (pin input and gnd) down the 10ft? (It would also be fine to send a 3rd wire carrying 5v). I’ve attached a schematic, but like I said- I really have very little idea what I’m doing and would appreciate some correction. Given I’m on the totally wrong track, what is a more coherent way to do this?

You can do it with 3 wires but they need to be one GND (as you've drawn it), one from a digital OUTPUT pin to the LED and another from a digital pin (in INPUT_PULLUP mode) to the switch.

Steve

What I want to do is

  1. Not compromise the accuracy of the button input readings, and
  2. have the LED on when the button is unpressed, and off while the button is pressed.

If you press the button as wired, you'll short your 5V power supply.
You need to separate the button circuit from the led circuit.
Read the button and then turn on the led with an output,
or
Just move the button to across the led.
When you press the button you'll bypass the led and they won't
get any current and therefore will be off when it is pressed and
on when it is unpressed.

slipstick- so you're saying "just use independent circuits (except for shared ground) for the LED and the button, and just set the LED digitally"? That would work. I had assumed this would have been possible without any microcontrollers, but if not, I guess i'll move forward knowing that.

raschemmel- "I'd short my 5v power supply with this setup when the button is pressed"- if that's true, then I really misunderstand pullup resistors (a very likely possibility!). If you take out the 2 LEDs and the resistor (that whole parallel branch) from the drawn circuit, isn't that the exact recommended use for INPUT_PULLUP pins? (ie, attach the pin to one end of the switch, and the other end to GND). The mini-schematic behind the "INPUT_PULLUP" line as drawn reflects my understanding of what it means to be an "INPUT_PULLUP"-configured pin. Is that incorrect?

By "move the button across the LED", that would certainly seem to create the correct button/LED relationship (pushed = off, not pushed = on). However, wouldn't that undermine the ability to digitalRead the IO pin? (I would expect it would read LOW regardless of whether the button is pressed). Also, if MY schematic shorts the 5v, wouldn't this as well?

I said put the button across the LEDS , not across the leds and the reisistor.
The resistor would still be in series with the button.

Your I/O is not going to read the button the way it is wired. It needs to be connected to the
leds , on the other side of the resistor. This is not a conventional way to read a button.
Usually it is separate and read separate from the led. (as suggested by Slipstick)
If the I/O is moved to the point between the resistor and the leds, it will be high when the
button is not pressed and low when it is pressed. Right now your I/O will read 5V when
the button is not pressed and the 5V will be shorted to gnd when it is pressed.

The normal way to read a button is have it short the pulled up I/O to ground.
(when unpressed the I/O is high. When pressed the pullup resistor is shorted to ground.)

Also, your pullup resistor is in the wrong place. It is in series with the I/O.
It should be BETWEEN the 5V and the I/O so when the I/O is pulled low it is low and when
not it is high. Did you google "arduino read button " ?
Either move it so it is between the circuit and 5V or move the circuit so it is between I/O and
the pullup resistor.

OP’s image:

FYI

FYI, example of Switch/LED on the same pin.
A-F go to Arduino I/O pin

@ 20 feet you may damage you I/O pin. ???

FYI, example of Switch/LED on the same pin

The buttons would have to be N.C. because the op want the led OFF when pressed. (Sorry Larry)

Thanks all for the information! It's clear I have a lot to learn, and this has given me a few things to think about...

raschemmel- I now see that you're right about the placement of the pullup resistor. But that goes against my (clearly wrong) intuition: why is it that, when the button is pressed, the current "prefers" to go to "ground" as opposed to an "input pin"? Is there some natural "resistance" on the path to input pins that is greater than that of the path to GND? (I had always assumed I should treat input pins as sinks? I realize there's a good chance I've got some fundamentals screwed up here...)

larryd (or others)- 20ft is enough to potentially screw up an input pin? is there anything I can do to mitigate that?

thanks for all your help!

I now see that you're right about the placement of the pullup resistor. But that goes against my (clearly wrong) intuition: why is it that, when the button is pressed, the current "prefers" to go to "ground" as opposed to an "input pin"? Is there some natural "resistance" on the path to input pins that is greater than that of the path to GND? (I had always assumed I should treat input pins as sinks? I realize there's a good chance I've got some fundamentals screwed up here...)

If you had the fundamentals correct I doubt you would be posting for this.

First of all, I/O pins are high impedance when configured as input pins. The input impedance is in the
order of 10 Mohms, so the path of least when the button is pressed is to ground, because there is
no resistance vs the 20k pullup resistor. When the button is not pressed the current flows from 5V,
through the pullup resistor, into the input and through the mcu chip to ground.

"sink" is a term used to descrbe OUTPUTS",
not inputs.

When you have an I/O pin, you need to establish some 'stable' 'known' initial state.
You can choose to make that high or low , it doesn't matter.

For this example , there is no need to discuss current, since we are only interested in voltage (H or L)
If you choose High as your initial state by connecting a pullup instead of a pulldown, then your
initial state is HIGH. That means that your device, button , switch or whatever is an 'active low' device
because when you press it, you pull the I/O pin Low.
This is why your button/led circuit needs to be connected to a pulled up I/O because when you press the
button you are shorting the led series current resistor to ground and thus the I/O to ground, which
is why the button needs to go across the leds. If you put it across the leds and the resistor you would
be back to your original problem of shorting the 5V to ground when you press it.
The pullup keeps the I/O high until the button is pressed.

raschemmel:
The buttons would have to be N.C. because the op want the led OFF when pressed. (Sorry Larry)

That can be done/inverted in a sketch with that same circuit.

i.e. without connecting the circuit to the Arduino, you are correct, a switch push turns ‘ON’ the LED.

However, that can be inverted in a sketch so pushing the switch turns ‘OFF’ the LED ;).

You win
(I just needed another post count.)