In this course, we’ll look at how to read the value of a pushbutton on the Raspberry Pi. This can be very useful for interacting with the user.

Here’s the diagram to connect the push button to the Raspberry Pi:

We’ve added a pull-down resistor so that when the push-button is not pressed, the board reads a low state and there are no undefined states.

Programming

Here is the program to read the values coming from the push button: