Arduino UNO Q - Keypad 4x4

Want to add a full 16-key membrane keypad to your Arduino UNO Q project? In this tutorial, you will learn how to read all 16 keys and build a password entry system — with Telegram alerts too.

In this tutorial, you will learn:

Arduino UNO Q 4x4 Keypad

Hardware Preparation

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

A 4x4 keypad has 16 membrane buttons arranged in 4 rows and 4 columns — including digits 0–9, letters A–D, and symbols * and #.

Pinout

A 4x4 keypad has 8 pins, divided into rows and columns:

  • 4 pins for rows: R1, R2, R3, R4
  • 4 pins for columns: C1, C2, C3, C4
4x4 Keypad Pinout

Wiring Diagram

The wiring diagram between Arduino UNO Q Keypad 4x4

This image is created using Fritzing. Click to enlarge image

Keypad Pin Arduino UNO Q MCU
R1 (Row 1) D9
R2 (Row 2) D8
R3 (Row 3) D7
R4 (Row 4) D6
C1 (Col 1) D5
C2 (Col 2) D4
C3 (Col 3) D3
C4 (Col 4) D2

Arduino UNO Q Code

The Arduino UNO Q has two processors working together:

  • The STM32 MCU reads the keypad matrix directly using the DIYables_Keypad 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.
/* * 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-4x4 */ // 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-4x4 #include <DIYables_Keypad.h> const int ROW_NUM = 4; const int COLUMN_NUM = 4; char keys[ROW_NUM][COLUMN_NUM] = { { '1', '2', '3', 'A' }, { '4', '5', '6', 'B' }, { '7', '8', '9', 'C' }, { '*', '0', '#', 'D' } }; byte pin_rows[ROW_NUM] = { 9, 8, 7, 6 }; // Arduino UNO Q MCU pins for rows byte pin_column[COLUMN_NUM] = { 5, 4, 3, 2 }; // Arduino UNO Q MCU pins for columns DIYables_Keypad keypad = DIYables_Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM); void setup() { Serial.begin(115200); delay(1500); Serial.println("Arduino UNO Q Keypad 4x4 ready"); } void loop() { char key = keypad.getKey(); if (key) { Serial.print("Key pressed: "); Serial.println(key); } }

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 4x4 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.
  • 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: Keypad4x4
  • Click Create to confirm.
Arduino App Lab App folders and files on Arduino UNO Q
  • Paste the sketch: Copy the MCU code above and paste it into sketch/sketch.ino. 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 DIYables_Keypad created by DIYables.io 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
DIYables_Keypad DIYables.io

The library is designed for Arduino, ESP32, ESP8266... to use with keypad such as 3x4, 4x4 keypad. It also works with Arduino Uno R4 WiFi/Minima

1.0.1
Install
More Info
  • Upload: Click the Run button in Arduino App Lab.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Open the Serial Monitor and press keys on the keypad. You will see each key 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 4x4 ready [2026-04-29 09:00:05] Key pressed: 1 [2026-04-29 09:00:08] Key pressed: A [2026-04-29 09:00:11] Key pressed: #

Keypad and Password

A common use of a 4x4 keypad is entering a password. Two special keys are used:

  • * — clears the current input and starts over
  • # — confirms the entry and checks the password

All other keys build up the password string one character at a time.

The logic:

  • Press any key → append it to the input buffer
  • Press * → clear the input buffer
  • Press # → compare input to the stored password, then clear the buffer
/* * 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-4x4 */ #include <DIYables_Keypad.h> // DIYables_Keypad library const int ROW_NUM = 4; //four rows const int COLUMN_NUM = 3; //three columns char keys[ROW_NUM][COLUMN_NUM] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'} }; byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad byte pin_column[COLUMN_NUM] = {5, 4, 3}; //connect to the column pinouts of the keypad DIYables_Keypad keypad = DIYables_Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); const String password = "1234"; // change your password here String input_password; void setup(){ Serial.begin(9600); Serial.println("Keypad 3x4 password"); input_password.reserve(32); // maximum input characters is 33, change if needed } void loop(){ char key = keypad.getKey(); if (key){ Serial.println(key); if(key == '*') { input_password = ""; // clear input password } else if(key == '#') { if(password == input_password) { Serial.println("password is correct"); // DO YOUR WORK HERE } else { Serial.println("password is incorrect, try again"); } input_password = ""; // clear input password } else { input_password += key; // append new character to input password string } } }

※ NOTE THAT:

Change the password variable to your desired password before uploading. You may use any combination of digits 0–9, letters A–D, and * or # in the password.

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 4x4 keypad is connected to the MCU (STM32) — the MCU polls it via keypad.getKey() 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, keypad.getKey() is called inside the Arduino loop() to continuously detect key presses — 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-4x4 */ // 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-4x4 #include <DIYables_Keypad.h> #include "Arduino_RouterBridge.h" const int ROW_NUM = 4; const int COLUMN_NUM = 4; char keys[ROW_NUM][COLUMN_NUM] = { { '1', '2', '3', 'A' }, { '4', '5', '6', 'B' }, { '7', '8', '9', 'C' }, { '*', '0', '#', 'D' } }; byte pin_rows[ROW_NUM] = { 9, 8, 7, 6 }; byte pin_column[COLUMN_NUM] = { 5, 4, 3, 2 }; DIYables_Keypad keypad = DIYables_Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM); char last_key = 0; String get_key(String arg) { char key = last_key; last_key = 0; if (key == 0) return "none"; 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(); Bridge.provide("get_key", get_key); Bridge.provide("get_status", get_status); Monitor.println("Arduino UNO Q Keypad 4x4 Bridge ready"); } void loop() { char key = keypad.getKey(); if (key) { last_key = key; Monitor.println("Key pressed: " + String(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-4x4 */ # 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-4x4 from arduino.app_utils import * import time def loop(): result = Bridge.call("get_key") if result != "none": print(f"Key pressed: {result}") else: print("No key pressed") time.sleep(0.2) App.run(user_loop=loop)

Detailed Instructions

  • Connect: Wire the 4x4 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 Keypad4x4Bridge, 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 4x4 Bridge ready [2026-04-29 09:00:05] Key pressed: A [2026-04-29 09:00:08] Key pressed: #
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: A [2026-04-29 09:00:07] No key pressed [2026-04-29 09:00:08] Key pressed: #

Telegram

Get Telegram notifications when a key is pressed on the 4x4 keypad — useful for remote access systems, event triggers, or PIN-code alerts.

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-4x4 */ # 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-4x4 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 notify on key press result = Bridge.call("get_key") if result != "none": msg = f"Key pressed: {result}" print(msg) send_message(CHAT_ID, msg) # 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 4x4 Bot\n" "/key - Read the last key pressed\n" "/status - Get keypad status") elif text == "/key": result = Bridge.call("get_key") if result != "none": send_message(chat_id, f"Key pressed: {result}") 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:05] Key pressed: B [2026-04-29 09:15:20] Received: /key [2026-04-29 09:15:35] Key pressed: D
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 B on keypad)
10:17 AM ✓✓
Key pressed: B
10:18 AM
/status
10:19 AM ✓✓
No key pressed
10:20 AM

OpenClaw

...OPENCLAW

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

...OPENCLAW

Project Ideas

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

  • Remote PIN Code Lock: User enters a PIN on the keypad; the MCU validates it and controls a relay or solenoid lock, while the MPU sends a Telegram alert on success or failure
  • Function Key Controller: Use keys A–D as function shortcuts — each triggers a different IoT action (e.g., A = lights on, B = lights off, C = fan on, D = alarm)
  • Calculator Interface: Build a simple calculator where the user enters two numbers and an operator via the keypad, and the result appears on the Serial Monitor or LCD
  • Telegram-Triggered Keypad Logger: All key presses are automatically forwarded to a Telegram group for remote monitoring of a physical location
  • Multi-User Access System: Assign different PINs to different users — the MPU logs each successful login with a username and timestamp via Telegram

Challenge Yourself

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

  • Easy: Modify the MCU sketch to turn an LED on when key A is pressed and off when key B is pressed.
  • Medium: Implement a full password system in Python: accumulate key presses received via Bridge, check the input when # arrives, and send a Telegram message with "Access granted" or "Access denied".
  • Advanced: Build a multi-user keypad access system — store two different PINs in Python; when either PIN is entered correctly on the keypad, the MCU activates a relay and the MPU logs the event with a timestamp and sends a Telegram notification identifying which PIN was used.

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