How to connect a handful of switches – actually approx. 20 to Arduino Mega in an energy efficient way?
Some of the switches will be momentary ones some of them will be flip-switches (i.e. staying permanently closed or open until flipped again).
Specifically – I’m NOT looking for some CD74HC4067 multiplexer nor am I in the market for advice how to connect multiple (usually 4) switches to one analog pin and distinguish between them via different resistor value connected to each.
I want to have each switch a digital pin of their own. It is clear I must use pull-down or a pull-up resistor and that can be either internal or external one.
Some of the flip-switches will most likely be for most of the time closed while other opened throughout the lifetime of the project. The momentary ones (just as their name suggests) will be closed only from time to time for fragments of seconds.
Now how to connect them properly to be as nice to Arduino as possible (not to stress it unnecessarily)? It most probably folds down to being energy-efficient i.e. to draw as small current as possible in overall.
E.g. pull-up resistor for momentary switches and flip-switches expected to be open most of the time and pull-down for the flip-switches expected to be closed most of the time? Or it does not matter? And external or internal or again it does not matter?
If I get the concept right, then a connection through a pull-up resistor (say 10k for a start) will bring 5V to the Arduino’s pin when the switch is open but the current – thanks to a high value of the resistor – will be very very small one. When pushed (closed) the circuit is shorted, and the PIN reads LOW.
If I follow the logic right further on – to answer one of my questions – it does not matter whether pull-up or pull-down is used – the current goes anyhow either to the pin or to the ground (and vice versa) and the fact that the current consumed is minimal is delivered by a relatively high value of the resistor.
However: I intend to connect quite a lot of switches and a hundred times nothing killed the donkey. And some of the switches will be connected over longer wires (10-20 meter) so forums suggest (esp. in electrically noisy environment) to use smaller value of the resistor to cut out the noise.
BTW, if e.g. pull-up resistor is used, and switch is open – 5V is brought to the digital pin. Does the small current flow all the time or only when pin is tested (read)?
Sorry for this novice question – but many posts look at how to properly connect one switch. Connecting a bunch of them in an energy efficient way is a name of the game for today.