. Arduino UNO R4 multiple Button | Arduino UNO R4 Tutorial
Arduino UNO R4 multiple Button | Arduino UNO R4 Tutorial
Arduino UNO R4 multiple Button | Arduino UNO R4 Tutorial

Arduino UNO R4 multiple Button

This guide shows you how to use an Arduino UNO R4 with multiple buttons at the same time without the delay () function to debounce. The guide offers code in two different methods:

Arduino UNO R4 code debounces multiple buttons without using delay() function. Arduino UNO R4 code debounces multiple buttons using arrays without using delay() function .

We will use five buttons as examples. You can change this easily for two buttons, four buttons, or even more.

Hardware Preparation

1×Arduino UNO R4 WiFi or Arduino UNO R4 Minima 1× Alternatively, DIYables STEM V4 IoT, Compatible with Arduino Uno R4 WiFi 1×USB Cable Type-A to Type-C (for USB-A PC) 1×USB Cable Type-C to Type-C (for USB-C PC) 1×Breadboard-mount Button with Cap 1×Breadboard-mount Button Kit 1×Panel-mount Button 1×Push Button Module 1×Breadboard 1×Jumper Wires 1× Recommended: Screw Terminal Block Shield for Arduino UNO R4 1× Recommended: Breadboard Shield for Arduino UNO R4 1× Recommended: Enclosure for Arduino UNO R4 1× Recommended: Power Splitter for Arduino UNO R4 1× Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. Additionally, some of these links are for products from our own brand, DIYables .

Overview of Button

We offer a detailed guide on buttons, covering hardware connections, how they work, wiring with Arduino UNO R4, and how to write the code. Learn more here:

Wiring Diagram

This image is created using Fritzing. Click to enlarge image

Arduino UNO R4 Code - Multiple Buttons with debounce

When using several buttons, situations can become complex.

Applications that need button debouncing Applications that must identify when buttons are pressed or released

The ezButton library simplifies working with buttons by handling debounce and button events internally. Users do not need to worry about managing timestamps and variables when using this library. Also, using multiple buttons can make the code clearer and shorter.

Detailed Instructions

Follow these instructions step by step:

If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.

Connect the Arduino Uno R4 to the buttons according to the provided diagram. Connect the Arduino Uno R4 board to your computer using a USB cable. Launch the Arduino IDE on your computer. Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi ) and COM port. Click on the Libraries icon on the left side of the Arduino IDE. Search for ezButton and locate the button library created by ArduinoGetStarted.com. Click on the Install button to install the ezButton library. Copy the code and paste it into Arduino IDE. Click the Upload button in Arduino IDE to compile and upload the code to the Arduino UNO R4 board. Open the Serial Monitor in the Arduino IDE. Press and release each button one at a resource time.

The button 1 is pressed The button 1 is released The button 2 is pressed The button 2 is released The button 3 is pressed The button 3 is released The button 4 is pressed The button 4 is released The button 5 is pressed The button 5 is released

Autoscroll Show timestamp Clear output

Arduino UNO R4 Code - Multiple Buttons using array

We can make the above code better by using an array of buttons.

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-multiple-button */ # include < ezButton .h># define BUTTON_NUM 5 // the number of buttons # define BUTTON_PIN_1 2 // The Arduino UNO R4 pin connected to the button 1 # define BUTTON_PIN_2 3 // The Arduino UNO R4 pin connected to the button 2 # define BUTTON_PIN_3 4 // The Arduino UNO R4 pin connected to the button 3 # define BUTTON_PIN_4 5 // The Arduino UNO R4 pin connected to the button 4 # define BUTTON_PIN_5 6 // The Arduino UNO R4 pin connected to the button 5 ezButton buttonArray [] = < ezButton (BUTTON_PIN_1), ezButton (BUTTON_PIN_2), ezButton (BUTTON_PIN_3), ezButton (BUTTON_PIN_4), ezButton (BUTTON_PIN_5) >; void setup () < Serial . begin (9600); for ( byte i = 0; i < BUTTON_NUM; i++) < buttonArray [i]. setDebounceTime (100); // set debounce time to 100 milliseconds >> void loop () < for ( byte i = 0; i < BUTTON_NUM; i++) buttonArray[i]. loop (); // MUST call the loop() function first for ( byte i = 0; i < BUTTON_NUM; i++) < // get button state after debounce int button_state = buttonArray[i]. getState (); // the state after debounce /* Serial.print("The button "); Serial.print(i + 1); Serial.print(": "); Serial.println(button_state); */ if (buttonArray[i]. isPressed ()) < Serial . print ( "The button " ); Serial . print (i + 1); Serial . println ( " is pressed" ); >if (buttonArray[i]. isReleased ()) < Serial . print ( "The button " ); Serial . print (i + 1); Serial . println ( " is released" ); >> >

Video Tutorial

Learn More

※ OUR MESSAGES

As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us

Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!

DISCLOSURE

Newbiely.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com, Amazon.it, Amazon.fr, Amazon.co.uk, Amazon.ca, Amazon.de, Amazon.es, Amazon.nl, Amazon.pl and Amazon.se

Copyright © 2026 Newbiely.com. All rights reserved. Terms and Conditions | Privacy Policy Email: newbiely.com@gmail.com

TABLE OF CONTENTS

  • Hardware Preparation
  • Overview of Button
  • Wiring Diagram
  • Arduino UNO R4 Code - Multiple Buttons with debounce
  • Arduino UNO R4 Code - Multiple Buttons using array
  • Video
  • Learn More
📎📎📎📎📎📎📎📎📎📎