Week 5 – Push Button

Arduino
Experiment : Push Buttons


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 experiment 2, we used an analog input to read the potentiometer. 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 RedBoard or Arduino Uno R3 is that when the button is pushed, the voltage goes LOW. Your RedBoard or Arduino Uno R3 reads this and reacts accordingly.
In this circuit, you will also use a pull-up resistor, which keeps the voltage HIGH when you’re not pressing the button.


Parts Needed
You will need the following parts:
1x Breadboard
1x RedBoard or Arduino Uno
1x LED
1x 330Ω Resistor
7x Jumper Wires
2x Push Buttons
2x 10k Resistors
Hardware Hookup
Ready to start hooking everything up? Check out the Fritzing diagram and hookup table below, to see how everything is connected.

What You Should 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.

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.
Real World Application
The buttons we used here are similar to the buttons in most video game controllers.

Program
Turn OFF the LED connected to pin 13 when push button connected to pin 2 is pressed

Turn ON the LED connected to pin 13 when push button connected to pin 2 is pressed

Turn OFF the LED connected to pin 13 when push button connected to pin 2 and pin 3 is pressed



Turn OFF the LED connected to pin 13 when push button connected to pin 2 or pin 3 is pressed

Challenges
⦁ Turn the LED when push button connected to pin 2 is pressed and pin3 is not pressed.
⦁ Connect another LED to PIN 12. Turn both the LED when push button connected to PIN 2 is pressed and turn off both the LED if push button connected to PIN 3 is pressed.
Real World Application
The buttons we used here are similar to the buttons in most video game controllers.