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
Quantity | Part | Description | Buy Link |
---|---|---|---|
1 | Arduino UNO | Micro controller Board | Buy on Elecsynergy |
1 | LED | Any color; output to control with the button | Buy on Elecsynergy |
1 | Push Button | Momentary switch for digital input | Buy on Elecsynergy |
1 | 220 ohm Resistor | Limits current to LED | Buy on Elecsynergy |
1 | 10k ohm Resistor | Pull-up resistor for the button | Buy on Elecsynergy |
1 | Breadboard | For circuit prototyping | Buy on Elecsynergy |
6 | Jumper Wires (M-M) | For connections between Arduino and components | Buy 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
pinMode()
initializes the LED as an output and button as an input.- When the button is pressed, Digital Pin 2 reads LOW because the circuit is closed.
- Arduino sets Pin 13 HIGH, and the LED turns ON.
- 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
- Toggle LED on Press: Use code logic to turn ON/OFF LED with every press instead of holding the button.
- Control multiple LEDs: One button can cycle through different LED states.
- Long Press vs Short Press: Differentiate between press durations using
millis()
. - Debounce the button: Use a delay or debounce algorithm to prevent false readings.
- 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
#ArduinoPushButton #ArduinoProjects #LEDControl #InnovateYourself #Elecsynergy #BeginnerArduinoProject