Arduino ezButton Library: Wiring, Code and Simulator

To build this Arduino ezButton Library project you need an Arduino Uno and a push button. The same debounced press counter with the ezButton library. Make the 2 connections in the wiring table, upload the Arduino C++ code, and use button.isReleased() to count releases instead.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1push buttonConnects 1 to 2 while held. Pair with INPUT_PULLUP and wire the other side to GND.

Wiring

#FromTo
1Arduino Uno pin 2push button 2.l
2Arduino Uno GNDpush button 1.r

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add a push button from the parts palette.
  3. Wire 1. Connect Arduino Uno pin 2 to push button 2.l.
  4. Wire 2. Connect Arduino Uno GND to push button 1.r.
  5. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  6. Run it. Press Run. Use button.isReleased() to count releases instead.

Arduino C++ code

// ezButton: the same press counter with the ezButton library.
#include <ezButton.h>

ezButton button(2);
int presses = 0;

void setup() {
  Serial.begin(9600);
  button.setDebounceTime(20);
}

void loop() {
  button.loop();
  if (button.isPressed()) {
    presses++;
    Serial.print("Presses: ");
    Serial.println(presses);
  }
}

What to try

Use button.isReleased() to count releases instead.

Frequently asked questions

How do I wire the ezButton Library project on an Arduino Uno?

Make 2 connections: Arduino Uno pin 2 to push button 2.l; Arduino Uno GND to push button 1.r.

What parts do I need for this Arduino project?

An Arduino Uno and a push button.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

The same debounced press counter with the ezButton library.

More Arduino Uno projects