I have a switch setup with a pull-up resistor. With the switch open I get a "1" or HIGH output and with the switch closed I get a "0" or LOW output. I understand why I am getting the "1" with it open (because it is connected to 5v) but I don't understand why I get the "0" when it's closed. Aren't 5v's still passing through the switch?
The switch is essentially an ideal conductor, with a negligible resistance that can be ignored. When closed, the node between the pull up resistor and the switch is pulled to ground or 0 potential. The resistor, as ohm laws would dictate, carries the 5v across it, "using" the voltage. Since the path of least resistance is a direct connecting to ground, the node is pulled to ground.
When the switch is open, the node is open, and no current flows, bringing the node to 5V through the weak resistor.
Think of the switch as a direct wire.
The other side of the switch is connected to Ground (0V rail).
In other words, you have a pull-up resistor connected from the 5V rail to the top side of the switch and also to your controller input pin. The other side of the switch is grounded.
When the switch is open, 5V from the pull-up resistor is fed to the controller input pin.
When the switch is closed, the input pin of the controller is connected to ground.
With the switch open,measuring across the switch will give you five volts because no current can flow through the resistor,hence you will find no voltage drop across it.
With the switch closed, assuming an ideal switch with zero resistance, according to our man Kirchov, all the voltage must drop across your resistor. So, you measure 0V in this case.