I’ve been struggling with this for a while now, and am no longer sure it’s actually possible.
I need to read a digital input on my Arduino. The button has a resistor and an LED in series indicating when the button is pressed. I can’t get this to work. The solutions I’ve tried either makes the LED very dim or fails to read the input correctly. (is it true that an LED will prevent pull down from working if placed in the wrong direction?)
Is this possible? I want the LED to be limited only by its dedicated resistor, and for the LED to light up and the digital input to read whatever when the button is pressed. No digital outputs.
You need to place a high value resistor across the LED, say 100k, that sort of value, otherwise
the LED will be extremely high impedance when off (gigaohms or more), and the pin is
effectively floating when the button isn't being pressed.
Connect the LED/resistor between pin and 5volt.
Connect the button between pin and ground.
Enable pull up on the pin in setup().
Now the pin is pulled up by the LED and the internal pull up of the chip,
And the pin and LED are pulled down by the switch.
Or to be precise the pin is pulled up by the internal pullup only, since the LED can't pull far enough
before it goes high-impedance, being the original issue. Probably.
Thanks! I went with the internal pullup. Had to resolder a bit more than I wanted, but at least it works now!