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:

ESP32 C3 Super Mini - Keypad 4x4

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)
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 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).
4x4 Keypad Pinout

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.

The wiring diagram between ESP32 C3 Super Mini Keypad 4x4

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.
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-keypad-4x4 */ #include <DIYables_Keypad.h> // DIYables_Keypad library #define ROW_NUM 4 // four rows #define COLUMN_NUM 4 // four columns 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] = {2, 3, 4, 5}; // The ESP32 C3 SuperMini pin GPIO2, GPIO3, GPIO4, GPIO5 connect to the row pins byte pin_column[COLUMN_NUM] = {6, 7, 10, 1}; // The ESP32 C3 SuperMini pin GPIO6, GPIO7, GPIO10, GPIO1 connect to the column pins DIYables_Keypad keypad = DIYables_Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); void setup() { Serial.begin(115200); } void loop() { char key = keypad.getKey(); if (key) { Serial.println(key); } }

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.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Library Manager
Type:
All
Topic:
All
DIYables_Keypad by 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 More info
1.0.1
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32C3 Dev Module on COM15
1
  • 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.

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
1 4 A #
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2

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.
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-keypad-4x4 */ #include <DIYables_Keypad.h> // DIYables_Keypad library #define ROW_NUM 4 // four rows #define COLUMN_NUM 4 // four columns 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] = {2, 3, 4, 5}; // The ESP32 C3 SuperMini pin GPIO2, GPIO3, GPIO4, GPIO5 connect to the row pins byte pin_column[COLUMN_NUM] = {6, 7, 10, 1}; // The ESP32 C3 SuperMini pin GPIO6, GPIO7, GPIO10, GPIO1 connect to the column pins DIYables_Keypad keypad = DIYables_Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); const String password = "7890A"; // change your password here String input_password; void setup() { Serial.begin(115200); 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("The password is correct, ACCESS GRANTED!"); // DO YOUR WORK HERE } else { Serial.println("The password is incorrect, ACCESS DENIED!"); } input_password = ""; // clear input password } else { input_password += key; // append new character to input password string } } }

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.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
1 2 3 4 B C # The password is incorrect, ACCESS DENIED! 7 8 9 0 A # The password is correct, ACCESS GRANTED!
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2

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

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