From a pure electronics viewpoint, there is no real difference between both circuits, the difference will be handled by your code running on the MCU, as a close switch will either be
LOW depending on the logic you used to wire your switch.
The resistor must be present for 2 reasons:
- to avoid producing a shortcut between
GND when the switch is closed, without it the shortcut would probably damage your power supply circuitry (if both pins are directly taken from Arduino, that would mean damaging Arduino supply circuits)
- to make the voltage pin attached to the pin the "winner" of both voltage pins when the switch is closed, ie that pin will provide the level to Arduino input pin
The value of the resistor should be:
- high enough to limit the current between
GND when the switch is closed, preventing damage and limiting overall power consumption of your circuit
- not too high to allow providing a voltage level to the input pin
Using 10k means that, applying Ohm's law, when closing the switch, a 0.5mA current would flow from
GND, which is generally acceptable in terms of consumption and cwill not damage your power supply.
Note that the input pin is "high impedance" which means it has no voltage level if not connected to anything, and it does not supply or sink any current (or more accurqtely a negligible current only).
Finally, it is good to know that Arduino MCU offers the
INPUT_PULLUP mode for digital pins, where an internal resistor pulls up the pin input to 5V. This enables you to directly connect your switch between the pin and
GND. So you just have to code:
For information, according to ATmega328P datasheet (the MCU of Arduino UNO), those internal pullup resistors have a value between 20k and 50k.