Circuit Design Tips for a 4x4 Matrix Keypad

March 20, 2020 Cadence PCB Solutions

Pressing a 4x4 matrix keypad

The 4 x 4 keypad is still very much alive.

I was rather amused when my 6-year-old son was recently confused by a dial phone. For someone born in the age of smartphones, it’s hard to imagine actually calling someone by dialing a bunch of numbers. This makes me realize that my age is finally catching up with me.

Even in the electronics world, touch-based displays rule the user interface experience. However, this doesn’t mean that the classic 4x4 mechanical keypad is getting obsolete. Far from it, the mechanical keypad remains a low-cost solution for embedded systems that require a certain degree of parameter calibration.

The Basics of a 4x4 Matrix Keypad

The 4x4 matrix keypad is a simple mechanism that resembles the numeric input on your computer keyboard, except that it has an additional ‘*,’ ‘#’ and 4 other auxiliary buttons that can be used for various functions in the application. The keypad is usually made of plastic materials and is relatively cheap compared to touchscreen displays.

A 4x4 matrix keypad can be implemented separately or within the physical product itself, such as a security access controller, where it is used for PIN identifications. Either way, the mechanism of the mechanical keypad remains the same when hardware and firmware designers are concerned.

If you’ve never designed with a 4x4 mechanical keypad, the best way to visualize the internal mechanism is a matrix of push-button switches. A 4x4 keypad has a total of 8 connections, where 4 of them are connected to the column and the remaining rows of the matrix of switches. 

When an individual button is pressed, a connection is established between one of the rows and columns. The microcontroller then deciphers the physical button based on the index of the row and column that is activated. 

Interfacing the 4x4 Mechanical Keypad With a Microcontroller.

The easiest way for a microcontroller to interface with a 4x4 mechanical keypad is to directly control the rows and columns with the general purpose input and output pins. Each of the rows is connected to an output pin of the microcontroller while the columns are connected to the inputs.

The microcontroller then scans the presence of a ‘key pressed’ event by setting the logic high on one of the outputs to the row while keeping other outputs on a low. This process is repeated for the next output continuously and ultimately loops back to the first output.

Connecting wires

Interfacing is a simple matter of directly connecting to the GPIO of a microcontroller.

Simultaneously, the microcontroller checks for the input values that are connected to the columns. If there is at least one button being pressed, one of the column inputs changes from its default logic state. When an input is detected, the firmware refers to an internal input map to determine the exact physical button that is being pressed.

Debouncing the Keypad

Designing with a 4 x 4 mechanical keypad isn’t rocket science. The hardware schematics require almost no other external components while the firmware follows a simple algorithm that every beginner should pick up pretty easily. There are two finer aspects of the design if you’re serious about ensuring users have a great experience with the keypad.

One of the common issues with a mechanical keypad is the additional pulse that a button can send to the input as it's released. This is due to the spring-like mechanism of the button. This will often result in multiple values of the same button being logged by the firmware. 

Capacitors for electronic circuits

Use capacitor for hardware debouncing.

To prevent the incorrect reading of the keypad, a method called debouncing is being applied. This can be done in the hardware, where a capacitor is in place to filter off the mini pulses that are triggered after the button is released.  

Alternatively, software debouncing can be implemented by firmware developers. Instead of evaluating a single instance of a triggering input, the firmware now samples and filters out impossibly short pulses that cannot be triggered by human interaction. 

It also helps to maintain clearance from other noisy signals that may couple over the electrical noise to the keypad traces. By setting up proper design rules, you can be sure to avoid any difficulty. Managing your design and analysis software is easy with the suite of tools from Cadence. OrCAD PCB Designer is the layout tool you need for any of your electronic hardware designs. 

If you’re looking to learn more about how Cadence has the solution for you, talk to us and our team of experts

About the Author

Cadence PCB solutions is a complete front to back design tool to enable fast and efficient product creation. Cadence enables users accurately shorten design cycles to hand off to manufacturing through modern, IPC-2581 industry standard.

Follow on Linkedin Visit Website More Content by Cadence PCB Solutions
Previous Article
Do Your Circuits Need a Schottky Diode?
Do Your Circuits Need a Schottky Diode?

Schottky diode components are less well-known than silicon diodes, but they provide some important advantag...

Next Article
SiC SPICE Model and Analysis for New MOSFETs
SiC SPICE Model and Analysis for New MOSFETs

If you’re building power amplifiers or RF amplifiers, you need SiC SPICE model and analysis tools in your P...