ESP32 S3 - Keypad 3x4
This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://newbiely.com/tutorials/esp32-s3/esp32-s3-keypad-3x4
This build connects a 3x4 membrane keypad to an ESP32 S3 so you can read individual key presses and use them to check a password. The keypad uses seven GPIO pins for row and column scanning, with no separate power pin needed, and the DIYables_Keypad library handles the scanning and key detection in code.
Supplies
Everything below is what the build uses. The links go to the parts we make and test.
- ESP32 S3 WROOM N16R8
- ESP32 S3 SuperMini Dev Module
- ESP32 S3 Uno-form Board
- ESP32 S3 Camera Board
- USB Cable Type-A to Type-C (for USB-A PC)
- USB Cable Type-C to Type-C (for USB-C PC)
- Keypad 3x4
- Jumper Wires
- Screw Terminal Expansion Board for ESP32 S3
- Breakout Expansion Board for ESP32 S3
- Power Splitter for ESP32 S3
- DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
- DIYables Sensor Kit (18 sensors/displays)
Wiring
Connect the keypad's four row pins R1-R4 to GPIO17, GPIO16, GPIO15, and GPIO7 on the ESP32 S3. Connect the three column pins C1-C3 to GPIO6, GPIO5, and GPIO4. The keypad runs on 3.3V logic and needs no separate power pin, so these seven connections are all that's required. Make sure each wire is seated firmly in its slot, since loose wiring is the usual cause of missed or swapped keys.
How It Works
The ESP32 S3 scans the row and column lines in sequence to figure out which of the 12 keys is pressed, using only the seven GPIO connections. In the password version, every key press that isn't '*' or '#' gets appended to an input string. Pressing '#' compares that string against a pre-defined password in the sketch and then clears it, while pressing '*' clears the input without checking anything.
Code
The sketch defines the 4x3 key layout as a character array and passes it, along with the row and column pin arrays, to the Keypad library to build a keypad object. The main loop calls getKey() continuously and prints any detected character to the Serial Monitor. The password version builds on this by accumulating characters into a string and running the compare/clear logic described above when '#' or '*' is pressed.
esp32-s3-keypad-3x4.ino - the sketch from the tutorial, unchanged.
Things That Go Wrong
If key presses don't register or the wrong character shows up, check that the row and column wires aren't swapped and that each jumper is pushed in all the way. If nothing appears in the Serial Monitor, confirm the baud rate there matches the Serial.begin() value in the sketch and that the correct board and port are selected in the Arduino IDE. Also confirm the DIYables_Keypad library is installed before uploading.
Full Tutorial
The complete tutorial, wiring diagram and code explanation: https://newbiely.com/tutorials/esp32-s3/esp32-s3-keypad-3x4