Push Button

In this project, you'll learn how to connect and use a push button to manually turn on and off a LED.

A push button is a simple on-off switch for turning on and off an electric signal. Press the button to turn on and release the button to turn off.

Parts needed:
  • Arduino
  • A push button
  • A 22K Ω resistors (red-red-orange)
  • Wires
  • Breadboard
Software stuff you'll learn:
Push button 22K ohm resistor
1 Making the connections

Be careful with the orientation of the 4 pins on the push button:
  • Pins 1 and 3 are always connected
  • Pins 2 and 4 are always connected
  • Pins 1 and 2 are connected only when you press the button
  • Pins 3 and 4 are connected only when you press the button
Push button Pins
Use pins 1 and 2 of the push button for this project.
  • Connect pin 2 of the push button to the GND pin on the Arduino.
  • Connect pin 1 of the push button to digital pin 2 on the Arduino and to one end of the 22K Ω resistor.
  • Connect the other end of the resistor to 5V on the Arduino.

    This resistor is called a pull-up resistor because it is pulling the signal on pin 2 up to 5V.



Push button schematic
Push button connections
2 Create a new program and type in this program.







The push button is connected to pin 2.
We will control the internal LED that is connected to pin 13.


The pinMode command declares the led pin for OUTPUT, and the pushButton pin for INPUT.




The digitalRead command reads in a digital value (either HIGH or LOW) from the pushButton input pin, and stores the value in the buttonState variable.

The digitalWrite command will either turn on or off the internal LED depending on the value that is stored in the buttonState variable.
Push button program
3 Run the program.

Press and release the push button and observe the internal LED on the Arduino board.