아두이노 우노 Q 1x4 키패드

Arduino UNO Q 프로젝트에 간단한 4개 버튼 키패드를 추가하고 싶으신가요? 이 튜토리얼에서는 디바운싱을 사용하여 키 누름을 감지하는 방법을 배우고, 키를 누를 때 Telegram 알림을 보내는 방법도 배우게 됩니다.

이 튜토리얼에서 배우게 될 내용:

Arduino UNO Q 키패드 1x4

필요한 하드웨어

1×Arduino UNO Q 아마존
1×USB Cable for Arduino Uno Q 아마존
1×키패드 1x4 쿠팡 | 아마존
1×점퍼케이블 쿠팡 | 아마존
1×(추천) 아두이노 우노용 스크루 터미널 블록 쉴드 쿠팡 | 아마존
1×(추천) Sensors/Servo Expansion Shield for Arduino Uno 쿠팡 | 아마존
1×(추천) 아두이노 우노용 브레드보드 쉴드 쿠팡 | 아마존
1×(추천) 아두이노 우노용 케이스 쿠팡 | 아마존
1×(추천) 아두이노 우노용 프로토타이핑 베이스 플레이트 & 브레드보드 키트 아마존
공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

1x4 키패드 소개

1x4 키패드는 한 줄에 4개의 버튼이 배열되어 있습니다. 코드 입력, 메뉴 탐색, 또는 다양한 프로젝트에서 작업을 트리거하는 데 사용됩니다.

핀아웃

1x4 키패드는 5개의 핀이 있습니다. 핀 순서가 라벨의 키 순서와 일치하지 않습니다:

  • Pin 1 → Key 2
  • Pin 2 → Key 1
  • Pin 3 → Key 4
  • Pin 4 → Key 3
  • Pin 5 → Common (GND)
키패드 1x4 사용법 핀아웃

배선도

Arduino UNO Q 키패드 1x4 연결 배선도

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

키패드 핀 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 코드

Arduino UNO Q는 함께 작동하는 두 개의 프로세서가 있습니다:

  • STM32 MCUezButton 라이브러리를 통해 디바운싱으로 키패드 핀을 직접 읽습니다
  • Qualcomm MPU는 Debian Linux를 실행하며 Wi-Fi, Python, 클라우드 연결을 처리합니다
  • 이 섹션에서는 MCU만 프로그래밍됩니다 — Linux 측은 유휴 상태입니다. 나중의 섹션에서는 두 프로세서가 Bridge를 통해 함께 작동하는 방법을 보여줍니다.

1x4 키패드의 각 키는 핀과 GND 사이에 연결된 버튼처럼 작동합니다. ezButton 라이브러리는 4개 키 모두에 대해 자동으로 디바운싱을 처리합니다.

/* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/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; }

빠른 단계

Arduino UNO Q 처음이신가요? 진행하기 전에 아두이노 우노 Q 시작하기 튜토리얼을 따라 개발 환경을 준비하세요.

  • 연결하기: 위의 배선도와 같이 1x4 키패드를 Arduino UNO Q MCU에 연결합니다.
  • Arduino App Lab 열기: Arduino App Lab을 시작하고 Arduino UNO Q를 감지할 때까지 기다립니다 — 처음 시작할 때는 몇 분이 걸릴 수 있습니다.
  • 새 앱 만들기: Create New App 버튼을 클릭합니다.
create new app in 아두이노 app lab on Arduino UNO Q
  • 앱에 이름을 지정합니다(예: Keypad1x4).
  • Create를 클릭하여 확인합니다.
아두이노 app lab app folders and files on Arduino UNO Q
  • sketch/sketch.ino 파일을 찾습니다 — 이것이 MCU 스케치를 붙여넣을 위치입니다.
  • 스케치 붙여넣기: 위의 MCU 코드를 복사하여 해당 스케치 파일에 붙여넣습니다. 다른 파일은 기본값으로 유지합니다.
    • Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.
    add sketch 라이브러리 in 아두이노 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
    • 업로드: Arduino App Lab의 Run 버튼을 클릭하여 STM32로 컴파일하고 업로드합니다.
    click run 버튼 in 아두이노 app lab on Arduino UNO Q
    • Serial Monitor 열기하고 키패드의 각 키를 누릅니다. 키 번호가 출력되는 것이 보입니다.
    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

    이 섹션에서는 Linux 측이 원격으로 키패드 누름을 읽을 수 있도록 Arduino UNO Q의 두 프로세서를 모두 프로그래밍하는 방법을 보여줍니다:

    • 1x4 키패드는 MCU(STM32)에 연결되어 있습니다 — MCU는 loop() 내에서 디바운싱을 사용하여 각 키를 폴링합니다
    • MPU는 키패드 핀을 직접 읽을 수 없습니다Bridge.call()을 통해 MCU로부터 마지막 누른 키를 요청해야 합니다
    • MPU는 Wi-Fi를 가지고 있습니다 — 전체 Debian Linux를 실행하여 키 누름에 반응하고 인터넷을 통해 알림을 보낼 수 있습니다
    • Arduino_RouterBridge두 프로세서 간 RPC 통신을 활성화합니다
    • ⚠️ /dev/ttyHS1 (Linux)와 Serial1 (MCU)은 라우터에 의해 예약됨 — 사용자 코드에서 열지 마세요

    간단히 말해: MCU가 키패드를 폴링합니다 → MPU는 Bridge를 통해 마지막 키를 읽습니다 → MPU는 인터넷을 통해 어디서나 키 누름에 반응할 수 있습니다.

    참고: Bridge 스케치에서 ezButton 폴링 루프는 Arduino loop() 함수 내에 배치되어 버튼 상태를 업데이트 상태로 유지합니다 — 이는 필수이며 Bridge 통신을 방해하지 않습니다.

    MCU 코드 (Bridge)

    /* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/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 코드 (Bridge)

    /* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/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)

    빠른 단계

    • 연결하기: 배선도와 같이 1x4 키패드를 Arduino UNO Q에 연결합니다.
    • Arduino App Lab 열기: Arduino App Lab을 시작하고 보드가 감지될 때까지 기다립니다.
    • 새 앱 만들기: Create New App를 클릭하고, 이름을 Keypad1x4Bridge로 지정한 다음 Create를 클릭합니다.
    • MCU 스케치 붙여넣기: 위의 MCU Bridge 코드를 복사하여 sketch/sketch.ino에 붙여넣습니다.
    • Python 코드 붙여넣기: 위의 Python Bridge 코드를 복사하여 앱의 Python 파일에 붙여넣습니다.
    • 업로드: Arduino App Lab의 Run 버튼을 클릭합니다.
    click run 버튼 in 아두이노 app lab on Arduino UNO Q
    • 키패드의 키를 누르고 Python 콘솔을 봅니다.

    App Lab 콘솔 출력

    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

    1x4 키패드에서 키를 누를 때 Telegram 알림을 받습니다 — 원격 초인종, 액세스 코드, 또는 이벤트 트리거에 유용합니다.

    MCU 스케치: 이전 Bridge 섹션과 동일한 MCU 스케치를 유지합니다.

    Python 코드 (Telegram)

    /* * 이 Arduino UNO Q 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino UNO Q 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/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)

    빠른 단계

    • YOUR_TELEGRAM_BOT_TOKEN을 BotFather의 실제 봇 토큰으로 바꿉니다.
    • YOUR_CHAT_ID를 Telegram 채팅 ID로 바꿉니다.
    • 이 Python 코드를 앱의 Python 파일에 붙여넣습니다 (동일한 MCU 스케치 유지).
    • Run 버튼을 클릭합니다. 키패드의 키를 누르면 — Telegram 채팅에 자동으로 알림을 받습니다.

    App Lab 콘솔 출력

    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

    You can adapt the OpenClaw to this tutorial by refering the instruction on 아두이노 우노 Q - OpenClaw Tutorial

    프로젝트 아이디어

    Arduino UNO Q와 1x4 키패드를 사용하여 많은 창의적인 프로젝트를 만들 수 있습니다:

    • 원격 액세스 코드 입력: 사용자가 키패드에서 4개 키 조합을 누릅니다; MPU는 Bridge를 통해 시퀀스를 받고 검증한 다음 성공 또는 실패 시 Telegram 알림을 보냅니다
    • 메뉴 탐색 시스템: 키 1-4를 사용하여 Serial Monitor 또는 LCD 디스플레이의 메뉴를 탐색합니다 — MPU가 선택을 추적하고 조치를 취합니다
    • 이벤트 버저 시스템: 키패드의 각 키는 다른 조치를 트리거합니다 (예: 릴레이 켜기, 버저 울리기, 또는 Telegram 알림 보내기)
    • 간단한 게임 컨트롤러: 1x4 키패드를 Linux MPU에서 실행 중인 간단한 텍스트 기반 게임에서 방향 입력(왼쪽/오른쪽/위/아래)으로 사용합니다
    • Telegram 초인종: 키패드의 키 1을 눌러 Telegram "초인종"을 울립니다 — MPU가 자동으로 주택 소유자의 휴대폰에 알림을 보냅니다

    도전해보기

    Arduino UNO Q의 1x4 키패드로 더 나아갈 준비가 되셨나요? 이러한 도전들을 시도해보세요:

    • 쉬운: MCU 스케치를 수정하여 어떤 키라도 누를 때마다 D6에 연결된 LED를 켜집니다.
    • 중간: MCU에 4자리 PIN 코드 시스템을 구현합니다 — 순서대로 키 1-2-3-4를 누르면 릴레이가 잠금 해제되고, 잘못된 시퀀스는 입력을 초기화합니다.
    • 고급: Telegram 기반 원격 키패드를 구축합니다: /key를 사용하여 마지막 누른 키를 쿼리한 다음, Python에서 상태 머신을 구축하여 키 시퀀스를 명령으로 해석합니다 (예: 1-1-2 = "lights on", 2-1-1 = "lights off").