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?
-
\$\begingroup\$ learn.sparkfun.com/tutorials/pull-up-resistors \$\endgroup\$– WillFeb 23, 2015 at 6:32
-
\$\begingroup\$ It is because the 5V gets dropped across your pull-up resistance when the switch is closed. \$\endgroup\$– nidhinFeb 23, 2015 at 9:05
3 Answers
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.
-
\$\begingroup\$ I wish I understood what you were saying. \$\endgroup\$ Feb 23, 2015 at 6:57
-
\$\begingroup\$ @MichaelRader: Think of the resistor as a spring and the power supplies as stiff rails. (This actually works for a lot of circuits, though not all.) With no other influence, the signal gets pulled to the supply rail by the spring. When you close the switch, you now have a REALLY STRONG spring pulling the signal to the other rail, and so the first spring gets "stretched out". If a spring is stretched beyond what it can handle, it blows up. \$\endgroup\$– AaronDFeb 23, 2015 at 18:01
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.