What is the actual circuitry of a keypad and the switch

Hi, I have a question about how the switches and circuit in a keypad work. My understanding is that each switch has two pins, one pin is connected to the row wire and the other connect to the column wire.

There needs to be diode too to prevent ghosting. diode can be installed in either the row wire or the column wire, as long as there is one diode per switch.

Now here is my questions: looking at the switches belonging to the same row wire, should the switches block the wire connection or be on the side? Like switches shouldn't be in the row wire but on the side of it. Just like the image on the right:

Awesome looks like my understanding is correct. Is 10k the conventional resistance for each row and column wire? Does the diode and resistor value have to change just because I am planning on building a 19 by 19 grid?

And thank you for replying so fast!

Just add as many rows and columns as needed; copy the same elements (diodes/resistors) that you see in the schematic.

The following (Fig-1) is the internal structure of the 4x4 Keypad that we usually use with Arduino UNO. There are no resistors and diodes. However, it works well by virtue of the Keypad.h Library.

Probably, the Library adds the internal pull-up resistors (Fig-2) of the IO lines of the MCU with the Row Lines of the Keypad.


Figure-1:


Figure-2:

Based on the image, there doesn't seem to be any resistors inside the keypad. The resistors are in Arduino itself right??

The pull-up resistors can be external or you can use the built in internal ones.

What is your Arduino? A 19x19 matrix will require 38 I/O pins.

I've used decade counters to consolidate the outs to two pins. You could use as few as 21.

I am using a uno for testing prototype and have a mega for the high number of pins. @er_name_not_found do you mind sharing more details of how you reduced pin count?

You have to provide an output for each column pin C1-C4 in the diagrams posted by @GolamMostafa
You can use a decade counter (CD4017) or two to do this in sequence by using one pin for the clock and one for the reset. You can chain decade counters by splitting the clock and reset signals for both and using the carry outs as the clock inhibits for each other.
With two decade counters you can provide up to 20 columns.

Edit: If you want to use multipress, I think you have to add diodes to all the decade counter outputs to prevent feeding current back into the chip the wrong way.

1 Like

Yes! Having read the Keypad.h Library, I have understood so.

I believe not, if all the switches have individual diodes.

True, but only

Which is not the case for the little membrane keypads as well as others.
If the new keypad is modeled as the schematic provided by @LarryD then the diodes are included and can be omitted, as you say.

Interesting. I wonder if the keypad library tristates the inactive column pins to avoid that.

Keypad/Keypad.cpp at master · Chris--A/Keypad · GitHub
Quick glance says no.

I'm pretty sure it will tank the CD4017 though.

The 4x4 Keypad that goes with Keypad.h Library is a Walking-0 keypad. The Row Lines of the keypad are terminated by pull-ups and the Column lines are scanned by a Walking-0 (Fig-1 of post #6) of about 1 kHz. Whenever a key is pressed, the corresponding Row Line assumes LOW state which immediately appears as an information to the MCU.

We know. The question is, what happens when column lines are shorted by multiple keys?

I would say that the column lines are not shorted; rather, multiple keys could be pressed at the same time.

As the said Keypad does not have built-in electronics like PC's Keyboard or an 8279 Keyboard Controller, it does not support 2/n-key lock out; where, all the pressed key must be released except one key for recognition.