How to Build a Keypad-Controlled LED With an ESP32

by taste_the_code in Circuits > Arduino

71 Views, 0 Favorites, 0 Comments

How to Build a Keypad-Controlled LED With an ESP32

Create a Smart Keypad Access System with ESP32! — EEmentor Kit Review

I just built a simple security system using a keypad and an ESP32, where I can turn an LED on and off by entering a secret code.

It's a fantastic beginner project that teaches you the basics of input and output, and you can easily expand it later to control a door lock or a room light with a relay.

I made a full video of the entire build process, which you can watch for a more visual guide. I also used components from an IoT starter kit that was sent to me, and I'll share my honest thoughts on it below.

The video and article are sponsored by Altium Develop!

Supplies

video.00_00_23_03.Still003.jpg

EEmentor IoT Starter Kit - https://shop.eementor.co/product/eementor-iot-esp32-starter-kit/


  1. ESP32 Dev Module - https://s.click.aliexpress.com/e/_c3o6V7Oz
  2. 4×4 Membrane Keypad - https://s.click.aliexpress.com/e/_c43EqllL
  3. LEDs - https://s.click.aliexpress.com/e/_c3eVShzx
  4. Resistors - https://s.click.aliexpress.com/e/_c4bWFn6H
  5. Breadboard Jumper Cables - https://s.click.aliexpress.com/e/_c31PjJkD
  6. Breadboards - https://s.click.aliexpress.com/e/_c3viKyqp
  7. Bench Power Supply - https://s.click.aliexpress.com/e/_c2xpoHD3
  8. Soldering Station - https://s.click.aliexpress.com/e/_c35ymMfb
  9. Multimeter - https://s.click.aliexpress.com/e/_c3UjPXwd

Connect the Keypad to the ESP32

MVI_2598.MP4.00_00_00_01.Still001.jpg
MVI_2598.MP4.00_00_35_09.Still002.jpg
MVI_2600.MP4.00_00_04_10.Still001.jpg
MVI_2601.MP4.00_00_23_11.Still001.jpg

The keypad has eight pins—four for the rows and four for the columns.

I connected them directly to digital pins on the ESP32. For the rows, I used pins 19, 18, 5, and 17. For the columns, I used pins 16, 4, 0, and 2.

I found that plugging them in directly worked better than using an expansion board, which sometimes gave me a bad connection.

Load the Basic Keypad Test Code

2025-11-19 17-41-27.mp4.00_01_19_00.Still001.jpg

Next, I wrote the code to read the keypad.

I used the Keypad library for Arduino, which makes it easy. The code defines the keypad layout and links the rows and columns to the correct pins.

The main loop just checks for a key press and prints it to the Serial Monitor.

This lets you test that every button works before moving on. You can find the complete code here.

Add the LED and Secret Code Logic

MVI_2604.MP4.00_00_24_13.Still001.jpg
2025-11-19 18-11-49.mp4.00_02_16_04.Still001.jpg

Once the keypad was working, I added an LED to pin 22 with a current-limiting resistor.

Then, I upgraded the code. I created a list of allowed secret codes, like "1234" and "5678".

Now, when I type a code and press the '#' key, the code checks if it's correct.

If it is, it toggles the LED on or off. The '*' key works as a clear button if I make a mistake.

The full, complete code is available here.

Final Thoughts

video.00_00_04_27.Still001.jpg
video.00_00_12_18.Still002.jpg

After uploading the final code, the system works perfectly. Entering "1234#" turns the LED on, and "5678#" turns it off.

It’s a rewarding project that shows how a few simple components can create an interactive system. For a complete demo and a deeper look at the components I used, please watch my full video on this project.

If you found this guide helpful, I’d really appreciate it if you’d subscribe to my channel for more tutorials like this.

Your support allows me to keep making these projects and reviews!