Push Button with Raspberry Pi

Story

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.push button with raspberry pi

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.

Hardware Setup

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 Conceptschematic push button with raspberry pi

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 GPIO.setup

For more detail: Push Button with Raspberry Pi


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top