How to use push button with Arduino UNO R3

Hi Everyone its me Bilal again. This is a third tutorial on series of tutorials on Arduino. In last tutorial we have seen. How to use Arduino digital pins as a output. In this tutorial, we will see how to use digital pins of Arduino as a input but you should have a concepts of using digital pins of Arduino as a ouput . 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 a input pins. To demonstrate use of digital pins as a 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 a output. Go through following tutorial :

How to use Arduino UNO R3 digital pins as a output 

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

Circuit Description of circuit diagram

Push button is basically used to control two LEDS or to turn on/off two LEDS. when push button is pressed. both LEDS glow and when push button is unpressed, LEDS remain 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 push button is not pressed, logic low is used as input for pin 0 and when push button is pressed, logic high is used as a 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 push button is  pressed:

Simulation with pressed push button
Simulation with pressed push button

Video lecture:

Programming :

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

pinMode(pin number, INPUT) : I have already discussed pinMode function use in LED blinking with Arduino UNO R3Same function is used to declare pin as a input pin. Where INPUT argument is used to declare specified pin number as a 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. 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.

Code of 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 issue 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 link below : Use of push button with Arduino UNO R3

Leave a Comment