How to Interface a Push Button with Arduino to Control an LED

How to Interface a Push Button with Arduino to Control an LED
0
0
4 min read

Learn how to control an LED using a push button and Arduino UNO in this beginner-friendly, hands-on project. Includes full circuit diagram, code, explanation, and expansion ideas.


Introduction

In this blog post, you will learn how to interface a push button with Arduino to control an LED. This is one of the most fundamental and essential skills in embedded systems and Arduino-based electronics.

Whether you’re building a DIY home automation system or just getting started with Arduino, understanding how to detect button presses is essential. Using them to control outputs like LEDs will form the foundation for more complex projects.

What the Project Does

When you press the push button, the LED turns ON. When you release the button, the LED turns OFF. This basic behavior teaches you how digital inputs and outputs interact in real time.

Real-World Use Case

Push buttons are used in almost every electronic system — from microwaves to elevators, from industrial control panels to toys. Learning how to handle them with micro controllers is essential for all embedded developers.

Skill Level

Beginner

Expected Outcome

By the end of this tutorial, you will:

  • Understand how push buttons work
  • Learn how to connect and debounce a push button
  • Control an output (LED) using a digital input

Components Required

QuantityPartDescriptionBuy Link
1Arduino UNOMicro controller BoardBuy on Elecsynergy
1LEDAny color; output to control with the buttonBuy on Elecsynergy
1Push ButtonMomentary switch for digital inputBuy on Elecsynergy
1220 ohm ResistorLimits current to LEDBuy on Elecsynergy
110k ohm ResistorPull-up resistor for the buttonBuy on Elecsynergy
1BreadboardFor circuit prototypingBuy on Elecsynergy
6Jumper Wires (M-M)For connections between Arduino and componentsBuy on Elecsynergy

Circuit Diagram + Explanation

Connection Overview:

  • LED anode (long leg) → Digital Pin 13 on Arduino
  • LED cathode (short leg) → One end of the 220Ω resistor
  • Other end of the resistor → GND
  • One terminal of push button → Digital Pin 2 on Arduino
  • Other terminal of push button → GND
  • 10kΩ resistor (pull-up) connected between Digital Pin 2 and 5V to keep the input high when button is unpressed

✅ This setup uses active-LOW logic: the pin reads LOW when the button is pressed.

Visual Diagram


Arduino Code

// Push Button to Control LED

int ledPin = 13;     // LED connected to digital pin 13
int buttonPin = 2;   // Button connected to digital pin 2
int buttonState = 0; // Variable to store button status

void setup() {
  pinMode(ledPin, OUTPUT);      // Set LED pin as OUTPUT
  pinMode(buttonPin, INPUT);    // Set button pin as INPUT
}

void loop() {
  buttonState = digitalRead(buttonPin); // Read the button state

  if (buttonState == LOW) {
    digitalWrite(ledPin, HIGH); // Turn LED ON
  } else {
    digitalWrite(ledPin, LOW);  // Turn LED OFF
  }
}

Working Explanation

  1. pinMode() initializes the LED as an output and button as an input.
  2. When the button is pressed, Digital Pin 2 reads LOW because the circuit is closed.
  3. Arduino sets Pin 13 HIGH, and the LED turns ON.
  4. When the button is released, Pin 2 reads HIGH , and the LED turns OFF.

This basic ON/OFF logic is the basis for implementing more advanced inputs like keypads, touch sensors, and rotary encoders.


Demo / Output Preview

💡 What You’ll See:

  • Press the button → LED turns ON
  • Release the button → LED turns OFF

Troubleshooting & Tips

  • Button not working? Double-check the pin mapping and resistor placement.
  • Ensure pull-up resistor is connected between the button pin and GND.
  • Replace your button if it’s stuck or non-responsive.
  • Try Serial.print() to debug button state in real time.
Serial.begin(9600);
Serial.println(buttonState);

Project Expansion Ideas

  1. Toggle LED on Press: Use code logic to turn ON/OFF LED with every press instead of holding the button.
  2. Control multiple LEDs: One button can cycle through different LED states.
  3. Long Press vs Short Press: Differentiate between press durations using millis().
  4. Debounce the button: Use a delay or debounce algorithm to prevent false readings.
  5. Control a Relay or Buzzer: Use the button to control larger outputs via relay modules.

Conclusion

Congratulations! You’ve just completed a key milestone in your Arduino learning journey. Interfacing a push button is not only simple but also incredibly powerful. This project lays the groundwork for real-time input/output control systems, automation, and user interfaces.

Ready for more? Bookmark this post and stay tuned for more projects in our Arduino series. Share your setup and tag us to get featured!


🛒 Buy the Complete Kit

Available on Elecsynergy


#ArduinoPushButton #ArduinoProjects #LEDControl #InnovateYourself #Elecsynergy #BeginnerArduinoProject

Leave a Reply