User manual

39
here so far. But it gets interesting when the pedestrian light, instead of running automatically, is started by
pressing a button as is the case with many pedestrian lights. In the next experiment a button is connected to
a GPIO port that will simulate the push button on a real traffic light.
4.2 Button on the GPIO connector
GPIO ports not only output data, for example by means of LEDs, but they can also be used to input data.
Therefore they must be defined as input in the programme. In the next project we are going to use a button
for the input, which is directly plugged into the breadboard. The button has four connector pins, whereby
each two pins that lie opposite to each other (long distance) are interconnected. As long as the button is
pressed, all four connectors are linked to each other. Unlike a switch, a pushbutton does not lock. The
connection breaks as soon as the button is released. If at a GPIO port which is defined as input a +3.3 V
signal is present, it is evaluated as logical
True or 1. In theory, you could connect an appropriate GPIO port
via a button to the +3.3 V port on the Raspberry Pi. Don’t ever do it! It will overcharge the GPIO port. Always
interpose a 1kohm protective resistor between a GPIO input and the + 3.3V terminal to protect the GPIO port
from too much current that would also be flowing to the processor.
Fig. 4.3: Pushbutton with protective resistance on a GPIO input.
In most cases, this simple circuit works, but the GPIO port has no clearly defined state when the button is
open. If a programme queries this port the results could be random. As a measure of prevention a relative
high resistor - usually 10 ohms - is connected to ground. This so-called pull-down resistor pulls the status of
the GPIO ports at open button back down to 0 V. As resistance is very high as long as the button is pressed,
there is no risk of a short circuit. When the button is pressed, the + 3.3V and the ground wire are connected
directly via this resistor.