Week 4: Raspberry PI push button

Introduction:

Up until now, we’ve focused mostly on outputs. Now we’re going to go to the other end of spectrum and play around with inputs. In this circuit, we’ll be reading in one of the most common and simple inputs – a push button – by using a digital input. The way a push button works with your Raspberry Pi is that when the button is pushed, the voltage goes LOW. Your Raspberry Pi reads this and reacts accordingly.


Parts Needed:
You will need the following parts:
⦁ 1x Breadboard
⦁ 1x Raspberry Pi
⦁ 1x LEDs
⦁ 1x 330 Ω or 220 Ω Resistors
⦁ 7x Jumper Wires
⦁ 2x Push Buttons
⦁ 2x 10k Resistors
⦁ Hardware Hookup
Ready to start hooking everything up?


Circuit Diagram:
Connect the top right PIN of the two push buttons to ground on the breadboard. Then connect Ground on the breadboard to Ground on the Raspberry PI. See last page for pin locations.
Connect the bottom right PIN of the 2 push buttons to ground using a 10k Ω resistor. Connect the same PIN to GPIO 3 and GPIO 4 on the Raspberry PI. See last page for pin locations.
Connect the Positive end of the LED to GPIO 2 and Connect Power on the breadboard to +5v on the Raspberry PI. Then connect the Negative end of the LED to ground using a 220 Ω or 320 Ω resistor.

Programming Code:


What should you see:
You should see the LED turn on if you press either button, and off if you press both buttons. (See the code to find out why!) If it isn’t working, make sure you have assembled the circuit correctly and verified and uploaded the code to your board or see the troubleshooting section.


Did you know?
In The circuit above if the Resistor connected to push button is changed from GND to +5V and the Push button switch is changed from +5V to GND the LED will operated inversely. i.e When push button is Pressed the LED connected to pin 13 will turn ON and when released the LED will turn OFF.


Challenges:
Can you change the program so the LED only turns on when both buttons are pushed?