Do I need a resistor between output and input?

Sorry for a noob question here. So I have a chain like this:
OUTPUT_PIN -> BUTTON -> LED -> R -> INPUT_PULLUP_PIN

The question is do I need R here? Do I need it if there's no LED, or there's a DIODE instead of the LED? If I don't need it, what are the benefits in having it. Will it be more power efficient?

What are you trying to do? Outputs and inputs are normally separate things.

I'm trying to do charlieplexing, to read 6 buttons (any combination) with 3 pins. The approach is somewhat similar to scanning. For every pin as output, read from 2 other pins as inputs, then analize the combinations. It all works fine, but i've added a 1k resistor to every pin just in case, and now I want to clean up the design and wondering what will happen if I remove the resistors :slight_smile:

Charlieplexing makes no sense with buttons, unless you put a diode in series with each switch.

Normally switches are put in a matrix, which makes sense.

No need for any resistors.

// Per.

Zapro:
No need for any resistors.

That implies that I can just short circuit output to input_pullup, do I understand this correctly?

yglukhov:
That implies that I can just short circuit output to input_pullup, do I understand this correctly?

Indeed you can, but you do have to be very cautious in the code, that you do not allow the possibility of a LOW output being connected to a HIGH output.

So your idea of a 1k series resistor to each Arduino pin is indeed safe, as this is entirely protective (for voltages between ground and your 5 V Vcc) but small compared to the effective resistance of the internal pull-up.

With three pins, there are exactly three pairs of pins that a switch can connect, but two switches can be connected with diodes in this arrangement between each pair of pins:

So you can detect six switches, but not multiple simultaneous switch presses.

Makes sense. Thanks @Paul__B, @Zapro.