I'm a software guy trying to get my head around how to measure the status of a switch connected to a LED as shown below through a digital input of a MCU.
My first try was many variations of circuit 1 below - seems every iteration I've tried causes the LED to dimly light even when SW1 is open. I've eliminated R3 and this issue still exists. I believe R3 and the MCU input provides a path to ground causing the LED to dimly light.
I then stumbled upon circuit 2 below which seems to work well. I can read the status of SW1 and the LED works correctly. Unfortunately I don't know why it works and therefore don't feel comfortable with it.
Can anyone suggest methods to read the status of SW1 with a MCU without interfering with the LED? Also why does circuit 2 appear to work?
Thanks!
simulate this circuit – Schematic created using CircuitLab