ESP32 S3 UNO - Keypad - LCD

This ESP32 S3 Uno keypad LCD tutorial shows you how to read the keys of a 3x4 keypad and print them on a 16x2 LCD I2C display. You will build it on the ESP32 S3 Uno form board with the Arduino IDE. Every key you press appears on the LCD screen, so it is a good base for a password lock or a number input project.

In this tutorial, you will:

  1. Wire a 3x4 keypad and an LCD I2C display to the ESP32 S3 Uno
  2. Install the DIYables keypad and LCD I2C libraries
  3. Read key presses with the getKey() function
  4. Display each pressed key on the LCD and clear it when the line is full

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×LCD I2C Display 3.3V
1×Alternatively, LCD I2C 20x4
1×Keypad 3x4
1×Breadboard
1×Jumper Wires
1×5V to 3.3V Level Converter (Optional, for SDA and SCL)

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 .

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

This project joins two parts you may already know. The keypad is the input, and the LCD is the output. If one of them is new to you, read its own tutorial first. There you will find the pinout, how the part works and a simple test sketch.

How the two parts work together

The 3x4 keypad has 7 pins: 4 row pins and 3 column pins. The ESP32 S3 Uno scans these pins to find which key is pressed. The LCD I2C needs only two signal wires, SDA and SCL, so the keypad and the LCD share the board without any pin conflict.

ESP32 S3 Uno Pinout

The image below shows the pinout diagram of the ESP32 S3 Uno form board. Use it to find the D3 to D9 pins for the keypad and the SDA and SCL pins for the LCD, with their GPIO numbers.

ESP32 S3 Uno pinout diagram

Wiring Diagram

The keypad goes to the digital pins D3 to D9, and the LCD goes to the I2C header pins. Follow the diagram and the tables below.

The wiring diagram between ESP32 S3 Uno Keypad LCD

This image is created using Fritzing. Click to enlarge image

Keypad wiring

Keypad Pin ESP32 S3 Uno Pin
R1 (Row 1) D9 (GPIO46)
R2 (Row 2) D8 (GPIO21)
R3 (Row 3) D7 (GPIO14)
R4 (Row 4) D6 (GPIO3)
C1 (Column 1) D5 (GPIO20)
C2 (Column 2) D4 (GPIO19)
C3 (Column 3) D3 (GPIO17)

WARNING

Two keypad rows use boot strapping pins. D9 (GPIO46) and D6 (GPIO3) are read by the ESP32 S3 Uno when it starts. If a key on row 1 or row 4 is held down during power-up or reset, the board may not boot or may fail to upload code. Do not press any key while you reset the board or upload the sketch.

LCD I2C wiring

LCD I2C Pin ESP32 S3 Uno Pin
GND GND
VCC 5V
SDA SDA (GPIO8)
SCL SCL (GPIO9)

On this board, A4 and A5 are only analog pins. The I2C bus is on the SDA (GPIO8) and SCL (GPIO9) header pins, and the LCD library uses them by default.

WARNING

The ESP32 S3 Uno pins work at 3.3V and are NOT 5V tolerant. Many LCD I2C backpacks pull SDA and SCL up to their own VCC, so with 5V power these lines can sit at 5V. To protect the board, put a bidirectional 5V to 3.3V level converter on SDA and SCL, or remove the pull-up resistors on the backpack.

ESP32 S3 Uno Code

The sketch scans the keypad all the time. When you press a key, it prints that character on the first line of the LCD and moves the cursor one step to the right. After 16 characters the line is full, so the code clears the screen and starts again from the left.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-keypad-lcd */ #include <DIYables_Keypad.h> // DIYables_Keypad library #include <DIYables_LCD_I2C.h> const int ROW_NUM = 4; // four rows const int 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] = { 46, 21, 14, 3 }; // ESP32 S3 Uno D9, D8, D7, D6 - connect to the row pinouts of the keypad byte pin_column[COLUMN_NUM] = { 20, 19, 17 }; // ESP32 S3 Uno D5, D4, D3 - connect to the column pinouts of the keypad DIYables_Keypad keypad = DIYables_Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); DIYables_LCD_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows int cursorColumn = 0; void setup(){ lcd.init(); // initialize the lcd (uses SDA = GPIO8, SCL = GPIO9 on the ESP32 S3 Uno) 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 I2C address of the LCD can be different from one maker to another. This code uses 0x27, which is the address given by the maker DIYables. If your screen stays blank, run an I2C scanner to find the real address.

Detailed Instructions

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Wire it up as shown in the diagram, with the keypad on D3 to D9 and the LCD on the SDA and SCL header pins.
  3. Connect the board to your computer with a USB Type-C cable.
  4. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  5. Open the Library Manager by clicking the Libraries icon on the left side of the Arduino IDE.
  6. Install the keypad library. Type DIYables_Keypad in the search box, find the library by DIYables.io and 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
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. Install the LCD library. Search for DIYables LCD I2C, find the DIYables_LCD_I2C library by DIYables and click Install.
  • 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 code above and paste it into the Arduino IDE.
  2. Upload the code by clicking the Upload button. Do not press any keypad key during the upload.
Arduino IDE Upload Code
  1. Press some keys on the keypad.
  2. Check the LCD. Each key you press shows up on the first line.
  3. Tip: If the LCD shows nothing, turn the small blue contrast knob on the back of the LCD, then read the LCD I2C troubleshooting guide.

Code Explanation

The comments inside the code explain each line. In short, the keys array maps every button to a character, and the pin_rows and pin_column arrays tell the library which GPIO pins the keypad uses. In loop(), keypad.getKey() returns the pressed key, or nothing if no key is pressed. The cursorColumn variable keeps track of where the next character goes on the LCD.

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

FAQ

Can I power the LCD I2C from the 3.3V pin of the ESP32 S3 Uno?

Most 16x2 LCD I2C modules are made for 5V. At 3.3V the text is often very faint or not visible at all. Power the LCD from 5V and protect SDA and SCL with a level converter, or use an LCD module that is rated for 3.3V.

Why do I wire the LCD to SDA and SCL and not to A4 and A5?

On the ESP32 S3 Uno, A4 (GPIO5) and A5 (GPIO4) are only analog pins. The I2C bus is on the SDA (GPIO8) and SCL (GPIO9) header pins. The LCD library calls Wire.begin(), which uses these two pins by default.

Why does the code use GPIO numbers like 46 and 14 instead of 9 and 7?

The ESP32 S3 Uno code always uses GPIO numbers, not the Uno header labels. The header D9 is GPIO46, D7 is GPIO14, and so on. Look at the wiring table or the pinout image to match each label with its GPIO number.

Can I show the keys on the second line of the LCD too?

Yes. Add a row variable and call lcd.setCursor(cursorColumn, 1) when the first line is full. Clear the LCD only when both lines are full. This gives you 32 characters before the screen resets.

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 keypad inputs, GPIO35 to GPIO42 or GPIO15/GPIO16 are good choices. Do not use GPIO47/GPIO48 for the keypad, 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, and 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 appears in the Arduino IDE USB driver missing or board not in upload mode Install the CP210x or CH340 driver, try another USB cable, or hold BOOT while you press RESET
Upload fails or the board does not start A key on row 1 or row 4 is pressed, which pulls D9 (GPIO46) or D6 (GPIO3) at boot Do not touch the keypad during upload or reset, then try again
LCD backlight is on but no text shows Contrast too low or wrong I2C address Turn the contrast knob on the back of the LCD and check the address with an I2C scanner
LCD stays dark Loose wires or no 5V power on the LCD Check that VCC goes to 5V and GND goes to GND, and press each jumper wire firmly
LCD does not work at all SDA and SCL wired to A4 and A5 Move the wires to the SDA (GPIO8) and SCL (GPIO9) header pins
Wrong character appears for a key Row or column wires swapped Compare each keypad wire with the wiring table, R1 to D9 and C1 to D5
Some keys do nothing A row or column wire is loose or broken Check the wires for that row or column and replace any bad jumper
Compile error about a missing header file Library not installed Install DIYables_Keypad and DIYables_LCD_I2C from the Library Manager

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