Membrane Keypads are what commonly seen to be used with various prototyping boards – black colored board with blue and red colored keys. Arduino Membrane Matrix Keypad Are Cheap, Versatile For Many Projects and Outweighs Work to Build Keypad From Push Buttons. Matrix keypad is any keypad arranged in matrices, which is an interface technique to interface inputs by dividing keys into columns and the rows. Here is basics of how membrane keypad words, setup of membrane keypad wit Arduino and required sample code.
How Arduino Membrane Matrix Keypad Works
As said earlier, matrices are an interface technique. Here, the I/O is divided into columns and the rows (like spread sheet). We mention them as like – 4 x 4, 3 x 4 matrix keyboard etc. 16 or 12 keys sit on column and rows like #
symbol. That creates 16 or 12 intersecting points. Membranes are nothing but one side conductor coated films. Upon pressing a key, the conductor will have a push-to-make contact to connect the column and the row at particular point. Like :
1 2 3 4 5 6 7 8 | A B C i +---+---+ | | | ii +---+---+ | | | iii +---+---+ | | | iv +---+---+ |
From the above line diagram, if you thing each +
sign as keys like :
---
1 2 3 4 5 6 7 8 | A B C i 1---2---3 | | | ii 4---5---6 | | | iii 7---8---9 | | | iv *---0---# |
So key 5 is located at B, ii. Key 0 is located at B, iv. In this way, each keys has unique address. When you are pressing Key 5, then you are making whole B column and ii row connected to electricity. You can actually create a basic matrix keyboard with metal foil or conductive tape and just with battery you can light up numbered 12 or 16 LEDs.
So, how many connecting wires a 3 x 4 Arduino Membrane Matrix Keypad will have? 3 + 4 = 7 ! You can see seven wires :
How To Write Code For Arduino Membrane Matrix Keypad?
Now we can write that above concept of connection as code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <Keypad.h> const byte ROWS = 4; //four rows const byte COLS = 3; //three columns char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'#','0','*'} }; byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); ... |
We can write a basic code which will print the value on Arduino IDE’s serial monitor :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <Keypad.h> const byte ROWS = 4; //four rows const byte COLS = 3; //three columns char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'#','0','*'} }; byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); void setup(){ Serial.begin(9600); } void loop(){ char key = keypad.getKey(); if (key != NO_KEY){ Serial.println(key); } } |
Rest to get started you’ll find on official website of Arduino :
1 | https://playground.arduino.cc/Code/Keypad |