Arduino - Button Module
In this tutorial, we are going to learn:
- What is inside a button module, and why it needs no extra resistor
- How to hook the button module up to Arduino Uno with three jumper wires
- How to program Arduino to print the raw HIGH/LOW level of the button
- How to program Arduino to report each press and each release, first with a simple delay() debounce, then with the non-blocking ezButton library

Hardware Required
Or you can buy the following kits:
| 1 | × | DIYables STEM V3 Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some links direct to products from our own brand, DIYables .
About Button Module
In short, a button module is a push button with its resistor already on board. The tactile switch, a colored cap and a pull-down resistor sit together on a small PCB. While nobody touches the cap, the resistor holds the OUT pin at LOW. Push the cap and the switch links OUT to VCC, so the pin goes HIGH. Release it and OUT falls back to LOW. Arduino just has to read that one pin.
One thing to keep in mind: a switch is a piece of metal hitting metal. For a few milliseconds after each push or release, the contacts bounce, so one press can look like several quick presses to a fast Arduino. The second and third examples below show how to filter this out.
The module comes in a pack of five, one cap of each color: red, yellow, green, blue and white. They are wired the same way inside, so you can pick colors by job, for example green for "start" and red for "stop".
| Button Module | |
|---|---|
| Switch Type | momentary tactile push button |
| Cap Colors | red, yellow, green, blue, white |
| Operating Voltage | 3.3V to 5V DC |
| On-board Resistor | pull-down on the OUT pin |
| Output Logic | LOW = released, HIGH = pressed |
| Header | 3-pin, 2.54mm |

From left to right, the header is labeled VCC, OUT, GND.
- VCC pin: needs to be connected to the 3.3V or the 5V pin of the Arduino Uno. When the button is pressed, this voltage appears on OUT.
- OUT pin: needs to be connected to an Arduino digital input pin. It reads LOW at rest and HIGH while the cap is held down.
- GND pin: needs to be connected to GND (0V)
Why pick the module over the bare 4-leg button from the Arduino - Button tutorial?
- The bare button has four legs joined in pairs, and it is easy to wire the wrong pair. The module has three printed labels instead.
- The bare button floats when it is not pressed, so you must add a pull-up or pull-down resistor, or use INPUT_PULLUP. The module brings its own pull-down.
- With INPUT_PULLUP, a bare button reads LOW when pressed, which feels backward. The module is not inverted: pressed is HIGH.
Wiring Diagram
Run three wires: module VCC to the Arduino 3.3V pin, module OUT to digital pin 7, and module GND to an Arduino GND pin. The 5V pin works for VCC too, so you can use either one.

This image is created using Fritzing. Click to enlarge image
Pin 7 is only a choice. Any digital pin from 2 to 13 can read the module; just change the pin number at the top of the code to match.
How To Program For Button Module
- Define the Arduino pin that the OUT wire goes to:
- Configure that pin as a plain input with pinMode(). Do not use INPUT_PULLUP here. The internal pull-up would fight the module's own pull-down resistor.
- Read the level with digitalRead(). HIGH means the cap is pushed down:
Arduino Code - Read Button Module State
The first sketch does nothing clever. It reads pin 7 five times per second and prints the number it gets: 1 while the button is held, 0 when it is free. It is a quick way to prove that the wiring is right before you build anything on top of it.
Quick Steps
- Connect Arduino to PC via USB cable.
- Plug the three wires between the button module and Arduino, following the wiring diagram.
- Open Arduino IDE, select the right board and port.
- Copy the above code and paste it to Arduino IDE.
- Click Upload button on Arduino IDE to upload code to Arduino.
- Open the Serial Monitor and set the baud rate to 9600.
- Hold the button down for about one second, then let it go.
If the value stays at 0 no matter what you do, check that OUT really goes to pin 7 and that VCC is on the 3.3V or 5V pin, not on a free header hole.
Arduino Code - Button Module Press and Release with delay()
Most projects do not care about the level itself. A doorbell, a "next song" button or a start/stop key only needs to know the moment the button goes down or comes up. This sketch remembers the last state. When a new reading is different, it waits 50 ms for the bounce to settle, reads the pin again, and only then prints a message.
Quick Steps
- Keep the wiring from the first example.
- Copy the above code and paste it to Arduino IDE.
- Click Upload button on Arduino IDE to upload code to Arduino.
- Open the Serial Monitor (baud rate 9600).
- Press and release the button three times.
Each press now gives exactly one "pressed" line and one "released" line. The cost is that delay() freezes the whole loop for 50 ms every time the pin changes, so nothing else can run during that wait.
For a deeper look at bouncing and a millis() version of this idea, see Arduino - Button - Debounce.
Arduino Code - Button Module with ezButton Library
The ezButton library does the same debounce job without ever stopping the loop. Each time button.loop() runs, it takes a quick look at the pin and checks the clock, then returns at once. This leaves Arduino free to blink LEDs, read sensors or drive a motor at the same time, which matters in something like a game controller where you cannot afford to pause.
Because the module pulls OUT down, the button object is created with EXTERNAL_PULLDOWN. This tells the library that HIGH means pressed. This option needs ezButton version 1.0.6 or newer.
The functions used in the sketch:
- button.setDebounceTime(50): ignore any change shorter than 50 ms.
- button.loop(): must be called first in every loop().
- button.isPressed() / button.isReleased(): true only once, right when the event happens.
- button.getState(): the steady, debounced level (HIGH = pressed).
Quick Steps
- Keep the same wiring.
- In Arduino IDE, click the Libraries icon on the left bar.
- Search "ezButton" and find the library by ArduinoGetStarted.com.
- Click the Install button. If an older version is installed, update it to 1.0.6 or newer.
- Search for ezButton created by ArduinoGetStarted.com and click the Install button.
- Copy the above code and paste it to Arduino IDE.
- Click Upload button on Arduino IDE to upload code to Arduino.
- Open the Serial Monitor (baud rate 9600).
- Press the button, hold it a moment, then release it. Do it twice.
※ NOTE THAT:
If every line comes out backward (pressed when you let go), the library is treating the pin as pull-up. Check that the object is created with EXTERNAL_PULLDOWN and that your ezButton version is 1.0.6 or newer.
Next, you can use the module to switch something real, as in Arduino - Button - LED.
Video Tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.
The Best Arduino Starter Kit
See Also
※ OUR MESSAGES
- We are AVAILABLE for HIRE. See how to hire us to build your project
- If this tutorial is useful for you, please give us motivation to make more tutorials.
- You can share the link of this tutorial anywhere. Howerver, please do not copy the content to share on other websites. We took a lot of time and effort to create the content of this tutorial, please respect our work!
Terms and Conditions | Privacy Policy