Source: https://mokxi.com/libraries/ezbutton
Updated: 2026-11-11

Libraries / Input

Arduino library · Input

# ezButton: a debounced button in four lines

ezButton, from ArduinoGetStarted.com, is the button library many beginner tutorials start with. You make one object per button, set a debounce time, call loop() on it every pass, and ask isPressed() or isReleased(). Both are events: they are true once, on the pass where the press or release happened, so a held button does not keep firing.

Open the example in the editor See the calls

Built in on Mokxi: #include <ezButton.h> and it builds, with nothing to install. Free, and no account needed.

## What ezButton does

By default the pin uses the board’s internal pull-up, so the button goes between the pin and GND with no resistor, and pressed reads as LOW. ezButton also counts presses for you with getCount(), and setCountMode() decides whether it counts presses, releases or both. getState() gives the steady, debounced level when you need to know whether the button is down right now.

One detail matters: the debounce time starts at 0, which means no debouncing at all. A real button bounces for a few milliseconds and would be counted several times, so always call setDebounceTime(50) in setup(), as the runnable example does. The simulated button bounces like a typical one, so you can see the difference by taking that line out.

Library Manager name | ezButton

Author | ArduinoGetStarted.com

Include | #include <ezButton.h>

Boards | every board Mokxi compiles for

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Pushbutton

## Install it

It builds on every board Mokxi compiles for.

In Mokxi it is built in: #include <ezButton.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "ezButton" by ArduinoGetStarted.com from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add ezButton to lib_deps in PlatformIO. Mokxi follows the calls of release 1.0.6, so a sketch written here builds there too.

- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- ATtiny85
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### ezButton button(2)

A button on pin 2 with the internal pull-up on. Wire it between the pin and GND.

### button.setDebounceTime(50)

A level must hold for 50 ms before it counts. The default is 0, so set it.

### button.loop()

Reads and debounces the pin. Call it first thing in loop(), every pass; the other calls report what it saw.

### button.isPressed()

True on the one pass where a press was confirmed.

### button.isReleased()

True on the one pass where the button was let go.

### button.getState()

The steady level: LOW while pressed with the default pull-up, HIGH while released.

### button.getCount()

How many presses so far. resetCount() sets it back to zero, and setCountMode(COUNT_BOTH) counts releases too.

## Example: Pressed and released, debounced

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 2 to Pushbutton 1a
- Arduino Uno R3 GND to Pushbutton 2a

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### One press is counted two or three times

The debounce time is still 0, its default. Add button.setDebounceTime(50) in setup(); raise it to 80 or 100 for a particularly noisy switch.

### isPressed() never becomes true

button.loop() is not being called, or is called only now and then. It must run on every pass of loop(), before isPressed(), and loop() must not sit in long delays.

### The button reads pressed all the time

It is wired to 5 V while the default pull-up mode expects GND. Move the wire to GND, or create the button with ezButton(2, INTERNAL_PULLDOWN) on a board that has pull-downs.

## Keep going

### Learn

- Arduino Button Debounce: See the Bounce, Then Fix It
- Arduino Button Counter: Count Presses, Not Bounces

### Parts

- Pushbutton

### More input libraries

- XPT2046_Touchscreen
- Keypad
- OneButton
- Encoder
- RotaryEncoder
- CapacitiveSensor
- IRremote
- Adafruit MCP23017 Arduino Library

Every built-in library · Open the editor

## Try ezButton without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
