Arduino UNO Q multiple Button

Managing multiple buttons simultaneously on Arduino UNO Q is easy with the right approach. In this tutorial, you will learn how to handle five buttons at once using the ezButton library — with full debounce and press/release detection — and then extend the project to track press counts remotely via Telegram.

In this tutorial, you will learn:

Arduino UNO Q - Multiple Buttons

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
5×Breadboard-mount Button with Cap
1×Breadboard-mount Button Kit
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
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

Learn about buttons (pinout, wiring, debounce) in these tutorials:

Wiring Diagram

The wiring diagram between Arduino UNO Q Multiple Button

This image is created using Fritzing. Click to enlarge image

MCU Code — Multiple Buttons with Debounce

The Arduino UNO Q has two processors: the STM32 MCU (handles real-time hardware control) and the Qualcomm MPU (runs Debian Linux). In this section, only the STM32 MCU is programmed — the Linux side stays idle. A later section will show how both processors work together.

The ezButton library handles debounce and press/release detection for each button automatically — no manual timestamp tracking required:

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-multiple-button */ #include <ezButton.h> #define BUTTON_NUM 5 #define BUTTON_PIN_1 2 // The Arduino UNO Q pin connected to button 1 #define BUTTON_PIN_2 3 // The Arduino UNO Q pin connected to button 2 #define BUTTON_PIN_3 4 // The Arduino UNO Q pin connected to button 3 #define BUTTON_PIN_4 5 // The Arduino UNO Q pin connected to button 4 #define BUTTON_PIN_5 6 // The Arduino UNO Q pin connected to button 5 ezButton button1(BUTTON_PIN_1); ezButton button2(BUTTON_PIN_2); ezButton button3(BUTTON_PIN_3); ezButton button4(BUTTON_PIN_4); ezButton button5(BUTTON_PIN_5); void setup() { button1.setDebounceTime(100); button2.setDebounceTime(100); button3.setDebounceTime(100); button4.setDebounceTime(100); button5.setDebounceTime(100); } void loop() { button1.loop(); // MUST call the loop() function first button2.loop(); button3.loop(); button4.loop(); button5.loop(); if (button1.isPressed()) { /* TO DO: button 1 pressed action */ } if (button1.isReleased()) { /* TO DO: button 1 released action */ } if (button2.isPressed()) { /* TO DO: button 2 pressed action */ } if (button2.isReleased()) { /* TO DO: button 2 released action */ } if (button3.isPressed()) { /* TO DO: button 3 pressed action */ } if (button3.isReleased()) { /* TO DO: button 3 released action */ } if (button4.isPressed()) { /* TO DO: button 4 pressed action */ } if (button4.isReleased()) { /* TO DO: button 4 released action */ } if (button5.isPressed()) { /* TO DO: button 5 pressed action */ } if (button5.isReleased()) { /* TO DO: button 5 released action */ } }

Detailed Instructions

  • First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial to get your development environment ready before proceeding.
  • Wire the buttons: Connect five buttons to pins 2–6 according to the wiring diagram. Each button has one pin on GND and the other on the signal pin.
  • Connect: Plug the Arduino UNO Q into your computer with a USB-C cable.
  • Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
  • Create a new App: Click the Create New App button.
Create New App in Arduino App Lab on Arduino UNO Q
  • Give the App a name, for example: DIYables_MultiButton
  • Click Create to confirm.
  • You will see a set of folders and files generated inside your new App.
Arduino App Lab App folders and files on Arduino UNO Q
  • Find the sketch/sketch.ino file — this is where you will paste the MCU sketch.
  • Paste the sketch: Copy the MCU code above and paste it into the sketch file. Keep other files as default.
    • Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.
    Add sketch library in Arduino App Lab on Arduino UNO Q
    • Search for ezButton created by ArduinoGetStarted.com and click the Install button.
    My Apps / DIYables Apps
    Run
    Bricks
    No bricks added...
    Sketch Libraries
    No sketch libra...
    Files
    python
    sketch
    .gitignore
    README.md
    app.yaml
    sketch.ino
    Add sketch library
    ezButton ArduinoGetStarted.com

    Button library supports debounce, pressed/released events and the press counting. It is easy to use with multiple buttons. The library can be used for push-button, momentary switches, toggle switch, magnetic contact switch (door sensor)... It is designed for not only beginners but also experienced users.

    1.0.6
    Install
    More Info
    • Search for Arduino_RouterBridge created by Arduino and click the Install button.
    My Apps / DIYables Apps
    Run
    Bricks
    No bricks added...
    Sketch Libraries
    No sketch libra...
    Files
    python
    sketch
    .gitignore
    README.md
    app.yaml
    sketch.ino
    Add sketch library
    Arduino_RouterBridge Arduino

    This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.

    0.4.1
    Install
    More Info
    • Upload: Click the Run button in Arduino App Lab to compile and upload to the STM32.
    Click Run button in Arduino App Lab on Arduino UNO Q
    • Press the buttons one at a time — press and release each button and see the result in the Bridge section below.
    • Pro Tip: Add action code inside each isPressed() / isReleased() block to control LEDs, servos, or other components.

    Cleaner Code with a Button Array

    Using an array of ezButton objects makes the code scalable — adding more buttons only requires changing BUTTON_NUM:

    /* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-multiple-button */ #include <ezButton.h> #define BUTTON_NUM 5 #define BUTTON_PIN_1 2 // The Arduino UNO Q pin connected to button 1 #define BUTTON_PIN_2 3 // The Arduino UNO Q pin connected to button 2 #define BUTTON_PIN_3 4 // The Arduino UNO Q pin connected to button 3 #define BUTTON_PIN_4 5 // The Arduino UNO Q pin connected to button 4 #define BUTTON_PIN_5 6 // The Arduino UNO Q pin connected to 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() { for (byte i = 0; i < BUTTON_NUM; i++) buttonArray[i].setDebounceTime(100); } 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++) { if (buttonArray[i].isPressed()) { // TO DO: button (i+1) pressed action here } if (buttonArray[i].isReleased()) { // TO DO: button (i+1) released action here } } }
    • How it works: The loop processes all buttons generically using the array index. Each button's press/release events trigger independent actions.
    • Pro Tip: Add a counter array (int press_count[BUTTON_NUM] = {0}) and increment press_count[i] on each isPressed() to track how many times each button was pressed.

    Linux + MCU Bridge Programming

    The Arduino UNO Q has two processors that work together: the MPU (Qualcomm, runs Debian Linux) and the MCU (STM32, runs Zephyr OS with your Arduino sketch). They communicate using RPC via the Arduino_RouterBridge library — never via raw serial ports.

    • All buttons are connected to the MCU (STM32) — wired to digital input pins on the STM32. The MCU handles debounce and press counting using ezButton.
    • The MPU cannot read buttons directly — it must request data from the MCU via Bridge.call(). The MCU responds with press counts or resets them.
    • The MPU has Wi-Fi — because the MPU runs full Debian Linux with Wi-Fi, it can forward press counts via Telegram and accept reset commands remotely.
    • Communication: Bridge.call() on the Linux side invokes Bridge.provide() functions on the MCU side
    • ⚠️ Reserved: /dev/ttyHS1 (Linux) and Serial1 (MCU) are used by the Arduino Router — never open them directly

    In short: MCU counts button presses → MPU requests counts → MPU forwards them via Telegram.

    MCU sketch — multiple buttons with press counting and Bridge:

    /* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-multiple-button */ #include "Arduino_RouterBridge.h" #include <ezButton.h> #define BUTTON_NUM 5 #define BUTTON_PIN_1 2 #define BUTTON_PIN_2 3 #define BUTTON_PIN_3 4 #define BUTTON_PIN_4 5 #define BUTTON_PIN_5 6 ezButton buttonArray[] = { ezButton(BUTTON_PIN_1), ezButton(BUTTON_PIN_2), ezButton(BUTTON_PIN_3), ezButton(BUTTON_PIN_4), ezButton(BUTTON_PIN_5) }; int press_count[BUTTON_NUM] = {0}; void get_press_counts() { String msg = "Press counts: "; for (int i = 0; i < BUTTON_NUM; i++) { msg += "B" + String(i + 1) + "=" + String(press_count[i]); if (i < BUTTON_NUM - 1) msg += ", "; } Monitor.println(msg); } void reset_counts() { for (int i = 0; i < BUTTON_NUM; i++) press_count[i] = 0; Monitor.println("All press counts reset"); } void setup() { for (byte i = 0; i < BUTTON_NUM; i++) buttonArray[i].setDebounceTime(100); Bridge.begin(); Monitor.begin(); Bridge.provide("get_press_counts", get_press_counts); Bridge.provide("reset_counts", reset_counts); Monitor.println("Multiple Button Bridge ready"); } void loop() { for (byte i = 0; i < BUTTON_NUM; i++) buttonArray[i].loop(); for (byte i = 0; i < BUTTON_NUM; i++) { if (buttonArray[i].isPressed()) { press_count[i]++; Monitor.println("Button " + String(i + 1) + " PRESSED (count: " + String(press_count[i]) + ")"); } if (buttonArray[i].isReleased()) Monitor.println("Button " + String(i + 1) + " RELEASED"); } }

    Python script (Arduino App Lab) — poll press counts from Linux:

    /* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-multiple-button */ from arduino.app_utils import * import time def loop(): while True: counts = Bridge.call("get_press_counts") print(f"Button press counts: {counts}") time.sleep(5) App.run(user_loop=loop)
    • Note: Make sure Bridge.begin() is called in the MCU sketch and the sketch is uploaded before running the Python script on the Linux side.
    • ⚠️ Warning: Never directly open /dev/ttyHS1 (on Linux) or use Serial1 (on MCU) in your code — these are reserved by the Arduino Router and accessing them will break the Bridge.

    Detailed Instructions

    • Upload the MCU sketch: Open Arduino App Lab, create a new App, paste the Bridge MCU sketch above into sketch/sketch.ino, install the ezButton and Arduino_RouterBridge libraries, and click Run.
    • Add the Python script: Paste the Python code above into the Python tab of the same App.
    • Run the App: Click Run — the Python side polls press counts every 5 seconds.
    • Press the buttons several times.
    • Check the console: Open the Console tab → MCU Monitor subtab to see press/release events.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    Message (Enter to send a message to "Newbiely" on usb(2820070321))
    New Line
    9600 baud
    Multiple Button Bridge ready Button 1 PRESSED (count: 1) Button 1 RELEASED Button 3 PRESSED (count: 1) Button 3 RELEASED Button 5 PRESSED (count: 1) Button 5 RELEASED

    Telegram Integration

    Query button press counts or reset them remotely over Telegram.

    If you do not have a Telegram bot yet, see How to Create a Telegram Bot to get your bot token before continuing.

    MCU sketch: Keep the same MCU sketch from the previous Bridge section — no changes needed. Make sure it is already uploaded and running on the STM32 before proceeding.

    Python script (Arduino App Lab) — Telegram bot for multiple button tracking:

    /* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-multiple-button */ from arduino.app_utils import * import requests import time BOT_TOKEN = "YOUR_BOT_TOKEN" API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" last_update_id = 0 def send_message(chat_id, text): requests.post(f"{API_URL}/sendMessage", json={"chat_id": chat_id, "text": text}) def get_updates(): global last_update_id resp = requests.get(f"{API_URL}/getUpdates", params={"offset": last_update_id + 1, "timeout": 5}) return resp.json().get("result", []) def loop(): global last_update_id updates = get_updates() for update in updates: last_update_id = update["update_id"] msg = update.get("message", {}) chat_id = msg.get("chat", {}).get("id") text = msg.get("text", "").strip() if text == "/counts": counts = Bridge.call("get_press_counts") send_message(chat_id, f"Button press counts:\n{counts}") elif text == "/reset": Bridge.call("reset_counts") send_message(chat_id, "All press counts reset to 0") else: send_message(chat_id, "Commands:\n/counts — get all button press counts\n/reset — reset all counts to 0") time.sleep(1) App.run(user_loop=loop)
    • Note: Replace YOUR_BOT_TOKEN with the token obtained from @BotFather on Telegram.
    • Send /counts to get all five button press counts.
    • Send /reset to reset all counts to zero.

    Detailed Instructions

    • Upload the MCU sketch: Use the Bridge MCU sketch from the previous section (upload it first if not already done).
    • Paste the Telegram script: Copy the Python code above into the Python tab of your App in Arduino App Lab.
    • Set your token: Replace YOUR_BOT_TOKEN in the script with your actual bot token.
    • Run the App: Click Run — the bot starts listening for Telegram messages.
    • Test it: Press each button a few times, then send /counts on Telegram. Then send /reset to clear all counts.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 12:00:01] Telegram: /counts [2026-04-29 12:00:01] Button press counts: B1=3, B2=1, B3=5, B4=0, B5=2 [2026-04-29 12:01:10] Telegram: /reset [2026-04-29 12:01:10] All press counts reset to 0
    Telegram
    Telegram 12:45
    Welcome to Telegram!
    ArduinoBot 10:19
    Chatting with Arduino...
    telegram-botfather
    BotFather Yesterday
    Your bot has been created.

    ArduinoBot

    bot
    Today
    /counts
    10:15 AM ✓✓
    Button press counts: B1=3, B2=1, B3=5, B4=0, B5=2
    10:16 AM
    /reset
    10:17 AM ✓✓
    All press counts reset to 0
    10:18 AM

    OpenClaw Integration

    OpenClaw integration for Arduino UNO Q multiple button reading is coming soon.

    • Coming Soon: OpenClaw support for reading multiple button states on Arduino UNO Q will be covered in a future update.

    Application/Project Ideas

    • Keyboard panel: Each button sends a different Telegram message — useful for quick presets or commands
    • Vote counter: Each button records a vote for a different option; query results via Telegram
    • Mode selector: Press button 1 for mode A, button 2 for mode B — each triggers a different action on the MPU
    • Multi-zone alarm: Each button is tied to a different zone sensor; press counts log how many times each zone was triggered
    • Remote test panel: Press buttons to test different hardware features, with results sent via Telegram

    Challenge Yourself

    • Easy: Add a sixth button to the sketch on pin 7 and track its press count the same way
    • Medium: Modify the Bridge sketch to expose get_count(int button_num) so Python can query individual button counts instead of all at once
    • Advanced: Build a Telegram bot that sends an alert automatically when any button's press count exceeds a threshold (e.g., 10 presses)

    ※ 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!