ESP32 S3 UNO - Keypad 3x4
This ESP32 S3 Uno keypad 3x4 tutorial shows you how to connect a 3x4 membrane keypad to the ESP32 S3 Uno form board and read each key with Arduino code. You see every pressed key in the Serial Monitor. Then you turn the keypad into a simple password lock that tells you if the code you typed is right or wrong.
In this tutorial, you will:
- Wire a 3x4 keypad to the ESP32 S3 Uno
- Install the DIYables_Keypad library in the Arduino IDE
- Read the pressed key and print it to the Serial Monitor
- Check a keypad password with the * and # keys

Hardware Preparation
| 1 | × | ESP32 S3 Uno-form Board | |
| 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 3x4 | |
| 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 3x4 Keypad
A 3x4 keypad is a cheap and easy way to let people type numbers into your project. Knowing how it is built helps you understand the wiring and the code.
The keypad has 12 thin membrane buttons. They sit in a grid of rows and columns, which is called a matrix. Each button is called a key. When you press a key, it connects one row line to one column line. The library scans the rows and columns very fast to find which key made the connection.
The keypad itself has no chip and needs no power pin. It is only a set of switches, so it works fine with the 3.3V logic of the ESP32 S3 Uno.
Pinout
The keypad has 7 pins in one row. They come in two groups.
Row pins
4 pins connect to the rows: R1, R2, R3 and R4.
Column pins
3 pins connect to the columns: C1, C2 and C3.

ESP32 S3 Uno Pinout
The image below shows the pinout diagram of the ESP32 S3 Uno form board. Use it to find the Uno header pins (D3 to D9) and their GPIO numbers when you wire the keypad.

Wiring Diagram
Connect the 7 keypad pins to seven digital pins in a row, from D9 down to D3. The diagram and the table show each connection.

This image is created using Fritzing. Click to enlarge image
| Keypad Pin | ESP32 S3 Uno Pin |
|---|---|
| R1 | D9 (GPIO46) |
| R2 | D8 (GPIO21) |
| R3 | D7 (GPIO14) |
| R4 | D6 (GPIO3) |
| C1 | D5 (GPIO20) |
| C2 | D4 (GPIO19) |
| C3 | D3 (GPIO17) |
WARNING
This wiring uses two boot strapping pins of the ESP32 S3 Uno: D9 (GPIO46) for row R1 and D6 (GPIO3) for row R4. The board reads these pins at power-up to choose its boot mode. A pressed key can pull them to a column line and change that level. So do not hold any key while you power on, reset or upload code. If the board does not start or the upload fails, unplug the keypad, upload again, and then plug it back in.
ESP32 S3 Uno Code
This sketch scans the keypad all the time. When you press a key, it prints that key to the Serial Monitor. The pin arrays in the code use GPIO numbers, and they match the wiring table above.
Detailed Instructions
- New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
- Wire it up as shown in the diagram.
- Connect the board to your computer with a USB Type-C cable.
- Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
- Open the Library Manager by clicking the Libraries icon on the left side of the Arduino IDE.
- Search the library. Type DIYables_Keypad in the search box and find the keypad library by DIYables.io.
- Install it by clicking the Install button.
- Search for DIYables_Keypad created by DIYables.io and click the Install button.
- Copy the code above and paste it into the Arduino IDE.
- Upload the code by clicking the Upload button.
- Open the Serial Monitor and set it to 9600 baud.
- Press some keys on the keypad.
- Check the output in the Serial Monitor.
- Tip: if a key prints nothing or the wrong character, check that the row and column wires are not swapped.
Keypad and Password
A keypad is a great input for a door lock or a secret code. To make it work, you give two keys a special job, and all the other keys become part of the password.
Start key
The "*" key starts the password from the beginning. Press it to clear what you typed so far.
Enter key
The "#" key ends the password. When you press it, the code checks your input.
How the logic works
- If the key is not "*" or "#", the code adds it to the password you are typing.
- If the key is "#", the code compares your input with the saved password, prints the result, and then clears your input.
- If the key is "*", the code clears your input so you can start again.
Keypad - Password Code
The sketch below stores the password "1234". It builds your input one key at a time and checks it when you press "#". Change the password line to set your own code, and put your action (open a lock, turn on an LED) where the comment says "DO YOUR WORK HERE".
- Upload the code above to the ESP32 S3 Uno.
- Open the Serial Monitor at 9600 baud.
- Type a wrong code: press "1", "2", "3", "4", "5", "6", then "#".
- Type the right code: press "1", "2", "3", "4", then "#".
- Read the results in the Serial Monitor.
Video Tutorial
Watch the video below to see this ESP32 S3 Uno project step by step.
Additional Knowledge
These guides help you go one step further with your keypad:
FAQ
Does a 3x4 keypad work with the 3.3V ESP32 S3 Uno?
Yes. The keypad is only a grid of switches with no chip inside, so it has no voltage of its own. The library uses the ESP32 S3 Uno pins and their internal pull-ups, so all signals stay at 3.3V. You do not need a level shifter or resistors.
Why are the pin numbers in the code different from the D pins on the board?
On the ESP32 S3 Uno, you write GPIO numbers in code, not the Uno header labels. For example, D9 is GPIO46 and D3 is GPIO17. That is why the code uses {46, 21, 14, 3} for the rows and {20, 19, 17} for the columns.
Can I use other pins for the keypad?
Yes. Any pin that works as a digital input and output is fine. Change the numbers in pin_rows and pin_column to the GPIO numbers you use. Avoid D0 and D1 (GPIO44 and GPIO43), because the USB serial uses them.
Is the code different from the UNO R4 version?
The logic and the DIYables_Keypad library are the same. Only the pin numbers change, because the ESP32 S3 Uno uses GPIO numbers. You also pick the ESP32S3 Dev Module board in the Arduino IDE.
What if my project needs more pins than the Uno headers give?
The ESP32 S3 Uno has two extra rows of holes with more GPIOs. GPIO15 and GPIO16 are I/O with PWM and analog. GPIO45 and GPIO35 to GPIO42 are I/O with PWM. GPIO47 and GPIO48 are output only with PWM. Solder pin headers to use them and write the GPIO number in code. For a keypad, GPIO15, GPIO16 and GPIO35 to GPIO42 are good choices. Do not use GPIO47 or GPIO48 for keypad rows, because the keypad needs input pins. Two warnings: GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. Also, GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.
How do I change the password?
Edit the line const String password = "1234"; and put your own digits between the quotes. Upload the code again. Do not use "*" or "#" in the password, because these keys have special jobs.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port in the Arduino IDE | USB driver missing or board not in upload mode | Install the CP210x or CH340 driver. Or hold BOOT, press RESET, then release BOOT and upload again |
| Upload fails or the board does not start | A key is pressed or a boot pin (D6 or D9) is pulled at power-up | Do not touch the keypad during reset. Unplug the keypad, upload, then plug it back in |
| Nothing prints when a key is pressed | Loose wire or wrong pin in the code | Check all 7 wires and make sure the code uses the GPIO numbers from the wiring table |
| Wrong character is printed | Row or column wires are swapped | Compare the keypad pin order R1 to C3 with the wiring table and fix the order |
| One full row or column does not work | That wire is broken or not seated | Reseat or replace the jumper wire for that row or column |
| Strange symbols in the Serial Monitor | Wrong baud rate | Set the Serial Monitor to 9600 baud |
| Compile error DIYables_Keypad.h not found | Library is not installed | Install DIYables_Keypad from the Library Manager |
| Password is always incorrect | Old input was not cleared or extra keys were typed | Press * first to clear, then type the password and press # |