ESP32 C3 Super Mini - Keypad - LCD

This tutorial shows you how to use the ESP32 C3 Super Mini with a keypad and an LCD display. You will program the board to show each pressed key on the LCD, with no computer needed to read the result. This ESP32 C3 Super Mini keypad LCD project is a great base for a door lock or a menu.

In this tutorial, you'll learn:

ESP32 C3 Super Mini - Keypad - LCD

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×LCD I2C Display 3.3V
1×Alternatively, LCD I2C 20x4
1×Keypad
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

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

The keypad is an input pad that sends the pressed key to the board, and the LCD I2C is a display that shows text using only two data wires.

Key Features:

  • Keypad: Gives you 12 keys: 0-9, star and hash
  • LCD I2C: Shows 2 rows of text with 16 characters in each row
  • No keypad power: The keypad needs no VCC and no GND wire

Technical Specifications:

  • Keypad layout: 4 rows x 3 columns
  • Keypad pins: 7 pins (R1, R2, R3, R4, C1, C2, C3)
  • LCD I2C power: 5V
  • LCD I2C address: Usually 0x27 or 0x3F, depending on the manufacturer

We have a full tutorial for each part, with the pinout, how it works, wiring and code:

Pinout

The two parts have 11 pins in total.

Keypad 3x4:

  • R1: Row 1, the top row of keys (1, 2, 3)
  • R2: Row 2, the second row of keys (4, 5, 6)
  • R3: Row 3, the third row of keys (7, 8, 9)
  • R4: Row 4, the bottom row of keys (*, 0, #)
  • C1: Column 1, the left column (1, 4, 7, *)
  • C2: Column 2, the middle column (2, 5, 8, 0)
  • C3: Column 3, the right column (3, 6, 9, #)

LCD I2C:

  • VCC: Connect to 5V power
  • GND: Connect to ground (0V)
  • SDA: I2C data signal
  • SCL: I2C clock signal

Wiring Diagram

Connect both parts to the ESP32 C3 Super Mini as shown below.

  • Note: Unplug the USB cable before you change any wire.
  • Note: The LCD uses the 5V pin for power. The keypad has no power wire.
The wiring diagram between ESP32 C3 Super Mini Keypad LCD

This image is created using Fritzing. Click to enlarge image

No breadboard? The same circuit can be wired without one, as shown below:

The wiring diagram between ESP32 C3 Super Mini Keypad LCD  (No Breadboard)

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
LCD I2C Pin ESP32 C3 Super Mini Pin
VCC 5V
GND GND
SDA GPIO8
SCL GPIO9

ESP32 C3 Super Mini Code - Keypad 3x4 - LCD I2C

The code below reads the keypad and shows each pressed key on the LCD.

What This Code Does:

  • Uses I2C: The LCD uses the default I2C pins of the board: GPIO8 (SDA) and GPIO9 (SCL)
  • Starts the LCD: Turns on the LCD and its backlight
  • Reads the keypad: Checks for a pressed key again and again
  • Shows the key: Prints each key on the first row, one position after the other
  • Starts over: Clears the LCD when the cursor reaches position 16
/* * 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-lcd */ #include <Keypad.h> #include <DIYables_LCD_I2C.h> #define ROW_NUM 4 // four rows #define COLUMN_NUM 3 // three columns byte pin_rows[ROW_NUM] = {2, 3, 4, 5}; // The ESP32 C3 SuperMini pin connected to the row pins of the keypad byte pin_column[COLUMN_NUM] = {6, 7, 10}; // The ESP32 C3 SuperMini pin connected to the column pins of the keypad char key_layout[ROW_NUM][COLUMN_NUM] = { {'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}, {'*', '0', '#'} }; Keypad keypad = Keypad( makeKeymap(key_layout), 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 cursor = 0; void setup() { lcd.init(); // Initialize the LCD I2C display lcd.backlight(); } void loop() { char key = keypad.getKey(); if (key) { if (cursor == 16) { // if reaching limit, clear LCD lcd.clear(); cursor = 0; } lcd.setCursor(cursor, 0); // move cursor to (cursor, 0) lcd.print(key); // print key at (cursor, 0) cursor++; // move cursor to next position } }

※ 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

Detailed Instructions

Follow these bullets to run the project.

  • 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: Connect the parts as shown in the wiring diagram.
  • Connect your board: Plug the ESP32 C3 Super Mini into your computer with a USB Type-C cable.
  • Open the IDE: Launch the Arduino IDE on your computer.
  • Select your board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
  • Select your port: Choose the matching COM port.
  • Open the Library Manager: Click the Libraries icon on the left bar of the Arduino IDE.
  • Search for the keypad library: Type “keypad” in the search box, then look for the keypad library by Mark Stanley, Alexander Brevig.
  • Install the keypad library: Click the Install button.
ESP32 C3 Super Mini keypad library
  • Search for the LCD library: Type “DIYables LCD I2C” in the search box, then look for the DIYables_LCD_I2C library by DIYables.
  • Install the LCD library: Click the Install button.
ESP32 C3 Super Mini DIYables LCD I2C library
  • Copy the code: Copy the code above and paste it into the Arduino IDE.
  • Upload the code: Click the Upload button to compile and upload the code to your ESP32 C3 Super Mini.
Arduino IDE Upload Code
  • Test it: Press some keys on the keypad.
  • See the result: Watch the keys appear on the LCD.
  • Pro Tip: If the LCD backlight is on but you see no text, turn the small contrast screw on the back of the LCD.

If the LCD does not display anything, see Troubleshooting on LCD I2C

Line-by-line Code Explanation

The above ESP32 C3 Super Mini code contains line-by-line explanation. Please read the comments in the code!

Application and Project Ideas

You can use this ESP32 C3 Super Mini keypad LCD project as the base for many useful builds.

  • Door lock panel: Type a PIN code and see each digit on the LCD
  • Simple calculator: Type numbers and show the result on the LCD
  • Menu system: Pick a setting with the keys and show it on the LCD
  • Timer setter: Type a time in seconds and show the countdown
  • Quiz box: Let players type an answer and show the score

Challenge Yourself

Ready to do more with your ESP32 C3 Super Mini, keypad and LCD? Try these challenges.

  • Easy: Show a welcome message on the LCD when the board starts
  • Easy: Clear the LCD when the * key is pressed
  • Medium: Use the second row when the first row is full
  • Medium: Show a star on the LCD instead of the real key, to hide a password
  • Advanced: Check a password and show "Correct" or "Wrong" on the LCD
  • Advanced: Add a relay that opens a door lock when the password is correct

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