Interfacing Push button with Raspberry Pi is very simple. In this project i will show you how to interface 4 pin push button switch with Raspberry Pi 2 and also connect one LED so that when button is pressed, LED will turn ON and on button release it will turns OFF.
There is direct connection between A and B, whether button is pressed of not. And same for C and D.
When button is pressed, A and C are getting shorted (actually all pins are getting shorted) and same way B and D are getting shorted.
So to use this push button as a switch, use either A-C pair or B-D pair or A-D or B-C.
The Button is wired in such a way that when it is pressed, it will connect GPIO 23 to the Ground(GND).
In the code (check below in code section),
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
means GPIO 23 is normally pulled up to 3.3V. So that when you read the input value using
GPIO.input , it will return False if the button is pressed.
Pull Up Resistor Concept
Each GPIO pin in Raspberry Pi has software configurable pull-up and pull-down resistors. When using a GPIO pin as an input, you can configure these resistors so that one or either or neither of the resistors is enabled, using the optional
pull_up_down parameter to
For more detail: Push Button with Raspberry Pi