How to use a Push Button with Arduino

Push buttons are among the most basic yet essential components in electronics. Whether you’re turning on an LED, starting a motor, or building a game controller — Push buttons are everywhere. In this blog, we’ll learn how to use a push button with Arduino, understand how it works, connect it correctly, and write sample code to read its state.

How to use a Push Button with Arduino

What is a Push Button?

A push button is a simple mechanical switch used to make or break a connection when pressed. It temporarily allows current to flow in a circuit and returns to its original state when released.

Key Features:
  • Normally Open (NO) or Normally Closed (NC)
  • No polarity – connect either terminal to Arduino
  • Used for inputs like user commands or triggers
What is Push Button? how we can use push button with arduino

What is Difference between Push Button and Switch?

While both push buttons and switches are used to control electrical circuits, they function differently:

A switch is a latching device – it maintains its state (ON or OFF) until toggled again. Once you flip or slide it, the circuit remains connected or disconnected until changed.

A push button is a momentary device – it only stays active while being pressed. Once released, it returns to its default state (usually open).

Components Required for using Push Button with Arduino?

  • Arduino UNO (or any compatible board)
  • 1x Push Button (Momentary Type)
  • 1x 10KΩ Resistor (for pull-down)
  • Breadboard & Jumper Wires
  • 1x LED (Optional, for output)

Circuit Diagram of Push Button with Pull-down Resistor:

  • One leg of the button → Digital Pin 2
  • Same leg → 10KΩ resistor → GND
  • Opposite leg of button → 5V

This way, when the button is not pressed, the input pin reads LOW. When pressed, it connects to 5V and reads HIGH.

Circuit Diagram of Push Button with Pull-down Resistor

Arduino Code for Push Button with Pull-down Resistor:


const int buttonPin = 2; // the number for pushButton pi 
const int ledPin = 13; // the number for LED

int buttonState = 0;

void setup() {
  // initialize the LED pin as an output
  pinMode(ledPin, OUTPUT);
  // initialize the pushButton pin as an Input
  pinMode(buttonPin, INPUT);

}

void loop() {
  // read the state of pushButton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushButton is presses. If it is
  if(buttonState == HIGH){
    // turn LED on:
    digitalWrite(ledPin,HIGH); 
  }else{
    // turn LED off:
    digitalWrite(ledPin,LOW);
  }
}

Circuit Diagram of Push Button with Input Pullup:

Arduino has built-in pull-up resistors that you can activate in code. This method eliminates the need for an external resistor.

  • One leg of the button → Digital Pin 2
  • Other leg → GND

In this method, we set the button as INPUT_PULLUP in void setup that means the initial state of button is HIGH. When we push the button, the state will change from HIGH to LOW. This method is much efficient and easy to use. But it totally depends on you which method you want to use.

Circuit Diagram of Push Button with Input Pullup
Input_Pullup

Arduino Code for Push Button with Input Pullup:


const int buttonPin = 2; // the number for pushButton pi 
const int ledPin = 13; // the number for LED

int buttonState = 0;

void setup() {
  // initialize the LED pin as an output
  pinMode(ledPin, OUTPUT);
  // initialize the pushButton pin as an Input
  pinMode(buttonPin, INPUT_PULLUP);

}

void loop() {
  // read the state of pushButton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushButton is presses. If it is
  if(buttonState == LOW){
    // turn LED on:
    digitalWrite(ledPin,HIGH); 
  }else{
    // turn LED off:
    digitalWrite(ledPin,LOW);
  }
}

How to use Push button as a Switch with Arduino?

The circuit diagram should be same. We can do changes in our code. Here is the code :

bool flag = false, State=false;
int ledPin=13;
void setup()
{
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() 
{
  if (digitalRead(2) == LOW && flag == false)
  {
    Serial.println("ON");
    flag = true;
    State = !State;
    if(State==true)
    digitalWrite(ledPin, HIGH);
    else
    digitalWrite(ledPin, LOW);
  }
  else if (digitalRead(2) == HIGH && flag == true)
  {
    flag = false;
    
  }
}

How to Use a Push Button with Arduino, Video Tutorial:

Real Life Applications of Push Button with Arduino

  • Turning ON/OFF lights or devices
  • Game controllers
  • Digital locks
  • Joystick-like controls
  • Start/stop counters or timers
  • User-triggered data logging

Troubleshooting of Push Button:

ProblemSolution
Button not respondingCheck wiring and pin numbers
Random HIGH/LOW valuesUse pull-up or pull-down resistor
Multiple triggersAdd software Debounce
LED always ON/OFFVerify logic (LOW = pressed)

Conclusion:

Using a push button with Arduino is one of the first things every electronics learner should master. It teaches digital inputs, logic control, and user interaction — all in one simple project.

By understanding both hardware (resistors, wiring) and software (pin modes, Debounce), you can build smarter and more interactive Arduino projects.

Need Help in Setup of Push Button with Arduino?

If you need any Help or Assistance for Setup of Push Button with Arduino, with Modifications or Customization then you can contact us through WhatsApp. We can deliver you this Project in the Following Ways.

Learn More about the services we offer.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
YouTube
× Contact us