How to use push button with Arduino UNO R3

This is the third tutorial on a series of tutorials on Arduino. In the last tutorial, we have seen. How to use Arduino digital pins as an output. In this tutorial, we will see how to use digital pins of Arduino as input but you should have a concept of using digital pins of Arduino as an output. How to use push button with Arduino UNO R3, In this article I have discussed push button use with Arduino UNO R3. How to use digital pins of Arduino as an input pin. To demonstrate the use of digital pins as an input, push-button is used to control two LEDs connected with digital input/output pins of Arduino. If you don’t know how to use Arduino pins as an output. Go through the following tutorial :

How to use Arduino UNO R3 digital pins as an output 

Two LEDs are connected with pin numbers 1 and 2 of the Arduino board. the push button is connected with pin number 0 of the Arduino to use push button with Arduino

Push button is basically used to control two LEDs or to turn on/off two LEDs. when the push button is pressed. Both LEDs glow and when a push button is unpressed, LEDs remains turn off. Two resistors are connected in series with both LEDS as a current limiting resistor. Push button one side is connected with 5 volt source and other side is connected with ground through 10k ohm resistor. When the push button is not pressed, logic low is used as input for pin 0 and when the push button is pressed, logic high is used as an input of pin 0. Circuit diagrams of both states are shown below Simulation diagram when push button is not pressed:

Unpressed push button
Unpressed push button

Simulation diagram when the push button is  pressed

Simulation with pressed push button
Simulation with pressed push button

Video lecture

Programming for Push button with Arduino

To understand the programming of push button use with Arduino, First, you need to know the input function and its use. Explanation of the input function is given below :

pinMode(pin number, INPUT): I have already discussed pinMode function use in LED blinking with Arduino UNO R3. The same function is used to declare pin as an input pin. Where INPUT argument is used to declare the specified pin number as an input pin. For example pinMode(0, INPUT) function declare pin 0 as a input pin.

digitalRead(pin number): digitalRead function is used to read status of input pin either pin is at logic level high or logic level low. The output of this function is stored in another variable which can be used to perform other functions according to your application.

digitalWrite(pin number, HIGH/LOW): digitalWrite function is used to write or output at specified pin number either output is logic high or logic low.

The code of the above circuit is given below. Copy this code to Arduino software.

int buttonStatus; // Variable declare to store status of digitalWrite
 void setup() {

 pinMode(1, OUTPUT); 
  pinMode(2, OUTPUT); 
  pinMode(3, INPUT); 

void loop()

 buttonStatus = digitalRead(3);
  if (buttonStatus == HIGH) 
  digitalWrite(1, HIGH);
  digitalWrite(2, HIGH); 

 digitalWrite(1, LOW); 
  digitalWrite(2, LOW); 

If you have any issues after reading this article, you are welcome to comment on this post. Share it with your friends on social media. To download code and circuit diagram of this project, click on the link below: Use of push button with Arduino UNO R3

Leave a Comment