User Guide
Table Of Contents
165
1. When the switch is not pressed the input pin can be
floating. When a pin floats, it is neither high nor low,
and can change between the two seemingly at
random.
2. When the switch is pressed, there is very little
resistance in the circuit and so this can damage the
Pi. It is, effectively, a short circuit.
Introducing Pull-Up and Pull-Down Resistors
In the diagram below, when the switch is open, electricity flows
through the resistor and into the GPIO pin. So when the switch
is open, the GPIO pin is high. When the switch is closed, all of
the electricity is drawn to ground, and this creates a low on the
GPIO pin. So the pin is always in one or state or the other, it is
never floating.
Pulling the line up in this way is called using a pull-up resistor.
Figure 6. A switch and a pull-up resistor
A pull-down resistor works in the opposite way: when the switch
is open, the GPIO pin is tied to ground and is low. But when the
switch is closed, electricity flows into the GPIO pin and it is high.
The Raspberry Pi has pull-up and pull-down resistors built-in to
all of the GPIO pins. And you can choose which ones you want
to use from your software programs.