Tutorial 20: GPIO How to Use a Push Button
We have covered simple digital outputs with a LED. Now let's take a look at simple digital inputs using a push button connected to the Raspberry Pi's GPIO header. In this tutorial I show you how, in Python 3, you can read a signal input from a push button on a breadboard.
Although not covered in the video tutorial, I recommend you attach a 10kohm pull up resistor on the pin used to take a reading. When this is done you guarantee a 'high' reading when you are not pressing the button, vs. reading a floating pin. A floating pin is generally not recommended as it subjects your circuit to potential misreadings due to electrical noise and electrical interference.
This tutorial is a little older (published in 2015!). The main principles are still relevant, so I haven't needed to update this lesson.