Monday, May 25, 2020

Using a 4x4 keypad


The 4x4 Keypad is technical speaking just 16 buttons. Usually you will need one digital input pin for each button which is connected to ground or voltage. So you will need 16 digital input pins plus a common ground/voltage. But the keypad has only eight connectors. How does this work?

The Matrix

The first four pins are connected to all buttons row-wise. The last four pins are also connected to all buttons, but column-wise.
So the first pin has a connection to button 1, 2, 3, A, the second pin to 4, 5, 6, B and so on.
And pin five (the first pin from the other group) is connected to button 1, 4, 7, *.
Keypad matrix

How to read a button-press

In simple terms: if you can measure a connection between pin 2 and pin 6, button 5 is pressed.How can we realize it with an Arduino? You connect all eight pins to digital pins of an Arduino. Declare the first four pins as output pins (that would be the pins, responsible for the rows) and the last four pins as input pins (aka the columns). Then you would pull each of the output pins high (one after another) and read all the input pins. So you pull pin 1 HIGH and read pins 5 to 8. Then you pull pin 1 LOW again and pull pin 2 to HIGH. Again reading pins 5 to 8. You have to continue with pin 3 and 4. And if none of those input pins get a positive reading - you know no button is pressed. Otherwise you know exactly which button was pressed.



4x4 Keypad
Arduino Uno
Breadboard & Jumpercables

No comments:

Post a Comment