I googled and searched in here but I couldn’t find an explanation that I understood on the digital input 2 and why it is wired the way it is.
A circuit diagram is attached. My confusion is around the positioning of the resistor and the line going from between the switch/resistor to the 2nd digital io pin on the Arduino. Alas the Arduino Projects Book doesn’t explain clearly why this is, just that it must be so. All the book states is:
Place the switch on the breadboard just as you did in the previous project. Attach one side to power, and the other side to digital pin 2 on the Arduino. You’ll also need to add a 10k-Ohm resistor from ground to the switch pin that connects to the Arduino. That pull-down resistor connects the pin to ground when the switch is open, so it reads LOW when there is no voltage coming in through the switch.
This implies to me that when the switch is open, a circuit is made between pin 2 and the GND via the ‘pull down resistor’. That kinda makes sense to me (but doesn’t explain the need for the resistor). My confusion is around what happens when the switch is closed? We have a circuit that includes 5V, GND and pin 2 afaict, which I don’t understand…
Any help would be appreciated.