ESP32 S3 UNO - Keypad 1x4
This ESP32 S3 Uno keypad 1x4 tutorial shows you how to connect a 4-key keypad to the ESP32 S3 Uno form board and read which key you press. Each key is debounced in code, so one press gives one clean result. You will see the key number appear in the Serial Monitor of the Arduino IDE.
In this tutorial, you will:
- Learn the pinout of a 1x4 keypad
- Wire a 4-key keypad to the ESP32 S3 Uno
- Debounce four keys at once with the ezButton library
- Print the pressed key number to the Serial Monitor

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 1x4 | |
| 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 Keypad 1x4
A 1x4 keypad is a thin strip with four push keys in one row. It is a cheap and simple way to add user input to a project. You can use it to type a short code, move through a menu, or pick one of four modes.
Inside, each key is just a small switch. When you press a key, it connects its own pin to a shared common pin.
Pinout
The keypad has 5 pins. Be careful: the pin order is not the same as the numbers printed on the keys. Use the table below to know which pin belongs to which key.
| Keypad Pin | Connected To |
|---|---|
| Pin 1 | Key 2 |
| Pin 2 | Key 1 |
| Pin 3 | Key 4 |
| Pin 4 | Key 3 |
| Pin 5 | Common pin of all keys |

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 D2 to D5 and their GPIO numbers when you wire the keypad.

Wiring Diagram
Each key pin goes to its own digital pin, and the common pin goes to GND. When you press a key, its ESP32 S3 Uno pin reads LOW.

This image is created using Fritzing. Click to enlarge image
| Keypad Pin | ESP32 S3 Uno Pin |
|---|---|
| Pin 1 (Key 2) | D2 (GPIO18) |
| Pin 2 (Key 1) | D3 (GPIO17) |
| Pin 3 (Key 4) | D4 (GPIO19) |
| Pin 4 (Key 3) | D5 (GPIO20) |
| Pin 5 (Common) | GND |
※ NOTE THAT:
No external resistors are needed. The ezButton library turns on the internal pull-up resistor of each pin. The keys only connect the pins to GND, so no 5V reaches the board. This matters because ESP32 S3 Uno pins work at 3.3V and are NOT 5V tolerant.
ESP32 S3 Uno Code
Every key on the keypad acts like a separate push button. You could read each one with digitalRead(), but a button bounces: one press can look like many fast presses. Debouncing four keys by hand, without blocking the rest of your code, takes a lot of work.
The ezButton library does this job for you. The sketch below makes one ezButton object for each key, sets a 100 ms debounce time, and prints the key number when a key is pressed.
Detailed Instructions
Follow these steps one by one:
- 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.
- Find the library by typing ezButton in the search box. Look for the button library by ArduinoGetStarted.com.
- Install it by clicking the Install button.
- Search for ezButton created by ArduinoGetStarted.com 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 the baud rate to 9600.
- Press each key on the keypad, one at a time.
- Check the result in the Serial Monitor:
- Tip: If a key shows the wrong number, check the pinout table again. The keypad pins are not in the same order as the key labels.
FAQ
Do I need resistors to connect a 1x4 keypad to the ESP32 S3 Uno?
No. The ezButton library sets each key pin to INPUT_PULLUP, so the ESP32 S3 Uno uses its internal pull-up resistors. Just connect the common pin to GND.
Can I power the 1x4 keypad from 5V on the ESP32 S3 Uno?
You do not need to. This keypad has no power pin, only key pins and a common pin. Connect the common pin to GND, not to 5V. ESP32 S3 Uno pins are 3.3V and are NOT 5V tolerant, so a 5V signal on a key pin can damage the board.
Can I use other pins for the keypad keys?
Yes. Any free digital pin works. Change the PIN_KEY_1 to PIN_KEY_4 values in the code to the GPIO numbers, not the Uno labels. For example, D7 is GPIO14, so write 14. Avoid D6 (GPIO3) and D9 (GPIO46), because they are boot strapping pins.
Is the ESP32 S3 Uno code different from the UNO R4 code?
Only the pin numbers change. The UNO R4 uses pins 2 to 5, while the ESP32 S3 Uno code uses GPIO18, GPIO17, GPIO20 and GPIO19 for the same D2 to D5 header positions. The ezButton library works on both boards.
How can I detect when a key is released?
The ezButton library also has an isReleased() function. Call it in the same loop as isPressed() to know when the key goes back up.
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 (I/O, PWM, analog), GPIO45 and GPIO35 to GPIO42 (I/O, PWM), and GPIO47/GPIO48 (output only, PWM). Solder pin headers to use them and write the GPIO number in code. For extra keys or buttons, GPIO35 to GPIO42 are good picks. Do not use GPIO47/GPIO48 for keys, because they are output only. Two warnings: (1) GPIO47/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. (2) GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins. A wrong connection can stop the board from booting or uploading code. Use the other extra pins first.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port in Arduino IDE | USB driver missing or board not in upload mode | Install the CP210x or CH340 driver, or hold BOOT while you press RESET, then upload again |
| Nothing prints when a key is pressed | Common pin not connected to GND or loose wire | Connect keypad pin 5 to GND and check every jumper wire |
| Wrong key number is printed | Keypad pins wired in label order | Follow the pinout table. Pin 1 is key 2 and pin 2 is key 1 |
| One press prints the number many times | Debounce time too short | Raise the value in setDebounceTime(), for example to 150 |
| Strange characters in the Serial Monitor | Wrong baud rate | Set the Serial Monitor to 9600 baud |
| Compile error for ezButton.h | Library not installed | Install the ezButton library from the Library Manager |