Oftenwe want to connect a digital input line to our microcontroller.Typically this might be to allow us to monitor the on-off state of aswitch.
Atfirst glance this seems fine.
When theswitch is closed, the pin on our microcontroller is tied to 0 volt,ie. low.
In contrastwhen the switch is open we would want the pin to be 5 volts, or high.
The input pinwould tend to “float” high. This however isn’t a true inputsignal, it is a very weak input and can readily switch from high tolow through the slightest of electrical interference in any of thewiring.
A simplesolution might appear to involve simply connecting the other end ofthe switch to our 5 volt supply
This willgive us a 5 volt (high) signal on the input pin when the switch isopen. When the switch is closed however we will get a short betweensupply and ground => zero resistance => infinite current - thisis not good news.
Theproblem can be remedied by simply putting a resistor into thecircuit. This is the pull-up resistor.
When theswitch is open, the input to the microcontroller is high. There is nodirect connection to the 5v rail, however because the input impedenceto the microcontroller is high, very little of the 5v is dropped overthe pull up resistor.
Whenthe switch is closed current flows down through the resistor andthrough the closed switch to ground. The input pin is tied to groundand so will read low.
Thisgives us what we want.
Avariation on this is the pull-down resistor. This ties the input pinto ground rather than the supply voltage.