Arduino UNO Q - Button

The push button is one of the most fundamental components in Arduino projects. This tutorial teaches you everything you need to use a button correctly with Arduino UNO Q — from reading its state to detecting press and release events, and even checking the button state remotely via Telegram.

※ NOTE THAT:

Before we begin, here are two common beginner mistakes to watch out for:

  1. Floating input problem:
  • Symptom: The button pin reads unpredictable values even when the button is not pressed.
  • Cause: No pull-up or pull-down resistor is connected.
  • Solution: Use INPUT_PULLUP mode in Arduino code — this enables the internal pull-up resistor and requires no external component.
  1. Chattering phenomenon:
  • Symptom: One physical press registers as multiple press events.
  • Cause: Mechanical bouncing causes rapid HIGH/LOW transitions.
  • Solution: Implement debounce. See the Arduino UNO Q - Button Debounce tutorial.

Chattering only affects applications that need a precise count of presses. For simple ON/OFF control, it usually does not matter.

Arduino UNO Q - Button

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
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
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

A push button (also known as a tactile button or momentary switch) is closed while held down and opens when released. Common types include:

  • PCB-mount buttons — can be used on a breadboard
  • Panel-mount buttons — for mounting in enclosures
Arduino UNO Q Push button

Pinout

PCB-mount buttons usually have four pins — connected in pairs internally. Only two pins (not the internally-connected pair) are needed.

Button Pinout
How To Use Button

Panel-mount buttons have two pins:

two-pin push button Pinout

How It Works

  • When the button is not pressed: pin A and pin B are disconnected
  • When the button is pressed: pin A and pin B are connected
How Button Works

Button Connection and Logic

Connect one button pin to GND and the other to an Arduino UNO Q pin configured as INPUT_PULLUP:

  • Button not pressed → pin reads HIGH
  • Button pressed → pin reads LOW

※ NOTE THAT:

Using INPUT_PULLUP enables the internal pull-up resistor — no external resistor is required. This is the recommended approach for beginners.

Wiring Diagram

  • Wiring for PCB-mount button:
The wiring diagram between Arduino UNO Q Button

This image is created using Fritzing. Click to enlarge image

  • Wiring for panel-mount button:
The wiring diagram between Arduino UNO Q Panel Button

This image is created using Fritzing. Click to enlarge image

How To Program a Button

Set the button pin as input with internal pull-up:

pinMode(7, INPUT_PULLUP);

Read the button state:

int button_state = digitalRead(BUTTON_PIN); // LOW = pressed, HIGH = not pressed

※ NOTE THAT:

Two common use-cases:

  • Level-based: If HIGH → do action A; if LOW → do action B (e.g., turn LED on while held)
  • Edge-based: When state changes from HIGH to LOW → press event; LOW to HIGH → release event (e.g., toggle LED on each press)

MCU Code — Reading Button State

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.

This sketch reads the button state and makes the result available for use (e.g., to control an LED or report via 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-button */ #define BUTTON_PIN 7 // The Arduino UNO Q pin connected to the button void setup() { // initialize the pushbutton pin as a pull-up input // (no external resistor needed — internal pull-up is used) pinMode(BUTTON_PIN, INPUT_PULLUP); } void loop() { // read the state of the button (LOW = pressed, HIGH = not pressed) int button_state = digitalRead(BUTTON_PIN); // TO DO: use button_state here (e.g., control an LED or send via Bridge) delay(100); }

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 button: Connect one button pin to GND and the other to pin 7 according to the wiring diagram.
  • 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_Button
  • 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 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 button: Press and hold the button, then release it.
    • See the state: To see button state output in real time, see the Bridge section below — it adds a get_button_state() function and shows state via the MCU Monitor console.
    • Pro Tip: Use button_state == LOW to check if the button is pressed (because INPUT_PULLUP inverts the logic).

    MCU Code — Detecting Button Press and Release Events

    To detect individual press and release events, track state transitions between HIGH and LOW:

    /* * 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-button */ #define BUTTON_PIN 7 // The Arduino UNO Q pin connected to the button int button_state; int prev_button_state = HIGH; // HIGH = not pressed (pull-up) void setup() { // initialize the pushbutton pin as a pull-up input pinMode(BUTTON_PIN, INPUT_PULLUP); } void loop() { // read the state of the button (LOW = pressed, HIGH = not pressed) button_state = digitalRead(BUTTON_PIN); if (prev_button_state == HIGH && button_state == LOW) { // button was just pressed (HIGH → LOW transition) // TO DO: add your press action here } else if (prev_button_state == LOW && button_state == HIGH) { // button was just released (LOW → HIGH transition) // TO DO: add your release action here } // save the last state prev_button_state = button_state; }
    • How it works: Detects a HIGHLOW transition (button pressed) and a LOWHIGH transition (button released).
    • Pro Tip: Add action code inside the if blocks — for example, toggle an LED on press, or log an event on release.

    ※ NOTE THAT:

    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.

    • The button is connected to the MCU (STM32) — wired to a digital input pin on the STM32. The MCU reads the button state using digitalRead().
    • The MPU cannot read the button directly — it must request the current state from the MCU via Bridge.call(). The MCU executes the registered Bridge.provide() function and responds.
    • The MPU has Wi-Fi — because the MPU runs full Debian Linux with Wi-Fi, it can check the button state on demand and forward it via Telegram.
    • 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: MPU requests button state → MCU reads pin → MCU reports result → MPU logs or forwards it.

    MCU sketch — button with Bridge and Monitor output:

    /* * 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-button */ #include "Arduino_RouterBridge.h" #define BUTTON_PIN 7 int button_state; int prev_button_state = HIGH; void get_button_state() { button_state = digitalRead(BUTTON_PIN); int pressed = (button_state == LOW) ? 1 : 0; Monitor.println("Button state: " + String(pressed) + " (1=pressed, 0=released)"); } void setup() { pinMode(BUTTON_PIN, INPUT_PULLUP); Bridge.begin(); Monitor.begin(); Bridge.provide("get_button_state", get_button_state); Monitor.println("Button Bridge ready"); } void loop() { button_state = digitalRead(BUTTON_PIN); if (prev_button_state == HIGH && button_state == LOW) Monitor.println("Button PRESSED"); else if (prev_button_state == LOW && button_state == HIGH) Monitor.println("Button RELEASED"); prev_button_state = button_state; }

    Python script (Arduino App Lab) — poll button state 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-button */ from arduino.app_utils import * import time def loop(): while True: result = Bridge.call("get_button_state") print(f"Polled: {result}") time.sleep(0.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, keep the default 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 the button state every 0.5 seconds.
    • Press the button: Press and hold it, then release it.
    • Check the console: Open the Console tab → MCU Monitor subtab to see press/release events in real time.
    • Pro Tip: Also open the Python Console subtab to see the polled state values.

    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
    Button Bridge ready Button PRESSED Button RELEASED Button PRESSED Button RELEASED

    Telegram Integration

    You can check whether the button is currently pressed — from anywhere in the world — by sending a Telegram message to your Arduino UNO Q.

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

    This section covers:

    • Running a Python script on the Linux side of Arduino UNO Q to listen for Telegram messages
    • Polling the button state from the MCU via Bridge.call() on demand
    • Sending the button state back to Telegram as a reply

    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 button state:

    /* * 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-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 == "/state": result = Bridge.call("get_button_state") # result contains "1" (pressed) or "0" (not pressed) if "1" in str(result): send_message(chat_id, "Button is currently PRESSED") else: send_message(chat_id, "Button is currently NOT pressed") else: send_message(chat_id, "Commands:\n/state — check if the button is pressed") time.sleep(0.5) App.run(user_loop=loop)
    • Note: Replace YOUR_BOT_TOKEN with the token obtained from @BotFather on Telegram.
    • Send /state to check whether the button is currently pressed.

    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 immediately.
    • Test it: Open Telegram, find your bot, press the physical button on Arduino UNO Q, and then send /state to see if it reads as pressed.
    • Pro Tip: Combine with an LED — light it up when the button is detected as pressed via Bridge.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 12:00:01] Telegram: /state [2026-04-29 12:00:01] Button is currently NOT pressed [2026-04-29 12:01:30] Telegram: /state [2026-04-29 12:01:30] Button is currently PRESSED
    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
    /state
    10:15 AM ✓✓
    Button is currently NOT pressed
    10:16 AM
    /state
    10:17 AM ✓✓
    Button is currently PRESSED
    10:18 AM

    OpenClaw Integration

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

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

    Application/Project Ideas

    Here are some project ideas using a button with Arduino UNO Q:

    • Remote doorbell: Press the button → Telegram sends "Someone is at the door!" to your phone
    • Emergency alert: Press and hold for 3 seconds → Telegram sends an alert message
    • Event counter: Count button presses on the MCU and send the total via Telegram on demand
    • Light switch: Press button → turn on a connected light; press again → turn it off
    • Two-mode system: Short press selects mode A, long press selects mode B — each triggers a different Python action

    Challenge Yourself

    Try these challenges with buttons on Arduino UNO Q:

    • Easy: Modify the Bridge sketch to turn on the built-in LED when the button is pressed and turn it off when released
    • Medium: Extend the Bridge sketch to expose a get_press_count() function that returns how many times the button has been pressed since power-on
    • Advanced: Build a Telegram bot that sends a message automatically (without polling) whenever the button is pressed — use a background loop in Python to monitor state changes via Bridge

    Function References

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