Arduino UNO Q - Keypad 1x4

Want to add a simple 4-button keypad to your Arduino UNO Q project? In this tutorial, you will learn how to detect key presses with debouncing — and even send Telegram alerts when a key is pressed.

In this tutorial, you will learn:

Arduino UNO Q Keypad 1x4

Hardware Preparation

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

A 1x4 keypad has four buttons arranged in a single row. It is used for entering codes, navigating menus, or triggering actions in different projects.

Pinout

The 1x4 keypad has 5 pins. The pin order does not match the key order on the label:

  • Pin 1 → Key 2
  • Pin 2 → Key 1
  • Pin 3 → Key 4
  • Pin 4 → Key 3
  • Pin 5 → Common (GND)
Keypad 1x4 Pinout

Wiring Diagram

The wiring diagram between Arduino UNO Q Keypad 1x4

This image is created using Fritzing. Click to enlarge image

Keypad Pin Arduino UNO Q MCU
Pin 1 (Key 2) D2
Pin 2 (Key 1) D3
Pin 3 (Key 4) D4
Pin 4 (Key 3) D5
Pin 5 (Common) GND

Arduino UNO Q Code

The Arduino UNO Q has two processors working together:

  • The STM32 MCU reads the keypad pins directly with debouncing via the ezButton library
  • The Qualcomm MPU runs Debian Linux and handles Wi-Fi, Python, and cloud connectivity
  • In this section, only the MCU is programmed — the Linux side stays idle. A later section shows how both processors work together via Bridge.

Each key on the 1x4 keypad works like a button connected between a pin and GND. The ezButton library handles debouncing for all four keys automatically.

/* * 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-keypad-1x4 */ // COPYRIGHT newbiely.com // AUTHOR: newbiely // This code is made available for public use without restriction. // For complete instructions, tutorials, and further information, visit: // https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-keypad-1x4 #include <ezButton.h> #define KEY_NUM 4 #define PIN_KEY_1 3 // Arduino UNO Q MCU pin connected to key 1 #define PIN_KEY_2 2 // Arduino UNO Q MCU pin connected to key 2 #define PIN_KEY_3 5 // Arduino UNO Q MCU pin connected to key 3 #define PIN_KEY_4 4 // Arduino UNO Q MCU pin connected to key 4 ezButton keypad_1x4[KEY_NUM] = { ezButton(PIN_KEY_1), ezButton(PIN_KEY_2), ezButton(PIN_KEY_3), ezButton(PIN_KEY_4) }; void setup() { Serial.begin(115200); delay(1500); for (byte i = 0; i < KEY_NUM; i++) { keypad_1x4[i].setDebounceTime(100); } Serial.println("Arduino UNO Q Keypad 1x4 ready"); } void loop() { int key = getKeyPressed(); if (key) { Serial.print("Key pressed: "); Serial.println(key); } } int getKeyPressed() { for (byte i = 0; i < KEY_NUM; i++) keypad_1x4[i].loop(); // MUST call loop() first for (byte i = 0; i < KEY_NUM; i++) { if (keypad_1x4[i].isPressed()) return (i + 1); } return 0; }

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.

  • Connect: Wire the 1x4 keypad to the Arduino UNO Q MCU as shown in the wiring diagram above.
  • Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q — this can take several minutes on first launch.
  • 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: Keypad1x4
  • Click Create to confirm.
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 that 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
    • 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
    • Open the Serial Monitor and press each key on the keypad. You will see the key number printed.
    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
    [2026-04-29 09:00:01] Arduino UNO Q Keypad 1x4 ready [2026-04-29 09:00:05] Key pressed: 1 [2026-04-29 09:00:08] Key pressed: 2 [2026-04-29 09:00:11] Key pressed: 3 [2026-04-29 09:00:14] Key pressed: 4

    Bridge: Linux + MCU

    This section shows how to program both processors of the Arduino UNO Q so the Linux side can read keypad presses remotely:

    • The 1x4 keypad is connected to the MCU (STM32) — the MCU polls each key with debouncing in loop()
    • The MPU cannot read keypad pins directly — it must request the last pressed key from the MCU via Bridge.call()
    • The MPU has Wi-Fi — running full Debian Linux, it can react to key presses and send alerts over the Internet
    • Arduino_RouterBridge enables RPC communication between the two processors
    • ⚠️ /dev/ttyHS1 (Linux) and Serial1 (MCU) are RESERVED by the router — never open them in user code

    In short: MCU polls the keypad → MPU reads the last key via Bridge → MPU can react to key presses from anywhere over the Internet.

    Note: In the Bridge sketch, the ezButton polling loop is placed inside the Arduino loop() function to keep button state up to date — this is required and does not interfere with Bridge communication.

    MCU Code (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-keypad-1x4 */ // COPYRIGHT newbiely.com // AUTHOR: newbiely // This code is made available for public use without restriction. // For complete instructions, tutorials, and further information, visit: // https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-keypad-1x4 #include <ezButton.h> #include "Arduino_RouterBridge.h" #define KEY_NUM 4 #define PIN_KEY_1 3 #define PIN_KEY_2 2 #define PIN_KEY_3 5 #define PIN_KEY_4 4 ezButton keypad_1x4[KEY_NUM] = { ezButton(PIN_KEY_1), ezButton(PIN_KEY_2), ezButton(PIN_KEY_3), ezButton(PIN_KEY_4) }; int last_key = 0; String get_key(String arg) { int key = last_key; last_key = 0; // clear after reading return String(key); } String get_status(String arg) { if (last_key == 0) return "No key pressed"; return "Last key: " + String(last_key); } void setup() { Bridge.begin(); Monitor.begin(); for (byte i = 0; i < KEY_NUM; i++) { keypad_1x4[i].setDebounceTime(100); } Bridge.provide("get_key", get_key); Bridge.provide("get_status", get_status); Monitor.println("Arduino UNO Q Keypad 1x4 Bridge ready"); } void loop() { for (byte i = 0; i < KEY_NUM; i++) keypad_1x4[i].loop(); for (byte i = 0; i < KEY_NUM; i++) { if (keypad_1x4[i].isPressed()) { last_key = i + 1; Monitor.println("Key pressed: " + String(last_key)); } } }

    Python Code (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-keypad-1x4 */ # COPYRIGHT newbiely.com # AUTHOR: newbiely # This code is made available for public use without restriction. # For complete instructions, tutorials, and further information, visit: # https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-keypad-1x4 from arduino.app_utils import * import time def loop(): result = Bridge.call("get_key") key = int(result) if key != 0: print(f"Key pressed: {key}") else: print("No key pressed") time.sleep(0.2) App.run(user_loop=loop)

    Detailed Instructions

    • Connect: Wire the 1x4 keypad to the Arduino UNO Q as shown in the wiring diagram.
    • Open Arduino App Lab: Launch Arduino App Lab and wait for the board to be detected.
    • Create a new App: Click Create New App, name it Keypad1x4Bridge, then click Create.
    • Paste the MCU sketch: Copy the MCU Bridge code above and paste it into sketch/sketch.ino.
    • Paste the Python code: Copy the Python Bridge code above and paste it into the Python file in the App.
    • Upload: Click the Run button in Arduino App Lab.
    Click Run button in Arduino App Lab on Arduino UNO Q
    • Press keys on the keypad and watch the Python console.

    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
    [2026-04-29 09:00:01] Arduino UNO Q Keypad 1x4 Bridge ready [2026-04-29 09:00:05] Key pressed: 1 [2026-04-29 09:00:09] Key pressed: 3
    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 09:00:03] No key pressed [2026-04-29 09:00:05] Key pressed: 1 [2026-04-29 09:00:07] No key pressed [2026-04-29 09:00:09] Key pressed: 3

    Telegram

    Get Telegram notifications when a key is pressed on the 1x4 keypad — useful for remote doorbells, access codes, or event triggers.

    MCU sketch: Keep the same MCU sketch from the previous Bridge section.

    Python Code (Telegram)

    /* * 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-keypad-1x4 */ # COPYRIGHT newbiely.com # AUTHOR: newbiely # This code is made available for public use without restriction. # For complete instructions, tutorials, and further information, visit: # https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-keypad-1x4 from arduino.app_utils import * import requests import time TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN" CHAT_ID = "YOUR_CHAT_ID" last_update_id = 0 def get_updates(): global last_update_id url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates" params = {"offset": last_update_id + 1, "timeout": 5} try: response = requests.get(url, params=params, timeout=10) data = response.json() if data["ok"]: return data["result"] except Exception as e: print(f"Error getting updates: {e}") return [] def send_message(chat_id, text): url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage" payload = {"chat_id": chat_id, "text": text} try: requests.post(url, data=payload, timeout=10) except Exception as e: print(f"Error sending message: {e}") def loop(): global last_update_id # Poll keypad and send Telegram alert on key press result = Bridge.call("get_key") key = int(result) if key != 0: msg = f"Key pressed: {key}" print(msg) send_message(CHAT_ID, msg) # Also handle incoming Telegram commands updates = get_updates() for update in updates: last_update_id = update["update_id"] if "message" not in update: continue message = update["message"] chat_id = message["chat"]["id"] text = message.get("text", "").strip() print(f"Received: {text}") if text == "/start": send_message(chat_id, "Arduino UNO Q Keypad 1x4 Bot\n" "/key - Read the last key pressed\n" "/status - Get keypad status") elif text == "/key": result = Bridge.call("get_key") key = int(result) if key != 0: send_message(chat_id, f"Key pressed: {key}") else: send_message(chat_id, "No key pressed") elif text == "/status": result = Bridge.call("get_status") send_message(chat_id, result) else: send_message(chat_id, "Unknown command. Send /start for help.") time.sleep(0.2) App.run(user_loop=loop)

    Detailed Instructions

    • Replace YOUR_TELEGRAM_BOT_TOKEN with your actual bot token from BotFather.
    • Replace YOUR_CHAT_ID with your Telegram chat ID.
    • Paste this Python code into your App's Python file (keep the same MCU sketch).
    • Click the Run button. Press keys on the keypad — your Telegram chat will receive alerts automatically.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 09:15:00] Waiting for Telegram messages... [2026-04-29 09:15:08] Key pressed: 2 [2026-04-29 09:15:20] Received: /key [2026-04-29 09:15:35] Key pressed: 4
    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
    /key
    10:15 AM ✓✓
    No key pressed
    10:16 AM
    (presses key 2 on keypad)
    10:17 AM ✓✓
    Key pressed: 2
    10:18 AM
    /status
    10:19 AM ✓✓
    No key pressed
    10:20 AM

    OpenClaw

    ...OPENCLAW

    OpenClaw support for Arduino UNO Q Keypad 1x4 is coming soon.

    ...OPENCLAW

    Project Ideas

    You can build many creative projects using the 1x4 keypad with Arduino UNO Q:

    • Remote Access Code Entry: User presses a 4-key combination on the keypad; the MPU receives the sequence via Bridge and validates it, then sends a Telegram alert on success or failure
    • Menu Navigation System: Use keys 1–4 to navigate a menu on the Serial Monitor or LCD display — MPU tracks the selection and takes action
    • Event Buzzer System: Each key on the keypad triggers a different action (e.g., turn on a relay, sound a buzzer, or send a Telegram notification)
    • Simple Game Controller: Use the 1x4 keypad as directional input (left/right/up/down) in a simple text-based game running on the Linux MPU
    • Telegram Doorbell: Press key 1 on the keypad to ring a Telegram "doorbell" — the MPU sends a notification to the homeowner's phone automatically

    Challenge Yourself

    Ready to go further with the 1x4 keypad on Arduino UNO Q? Try these challenges:

    • Easy: Modify the MCU sketch to light up an LED connected to D6 whenever any key is pressed.
    • Medium: Implement a 4-digit PIN code system on the MCU — pressing keys 1-2-3-4 in sequence unlocks a relay, while any wrong sequence resets the input.
    • Advanced: Build a Telegram-based remote keypad: use /key to query the last pressed key, then build a state machine in Python that interprets key sequences as commands (e.g., 1-1-2 = "lights on", 2-1-1 = "lights off").

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