ESP32 C3 Super Mini - Keypad 4x4
A 4x4 keypad gives your ESP32 C3 Super Mini 16 buttons on a single thin pad. It is the easiest way to let a user type a number or a PIN code. This ESP32 C3 Super Mini keypad 4x4 tutorial shows you the wiring, the code, and a working password check.
In this tutorial, you'll learn:
- What a 4x4 keypad is and how key scanning works
- What the 8 keypad pins (R1-R4 and C1-C4) do
- How to wire a 4x4 keypad to the ESP32 C3 Super Mini
- How to print every pressed key to the Serial Monitor
- How to build a password check with the * and # keys

Hardware Preparation
| 1 | × | ESP32 C3 Super Mini | |
| 1 | × | USB Cable Type-A to Type-C (for USB-A PC) | |
| 1 | × | USB Cable Type-C to Type-C (for USB-C PC) | |
| 1 | × | Keypad 4x4 | |
| 1 | × | Jumper Wires |
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of 4x4 Keypad
A 4x4 keypad is a membrane input pad with 16 buttons placed in 4 rows and 4 columns.
Key Features:
- 16 keys: 0-9, A, B, C, D, star and hash.
- Only 8 wires: 4 row pins and 4 column pins.
- No power pin: The keypad takes no VCC and no GND.
- Thin and flat: A sticker back lets you glue it to a box.
- 3.3V friendly: It works straight from ESP32 C3 Super Mini logic levels.
Technical Specifications:
- Layout: 4 rows x 4 columns.
- Pins: 8 pins (R1, R2, R3, R4, C1, C2, C3, C4).
- Contact type: Simple momentary switch under each key.
- Operating voltage: Set by the board. 3.3V on the ESP32 C3 Super Mini.
- Current draw: Almost zero, so it needs no extra supply.
How Key Scanning Works
The keypad has no chip inside, so the ESP32 C3 Super Mini finds the key by scanning.
- One switch per key: Each key joins one row wire to one column wire.
- Row by row: The board pulls one row LOW at a time.
- Read the columns: It then reads all 4 column pins.
- Match: A LOW column tells the board which key is down.
- Fast: The whole scan takes less than a millisecond, so it feels instant.
- Library does it: The DIYables_Keypad library runs this scan for you.
Pinout
The 4x4 keypad has 8 pins in two groups.
- R1 pin: Row 1, the top row of keys (1, 2, 3, A).
- R2 pin: Row 2, the second row of keys (4, 5, 6, B).
- R3 pin: Row 3, the third row of keys (7, 8, 9, C).
- R4 pin: Row 4, the bottom row of keys (*, 0, #, D).
- C1 pin: Column 1, the left column (1, 4, 7, *).
- C2 pin: Column 2, the second column (2, 5, 8, 0).
- C3 pin: Column 3, the third column (3, 6, 9, #).
- C4 pin: Column 4, the right column (A, B, C, D).

WARNING
A 4x4 keypad needs 8 GPIO pins, and that is nearly every free pin on the ESP32 C3 Super Mini. After wiring it, you have almost no pin left for a display, a relay or a sensor.
If you need pins for other parts, use one of these instead:
- An I2C keypad, which needs only SDA GPIO10 and SCL GPIO8.
- A PCF8574 I/O expander between the keypad and the board, also on SDA GPIO10 and SCL GPIO8.
Both options drive the same 16 keys with just 2 wires.
Wiring Diagram
Connect the 4 row pins and the 4 column pins of the keypad to 8 free GPIO pins on the ESP32 C3 Super Mini.

This image is created using Fritzing. Click to enlarge image
| Keypad Pin | ESP32 C3 Super Mini Pin |
|---|---|
| R1 | GPIO2 |
| R2 | GPIO3 |
| R3 | GPIO4 |
| R4 | GPIO5 |
| C1 | GPIO6 |
| C2 | GPIO7 |
| C3 | GPIO10 |
| C4 | GPIO1 |
- Note: The keypad has no VCC and no GND wire. All 8 pins go to GPIO pins.
- Note: Never use GPIO8 (built-in LED and boot pin), GPIO9 (boot pin), GPIO20 or GPIO21 (Serial Monitor UART).
- Note: The keypad is 3.3V safe. Do not connect any pin to 5V.
- Note: Push each jumper wire fully into the breadboard. A loose wire is the top cause of missed key presses.
- Note: Hold the keypad with the keys facing up and count the ribbon wires from the left. The first one is R1 and the last one is C4.
ESP32 C3 Super Mini Code - Keypad 4x4
This first sketch just prints every key you press.
What This Code Does:
- Builds a map of the 16 keys in a 4x4 array.
- Tells the library which GPIO pins hold the rows and the columns.
- Scans the keypad again and again inside the loop.
- Prints the pressed key to the Serial Monitor at 115200 baud.
- Prints nothing when no key is down.
Detailed Instructions
- New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
- Wire the parts: Follow the wiring diagram above to connect the 4x4 keypad to the ESP32 C3 Super Mini.
- Connect the board: Plug the ESP32 C3 Super Mini into your PC with a USB Type-C cable.
- Open the IDE: Start the Arduino IDE software.
- Select the board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
- Select the port: Pick the COM port of your board in Tools > Port.
- Open Library Manager: Click the Libraries icon on the left bar of the Arduino IDE.
- Search for library: Type "DIYables_Keypad" in the search box.
- Install library: Look for the keypad library by DIYables.io, then click Install.
- Search for DIYables_Keypad created by DIYables.io and click the Install button.
- Copy the code: Copy the keypad code above and paste it into the Arduino IDE.
- Upload the code: Click the Upload button to send the sketch to the ESP32 C3 Super Mini.
- Open Serial Monitor: Set the baud rate to 115200.
- Test it: Press a few keys on the keypad, one at a time.
- Check the output: Each key you press shows up on its own line.
- Pro Tip: If the wrong key is printed, swap the row pins and the column pins in the code. Keypad ribbon cables are not wired the same way by every maker.
Serial Monitor Output
Press the keys 1, 4, A and # one after the other.
Keypad and Password
The keypad becomes a PIN pad when you use two keys as control keys.
- Star key: The * key clears what you typed so you can start again.
- Hash key: The # key ends the entry and checks it against the saved password.
- Any other key: Is added to the end of the typed password.
- Result: The sketch prints ACCESS GRANTED or ACCESS DENIED, then clears the input.
- Your code: Put your own action, such as opening a lock, where the code says DO YOUR WORK HERE.
ESP32 C3 Super Mini Code - Keypad Password
This second sketch turns the ESP32 C3 Super Mini keypad into a password checker.
What This Code Does:
- Keeps a password in the sketch, set to 7890A by default.
- Collects each pressed key into an input string.
- Clears the input when you press the * key.
- Compares the input with the password when you press the # key.
- Prints whether the password is correct, then clears the input.
Quick Steps (Password Example)
- Upload the code: Send the password sketch to the ESP32 C3 Super Mini.
- Open Serial Monitor: Set the baud rate to 115200.
- Type a wrong code: Press 1234BC and then #.
- Type the right code: Press 7890A and then #.
- Check the output: Read the result lines on the Serial Monitor.
- Pro Tip: Press * any time you make a typing mistake. It clears the entry without a wrong-password message.
※ NOTE THAT:
The password sits in plain text inside the sketch. That is fine for learning. For a real lock, store it in NVS flash so you can change it without a new upload.
Line-by-line Code Explanation
The ESP32 C3 Super Mini code above contains line-by-line explanation. Please read the comments in the code!
Application/Project Ideas
A keypad is the input side of almost any small security or menu project.
- Door Lock: Open a solenoid lock when the PIN is correct.
- Safe Box: Ask for a longer key sequence before a box can be opened.
- Alarm Keypad: Arm and disarm an alarm with a code.
- Access Log: Save every key press with a time stamp to an SD card.
- Simple Calculator: Use 0-9 for numbers and A-D for plus, minus, times and divide.
- Menu Control: Pick a menu item on an LCD by typing its number.
Challenge Yourself
Try these small projects to practice with the 4x4 keypad and the ESP32 C3 Super Mini.
- Easy: Change the password to your own 6-digit number and test it.
- Easy: Blink the built-in LED on GPIO8 once for every key press.
- Medium: Show each key on an I2C LCD instead of the Serial Monitor, using SDA GPIO10 and SCL GPIO8.
- Medium: Block the keypad for 30 seconds after 3 wrong tries.
- Advanced: Save the password in NVS flash so it survives a power cut, and add a key sequence to change it.
- Advanced: Swap the direct wiring for a PCF8574 I/O expander so the keypad needs only 2 pins.