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 legs on the push button:
  • Legs 1 and 3 are always connected
  • Legs 2 and 4 are always connected
  • Legs 1 and 2 are connected only when you press the button
  • Legs 3 and 4 are connected only when you press the button
Push button legs
Use legs 1 and 2 of the push button for this project.
  • Connect leg 2 of the push button to the 5V pin on the Arduino.
  • Connect leg 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 GND on the Arduino.



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 to be for OUTPUT, and the pushButton pin to be 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.