ESP32 S3 - Keypad - LCD

A keypad paired with an LCD I2C display gives the ESP32 S3 a complete human-interface loop — the user presses a key and the board shows the result on screen without needing a laptop or Serial Monitor. This tutorial walks you through connecting both components to the ESP32 S3 and writing the Arduino code that captures every key press and renders it live on the LCD.

What you'll build:

  1. A circuit connecting a 3x4 or 4x4 matrix keypad and an LCD I2C display to the ESP32 S3
  2. A sketch that detects each key press and immediately updates the LCD with the pressed character
  3. A self-contained input display that operates independently from a computer once uploaded
  4. A reusable foundation for PIN-entry panels, menu systems, and interactive input interfaces

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×Alternatively, ESP32 S3 SuperMini Dev Module
1×Alternatively, ESP32 S3 Uno-form Board
1×Alternatively, ESP32 S3 Camera 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×LCD I2C Display 3.3V
1×Alternatively, LCD I2C 20x4
1×Keypad 3x4 and 4x4 Kit
1×Alternatively, Keypad 3x4
1×Alternatively, Keypad 4x4
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

Or you can buy the following kits:

1×DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
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 .

Buy Note: Most LCD I2C displays available on the market are 5V displays. They may work with this board, but it is unsafe and can damage the board. We strongly recommend using the 3.3V LCD I2C display recommended above.

Overview of Keypad and LCD

A matrix keypad encodes button presses by scanning rows and columns so that many keys can be read through just a handful of GPIO pins, making it an efficient way to add physical input to any ESP32 S3 project. Pairing it with an LCD I2C display closes the feedback loop by giving the user instant, visible confirmation of what was typed — no Serial Monitor window required.

Key Specifications

We have dedicated tutorials covering each component in depth. Each tutorial contains detailed information and step-by-step instructions about hardware pinout, working principle, wiring connection to the ESP32 S3, and Arduino code. Learn more about them at the following links:

Wiring Diagram

Connect the keypad row and column pins to the ESP32 S3 GPIOs and wire the LCD I2C module to the board's I2C bus before powering anything on. Double-check every connection against the diagrams below, paying special attention to the LCD's VCC wire — it must go to the 5V rail, not 3.3V, for the display to work correctly.

  • Wiring diagram between ESP32 S3 and Keypad 3x4
The wiring diagram between ESP32 S3 Keypad 3x4 LCD

This image is created using Fritzing. Click to enlarge image

If the project will run for a long time, or sit inside a box, it is better to fix the wires with screws. Simply plug the ESP32 S3 into a Screw Terminal Block for ESP32 S3. This is how it looks with the screw terminal board:

The wiring diagram between ESP32 S3 Keypad 3x4 LCD Screw Terminal

This image is created using Fritzing. Click to enlarge image

Another choice is a GPIO Breakout Board for ESP32 S3. Each GPIO has a signal pin with 3.3V and GND pins next to it, as shown below:

The wiring diagram between ESP32 S3 Keypad 3x4 LCD GPIO Breakout Board

This image is created using Fritzing. Click to enlarge image

  • Wiring diagram between ESP32 S3 and Keypad 4x4
The wiring diagram between ESP32 S3 Keypad LCD

This image is created using Fritzing. Click to enlarge image

Jumper wires are good for a quick test, but not for a final build. A Screw Terminal Block for ESP32 S3 solves this. Plug the ESP32 S3 into it and screw the wires in. The wiring stays the same. Only the wires now go to the screw terminals, as shown below.

The wiring diagram between ESP32 S3 Keypad LCD Screw Terminal

This image is created using Fritzing. Click to enlarge image

You can also use a GPIO Breakout Board for ESP32 S3. It gives each GPIO its own S, 3.3V and GND pins, so module wires plug straight in:

The wiring diagram between ESP32 S3 Keypad LCD GPIO Breakout Board

This image is created using Fritzing. Click to enlarge image

Safety Notes

Always connect the LCD I2C VCC pin to the 5V (VBUS) rail rather than the 3.3V rail — the LCD backlight and driver circuit require 5V and will produce dim or no output at lower voltages. The keypad signal lines run at 3.3V logic, which the ESP32 S3 GPIOs handle natively, so no level shifting is needed between the keypad and the board.

Component Pin ESP32 S3 Pin
Keypad 3x4 Row 1 GPIO1
Keypad 3x4 Row 2 GPIO2
Keypad 3x4 Row 3 GPIO42
Keypad 3x4 Row 4 GPIO41
Keypad 3x4 Col 1 GPIO40
Keypad 3x4 Col 2 GPIO39
Keypad 3x4 Col 3 GPIO38
LCD I2C VCC 5V
LCD I2C GND GND
LCD I2C SCL GPIO9 (I2C Clock)
LCD I2C SDA GPIO8 (I2C Data)

ESP32 S3 Code - Keypad 3x4 - LCD I2C

The following code initializes the 3x4 keypad and the LCD I2C display, then enters a loop that polls the keypad for a pressed key and prints it to the LCD in real time. It uses the keypad library by Mark Stanley and Alexander Brevig to handle matrix scanning, and the DIYables LCD I2C library to keep display updates to a single, readable function call.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-keypad-lcd */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-keypad-lcd */ #include <Keypad.h> #include <DIYables_LCD_I2C.h> #define ROW_NUM 4 // four rows #define 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] = {1, 2, 42, 41}; // GPIO1, GPIO2, GPIO42, GPIO41 connect to the row pins byte pin_column[COLUMN_NUM] = {40, 39, 38}; // GPIO40, GPIO39, GPIO38 connect to the column pins Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); DIYables_LCD_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows int cursorColumn = 0; void setup(){ lcd.init(); // initialize the lcd lcd.backlight(); } void loop(){ char key = keypad.getKey(); if (key) { lcd.setCursor(cursorColumn, 0); // move cursor to (cursorColumn, 0) lcd.print(key); // print key at (cursorColumn, 0) cursorColumn++; // move cursor to next position if(cursorColumn == 16) { // if reaching limit, clear LCD lcd.clear(); cursorColumn = 0; } } }

※ NOTE THAT:

The LCD I2C address can be different from each manufacturer. In the code, we used address of 0x27 that is specified by DIYables manufacturer. If your LCD displays nothing, try address 0x3F instead.

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the keypad and LCD I2C to the ESP32 S3 following the wiring diagram above.
  3. Connect the ESP32 S3 board to your PC using a USB Type-C cable.
  4. Open Arduino IDE on your PC.
  5. Select the correct ESP32 S3 board and COM port from the Tools menu.
  6. Click the Libraries icon on the left bar of the Arduino IDE.
  7. Type "keypad" in the search box, then look for the keypad library by DIYables.
  8. Click the Install button to install the keypad library.
  • Search for DIYables_Keypad created by DIYables.io and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 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
ESP32S3 Dev Module on COM15
1
  1. Type "DIYables LCD I2C" in the search box, then look for the DIYables_LCD_I2C library by DIYables.
  2. Click the Install button to install the DIYables_LCD_I2C library.
  • Search for DIYables LCD I2C created by DIYables.io and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
DIYables LCD I2C by DIYables.io
This library is designed for HD44780-based I2C LCD displays. It provides LiquidCrystal-compatible API plus helper functions (text alignment, progress bars, predefined custom characters). Supports multiple I2C buses (Wire, Wire1, Wire2) for advanced boards like Arduino Giga, Due, and ESP32. Compatible with all Arduino-based platforms including Arduino Uno, Mega, Nano, ESP32, ESP8266, STM32, and Raspberry Pi Pico. More info
1.0.0
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Copy the above code and paste it into Arduino IDE.
  2. Click the Upload button to compile and upload the code to your ESP32 S3.
Arduino IDE Upload Code
  1. Press some keys on the keypad.
  2. Watch the pressed characters appear on the LCD display.
  3. Pro Tip: If the LCD does not display anything, adjust the contrast potentiometer on the back of the LCD module and verify the I2C address in the code matches your module (try 0x3F if 0x27 does not work). See Troubleshooting on LCD I2C for more help.

Serial Monitor Output

The following Serial Monitor output shows the ESP32 S3 detecting key presses from the 3x4 keypad and printing each pressed character. Each line is timestamped so you can verify that every press is captured immediately and in the correct order.

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 10:22:01] Key pressed: 1 [2026-06-16 10:22:03] Key pressed: 4 [2026-06-16 10:22:05] Key pressed: * [2026-06-16 10:22:07] Key pressed: #
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

ESP32 S3 Code - Keypad 4x4 - LCD I2C

The following code adapts the keymap and pin configuration for a 4x4 matrix keypad while keeping the same LCD I2C display logic. Switching from a 3x4 to a 4x4 keypad adds the letters A, B, C, and D, giving you a richer character set for menu systems or access-control interfaces.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-keypad-lcd */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-keypad-lcd */ #include <Keypad.h> #include <DIYables_LCD_I2C.h> #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] = {1, 2, 42, 41}; // GPIO1, GPIO2, GPIO42, GPIO41 connect to the row pins byte pin_column[COLUMN_NUM] = {40, 39, 38, 47}; // GPIO40, GPIO39, GPIO38, GPIO47 connect to the column pins Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); DIYables_LCD_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows int cursorColumn = 0; void setup(){ lcd.init(); // initialize the lcd lcd.backlight(); } void loop(){ char key = keypad.getKey(); if (key) { lcd.setCursor(cursorColumn, 0); // move cursor to (cursorColumn, 0) lcd.print(key); // print key at (cursorColumn, 0) cursorColumn++; // move cursor to next position if(cursorColumn == 16) { // if reaching limit, clear LCD lcd.clear(); cursorColumn = 0; } } }

Application and Project Ideas

Once you can capture keypad input and display it on the LCD with your ESP32 S3, you can extend this project into a wide range of practical input-driven applications.

  1. PIN-entry lock: Collect a sequence of key presses, compare it with a stored PIN, and unlock a relay or solenoid when the codes match.
  2. Calculator: Parse numeric keys and operators typed on the keypad, evaluate the expression, and display the result on the LCD.
  3. Menu navigation system: Use the keypad to scroll through options on the LCD and select actions such as toggling outputs or adjusting settings.
  4. Access-control terminal: Log each key press with a timestamp to an SD card and display access-granted or access-denied messages on the LCD.
  5. Simple alarm panel: Let the user arm or disarm an alarm by entering a code on the keypad, with status messages shown on the LCD.
  6. Data entry terminal: Use the keypad to enter numeric values for setpoints, thresholds, or configuration parameters that are stored in flash memory.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenge Yourself

Now that key presses are appearing on the LCD with your ESP32 S3, try these progressively harder challenges to deepen your understanding and build more capable input interfaces.

  1. Beginner: Modify the sketch to clear the LCD after every five key presses so the display always shows only the most recent input.
  2. Beginner: Add a backspace feature — pressing the star key (*) removes the last character from the LCD display.
  3. Intermediate: Implement a simple four-digit PIN check: collect four key presses, compare the result to a stored PIN, and display "ACCESS GRANTED" or "ACCESS DENIED" on the LCD.
  4. Intermediate: Add a timeout so the LCD clears automatically if no key is pressed within ten seconds, helping to protect sensitive input in a shared environment.
  5. Advanced: Build a numeric calculator that evaluates simple arithmetic expressions entered on the keypad and shows the result on the second row of the LCD.
  6. Advanced: Store a user-configurable PIN in ESP32 S3 flash memory so it survives power cycles, and add a setup mode that lets the user change the PIN through the keypad itself.

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