Illuminated LED and push-button using only 2 wires

I want to make a circuit with an illuminated LED push-button that is far away from the input board and I only have 2 wires available. The push-button is not something specific. The input board will have many buttons, but not all buttons will have LEDs. The input board will probably be a MCP23017 16-bit expander with an MCU.

I came up with this circuit:

simulate this circuit – Schematic created using CircuitLab

The MCP23017 is powered with 5V.

When the push-button is not pressed, the voltage at the MCP input pin is about 1V, low enough to register a 0 on the digital input.

When the push-button is pressed, the voltage is 5.6V without the added 5.1V zener diode D3, and 5 volts with the zener in place - well above 0.8 * 5V VDD required by MCP23017. But because the circuit is just a voltage divider 220+220 ohm resistors over the 12V supply, it will draw ~28mA, resulting in a bit of heat from the resistors. Because the push-buttons will not be pressed for more than a few seconds, I can live with this.

D2 LED was actually an opto-coupler to separate the long wire from the digital input, but I gave up on this protection for now.

I searched a lot on the internet for other ideas about how to power an LED and have a button using only 2 wires and no complex circuitry, but could not find any relevant info.

I built this circuit and it works, but one thing I cannot test is the influence of mains wires that run alongside my long button wires. They are separated and individually protected, but parallel to each other.

Do you have any other suggestions on how to use a button and an LED on 2 wires?

Later edit:

The buttons can only be normally open. They are European type light push buttons available only NO. LED is added by me. Led should be lit all the time when the push-button is open. When the button closes there is no problem if the led tuns off or remains on. In this particular case, the led is used for night time finding only.

One other idea I had recently was to use input-output feature of the IO expander chip. Using the output to turn on the led, and then switch to input to check for the push-button state. Doing this fast enough not to see a flicker. But I haven't drawn any circuit yet.

• Are the buttons normally-open (NO) only. It would be dead easy with NC contacts. Do you have a datasheet link for the button? LED should be normally lit? LED can go out when button pressed? (Put all the info into the question rather than in the comments.) – Transistor Dec 4 '19 at 16:58
• Alex, I'm a little confused about something you wrote. You mentioned that these are "euro-type light push buttons" but you also mention that the "LED is added by me." If the euro-style PB types are already lighted, they probably have an LED or other kind of light already built into them. If you had to add an LED, you'd either have to modify the PB mechanicals or else install the LED separately to light up the button. If there is already a light in the PB, I'd prefer to see what they put inside... not what you want to add, now. But I'm confused. So perhaps you could clarify? – jonk Dec 4 '19 at 21:03
• jonk, PB are single-throw single-pole mechanical switch designed for mains (230V AC) light control or doorbell for example, no ilumination by default. My added LED illumination does not modify the hardware button. – AlexV Dec 5 '19 at 18:42

If you still want isolation, you just need a source of low-voltage AC power:

simulate this circuit – Schematic created using CircuitLab

Each switch controls the LED at the other end of the long 2-wire cable.

Either LED could be part of an optoisolator.

D2 and D4 are only necessary if the peak voltage out of the transformer exceeds the LED reverse voltage rating.

• Thanks, I will test this idea because it is much simpler to implement in software and uses less pins. – AlexV Dec 5 '19 at 20:31

simulate this circuit – Schematic created using CircuitLab

Figure 1. A simpler circuit using two GPIO pins.

How it works:

• IO2 toggles between high and low.
• IO1 toggles between input and output high.

Table 1.

State  Button  IO1       IO2     LED
1    Open    Out high  Out lo  ON
2    Open    Input     Out hi  Off   IO1 reads low due to pull-down R2.
3    Pressed Out high  Out lo  Off   LED shorted out.
4    Pressed Input     Out hi  Off   IO1 pulled high by IO2.

• Light the LED when IO1 is high and IO2 is low.
• Read the switch when IO2 is high and IO1 is input.