If we add an external resistor to the circuit, as shown in the following diagram, then we'll introduce what is called a pull-up resistor, which serves the purpose of pulling (meaning connecting) GPIO pin 21 up (meaning connected to a positive voltage) to 3.3 volts:
Figure 6.6 – Push button circuit with a pull-up resistor
Here are the steps to create this circuit on your breadboard. The step numbers here match the numbered black circles shown in the preceding diagram:
- Place the push button on your breadboard.
- Place the resistor (with a value between 50kΩ to 65kΩ ) on your breadboard. One end of the resistor shares the same row (shown at hole B5) as the upper positioned leg of the push button. The other end of the resistor is placed on an empty row.
- Connect the other end of the resistor to a 3.3-volt pin on your Raspberry Pi.
- Connect the lower leg of the push button to a GND...