![]() |
| Arduino Push Button Tutorial |
{getToc} $title={Table of Contents}
Introduction
After learning how to blink an LED, the next step in Arduino is to control things using input. This is where the push button comes into the picture.
A push button is one of the simplest input devices. When you press it, it sends a signal to the Arduino. When you release it, the signal stops. Even though it looks very basic, this small component is used in almost every electronic system.
I remember when I first tried using a push button, it didn’t work properly because of a small wiring mistake. But once I understood how it actually works, it became one of the most useful components in my projects.
In Arduino, push buttons are important because they allow you to interact with your project. Instead of running automatically like an LED blink, now you can control things using your actions.
👉 If you haven’t checked the LED Blink tutorial yet, it is recommended to go through it first. It will help you understand output before learning input.
In this tutorial, you will learn two important ways to use a push button:
- Mode 1: Read button state (0 and 1)
- Mode 2: Toggle ON/OFF using clicks
By the end of this guide, you will clearly understand how Arduino reads input and how to use that input to control your projects.
What is Push Button in Arduino?
A push button is a simple electronic component used to send input signals to the Arduino. When you press the button, it completes the circuit and sends a signal. When you release it, the circuit breaks and the signal stops.
In Arduino, a push button is used as an input device. This means it allows the user to control what the Arduino should do. Instead of running automatically, the program can now respond based on your action.
You can think of it like a switch. When you press it, something happens. When you release it, the action stops. Arduino reads this change using its input pins.
In real life, push buttons are used in many places:
- Doorbells
- Keyboard keys
- Elevator buttons
- Power switches
When I first used a push button with Arduino, I realized that this is how real-world systems take input from users. It’s a small component, but it plays a big role in building interactive projects.
Now that you understand what a push button is, let’s look at its pin structure and how it works internally.
Push Button Pinout
Before connecting the push button to Arduino, it is important to understand how its pins are arranged. Many beginners get confused here, but once you understand the structure, it becomes very simple.
![]() |
| Push Button 4-pin structure |
A standard push button usually has 4 pins. Even though there are four pins, it actually works like a simple two-connection switch.
4-Pin Structure
The push button has two pairs of pins:
- Two pins on one side are internally connected
- The other two pins on the opposite side are also connected
So, each side acts like a single connection point.
Internal Connection
Inside the push button:
- Not Pressed: The two sides are not connected
- Pressed: Both sides get connected
When you press the button, it completes the circuit, allowing current or signal to pass through.
Why Opposite Pins Are Used
To use the push button correctly, you must connect pins from opposite sides.
👉 If you connect pins from the same side, they are already connected internally, so the button will not work.
👉 If you use opposite pins, the circuit will only complete when the button is pressed.
{alertWarning} Common Mistake: Many beginners connect pins from the same side, which causes the button to always stay ON.
Understanding the pinout is very important because most wiring mistakes happen at this stage.
Push Button Pin Diagram
To clearly understand how a push button works, it is helpful to look at its pin diagram. This will show you which pins are internally connected and how to use them correctly.
Push Button Diagram
Refer to the labeled image below:
![]() |
| Push Button Pin Diagram |
In the diagram, you can see that:
- Pins on the same side are internally connected
- Opposite sides are separated until the button is pressed
Correct Connection
To make the button work properly:
- Use one pin from one side
- Use another pin from the opposite side
This ensures the circuit is completed only when the button is pressed.
Wrong Connection
If you connect pins from the same side:
- The circuit will always remain connected
- The button will not work as expected
{alertWarning} ⚠️ Important: Always double-check the pin connections before powering the circuit. Incorrect wiring is the most common mistake beginners make.
Once you understand this diagram, connecting the push button becomes very easy.
Components Required
To build this push button circuit, you only need a few basic components. These are commonly used in most Arduino projects and are easily available.
| Component | Quantity | Buy Link |
|---|---|---|
| Arduino Uno | 1 | {getButton} $text={Buy Now} $icon={cart} |
| Push Button | 1 | {getButton} $text={Buy Now} $icon={cart} |
| Resistor (10kΩ) | 1 | {getButton} $text={Buy Now} $icon={cart} |
| Breadboard | 1 | {getButton} $text={Buy Now} $icon={cart} |
| Jumper Wires | 3-4 | {getButton} $text={Buy Now} $icon={cart} |
Make sure all components are properly connected before powering the Arduino. Using the correct resistor value (10kΩ) is important to ensure stable input readings.
Simple Push Button Circuit
Now let’s build a simple push button circuit using Arduino. This is the basic setup that helps Arduino detect whether the button is pressed or not.
At first, I thought just connecting a button directly would work. But without a proper resistor, the input signal becomes unstable. That’s why understanding this circuit is very important.
Circuit Connections
- Push Button → Connect one side to Pin 2
- Other side → Connect to 5V
- Resistor (10kΩ) → Connect between Pin 2 and GND
This setup is called a pull-down resistor circuit.
Pull-down Concept
The pull-down resistor ensures that the input pin has a stable value when the button is not pressed.
- Button NOT pressed → Pin reads LOW (0)
- Button pressed → Pin reads HIGH (1)
Without the resistor, the input pin may show random values (called floating), which can cause incorrect readings.
{alertWarning} ⚠️ Important: Always use a 10kΩ resistor in push button circuits to avoid unstable input signals.
Circuit Diagram
Refer to the image below for better understanding:
![]() |
| Simple push Button circuit |
Make sure the connections are correct before powering the Arduino.
Once your circuit is ready, we can move to the next step and read the button input using code.
Mode 1: Read Button State (0 / 1)
Now let’s read the input from the push button. This is the first step in understanding how Arduino receives signals from external components.
When you press the button, Arduino reads a signal. When you release it, the signal changes. We can see this clearly using the Serial Monitor.
What is HIGH and LOW?
Arduino reads digital input in two states:
- HIGH (1) → Button is pressed
- LOW (0) → Button is not pressed
These values help Arduino understand your actions.
Arduino Code
Serial Monitor Output
After uploading the code:
- Open Serial Monitor (Tools → Serial Monitor)
- Set baud rate to 9600
You will see:
- Press button → 1
- Release button → 0
This confirms that Arduino is correctly reading the button input.
How It Works
- digitalRead(buttonPin) reads the button state
- The value is stored in buttonState
- Serial.println() prints the value
👉 Press = 1 (HIGH) 👉 Release = 0 (LOW)
Once you understand this, you are ready to control outputs using the button.
Mode 2: Toggle ON/OFF (Switch Logic)
In the previous section, we learned how to read the button state. Now let’s use that input to control something — just like a real switch.
In this mode, the button will work like a toggle switch:
- First press → Turns ON
- Next press → Turns OFF
- Next press → Turns ON again
This is how most real-world switches work.
Arduino Code
How the Toggle Logic Works
This code uses a simple trick to detect when the button is pressed only once.
- buttonState → Current button reading
- lastButtonState → Previous button state
The condition:
- buttonState == HIGH && lastButtonState == LOW
This means the button has just been pressed (not held).
When this happens:
- ledState = !ledState; flips the state
- If OFF → becomes ON
- If ON → becomes OFF
Why This Is Important
Without this logic, the LED would keep switching very fast while holding the button. This method ensures one action per press.
This concept is widely used in real applications like:
- Switch controls
- Menu buttons
- Device toggling systems
Now you have learned how to turn a simple push button into a smart control system.
How the Code Works
Now that you have written the code, let’s understand how it actually works step by step. This will help you move from just copying code to truly understanding it.
When I first learned this, I realized that Arduino simply follows instructions in a loop, checking conditions again and again.
digitalRead()
The digitalRead() function is used to read the state of the push button.
- HIGH (1) → Button is pressed
- LOW (0) → Button is not pressed
This value is stored in a variable:
- buttonState → current state of the buttonCondition Checking
The code checks this condition:
- buttonState == HIGH && lastButtonState == LOW
This means the button has just been pressed (not held down).
Why this matters:
- Without this check, the button would trigger continuously while being pressed
- This ensures one action per click
Toggle Logic Explanation
The line:
- ledState = !ledState;
is used to toggle the LED state.
- If LED is OFF → it becomes ON
- If LED is ON → it becomes OFF
This is what creates the switch-like behavior.
Finally, the current button state is stored:
- lastButtonState = buttonState;
This helps Arduino compare the previous and current states in the next loop.
Once you understand this flow, you can control many devices using buttons in your future projects.
Pull-down vs Pull-up Resistor
When I first connected a push button without a resistor, the readings were random. Sometimes it showed HIGH even when I didn’t press the button. This happens because of something called a floating input.
To fix this problem, we use resistors — either pull-down or pull-up.
Why Resistor is Needed
An Arduino input pin should always have a defined state:
- Either HIGH (1)
- Or LOW (0)
Without a resistor, the pin is not connected to a stable voltage. It can randomly change between HIGH and LOW due to noise.
👉 This is called a floating input.
Pull-down Resistor
In a pull-down setup:
- The resistor connects the input pin to GND
- Default state → LOW (0)
- When button is pressed → HIGH (1)
This is the circuit we used in this tutorial.
Pull-up Resistor
In a pull-up setup:
- The resistor connects the input pin to 5V
- Default state → HIGH (1)
- When button is pressed → LOW (0)
Arduino also provides a built-in pull-up resistor using:
- pinMode(buttonPin, INPUT_PULLUP);
Simple Comparison
| Type | Default State | When Pressed |
|---|---|---|
| Pull-down | LOW (0) | HIGH (1) |
| Pull-up | HIGH (1) | LOW (0) |
👉 For beginners, pull-down is easier to understand. But in real projects, pull-up is often used because it requires fewer components.
{alertWarning} ⚠️ Important: Never leave an input pin floating. Always use a pull-up or pull-down resistor.
Once you understand this concept, your button circuits will work reliably without random behavior.
Common Mistakes
When working with push buttons, beginners often face small issues that can stop the circuit from working. Most of these problems are simple and can be fixed easily once you understand them.
Let’s go through the most common mistakes and how to avoid them.
Wrong Pin Connection
One of the most common mistakes is connecting the wrong pins of the push button.
- Using pins from the same side (already connected internally)
- Not using opposite pins
👉 Always connect pins from opposite sides of the button.
Floating Input
If you don’t use a resistor, the Arduino input pin may read random values.
This is called a floating input.
- LED may turn ON/OFF randomly
- Serial values may change without pressing the button
👉 Always use a pull-down or pull-up resistor.
No Resistor
Some beginners skip using a resistor to simplify the circuit.
Without a resistor:
- Input becomes unstable
- Circuit may not work properly
👉 Always use a 10kΩ resistor for push button circuits.
Button Not Working
If your button is not working, check the following:
- Loose or incorrect wiring
- Wrong pin number in code
- Incorrect resistor placement
- Code not uploaded properly
{alertWarning} ⚠️ Tip: Always double-check your connections and code before troubleshooting further.
Most problems can be solved by checking these basic things. Once fixed, your circuit should work perfectly.
Applications of Push Button
At first, a push button may look like a very simple component. But once you understand how it works, you will start noticing it everywhere in real-world systems.
This small input device is used to control actions, select options, and interact with electronic systems.
Switch Control
Push buttons are widely used as switches to control devices.
- Turn LEDs ON/OFF
- Control motors or relays
- Start or stop a system
This is exactly what you learned in the toggle mode.
Menu Selection
Push buttons are used in systems where users need to select options.
- Navigating menus on displays
- Selecting modes in devices
- Changing settings
With multiple buttons, you can build full menu-based systems.
User Input Systems
Push buttons allow users to interact with Arduino projects.
- Keypads and control panels
- Game controllers
- Home automation switches
This makes your projects interactive instead of automatic.
So even though this tutorial started with a simple button, the concept you learned is used in many advanced applications.
Frequently Asked Questions (FAQ)
{alertInfo} Quick answers to common questions about push button in Arduino.
What is push button in Arduino?
A push button is an input device used to send signals to the Arduino. When you press it, it sends a HIGH signal, and when you release it, it sends a LOW signal.
Why is my button not working?
This usually happens due to small mistakes like:
- Wrong pin connection
- No resistor used
- Loose wiring
- Incorrect code or pin number
Check these points, and your button should work correctly.
What is HIGH and LOW?
These are digital signals used by Arduino:
- HIGH (1) → Button is pressed
- LOW (0) → Button is not pressed
Arduino uses these values to understand input and control outputs.
How does toggle work?
Toggle means switching between ON and OFF states.
Each time you press the button, the state changes:
- First press → ON
- Next press → OFF
This is done using logic that detects a button press and flips the current state.
Final Thoughts
Now you can control Arduino using a button — and this is a big step forward in your learning journey.
So far, you have learned how to read input signals and use logic to control behavior. This is how real electronic systems work — they respond based on user actions.
Through this tutorial, you have understood:
- How a push button works
- How Arduino reads input (HIGH / LOW)
- How to use toggle logic for ON/OFF control
When I first learned this, I realized that this simple concept can be used to build many real-world systems.
👉 This is just the beginning.
In the next step, we will use this button to control real devices like LEDs, relays, and sensors.
{alertSuccess} Next Step: Build a button-controlled project and take your Arduino skills to the next level 🚀
Thank you for reading this tutorial. If you have any questions, feel free to leave a comment — we will try to respond as soon as possible.



