Switch between pinModes to save pins?

I have been working on a project that uses a lot of sensors, LEDs and other modules. However, due to limitations in size and budget, the only board I can use is Arduino Uno R3, meaning that the I/O pins are not enough.

In response to the issue, I came up with the idea to connect a button and LED in series to one pin (pin x) and switch between pinMode(x, INPUT) and pinMode(x, OUTPUT) when in need of controlling the LED or reading from the button.

I would like to know if it will cause any damage to my hardware (sensors, board, LEDs...), will it be feasible or are there better options to solve my problem.

Thanks in advance.

You only told us about one end of the two connections. What is connected to the other end of both the switch and the LED?

You may already know this, but the analog input Ax pins are digital pins too. If they're vacant, there's 6 more digital pins.

Other option is using port expanders, or bitshifters (personal favorite)

Post a design schematic of your project to see how we can help.

1 Like

Can you please post a list of your input devices and output devices with links to data/spec.

What is the application?

Thanks.. Tom.... :grinning: :+1: :coffee: :australia:

consider buying a 16 IP-pin port-expander input/or output



8 IO-pin output


endless status-information much more flexible than a LED

16x2 LCD

Amen to that. It should be a schematic of the proposed solution.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.