Membrain Keypad 4x4 Numeric Matrix Array
-
RM8.50
- Product Code: Keypad Membrain 4x4
- Availability: In Stock
This 16-button keypad provides a useful human interface component for microcontroller projects. Convenient adhesive backing provides a simple way to mount the keypad in a variety of applications.
Key Features:
Application Ideas:
Features:
How it worksMatrix keypads use a combination of four rows and four columns to provide button states to the host device, typically a microcontroller. Underneath each key is a pushbutton, with one end connected to one row, and the other end connected to one column.In order for the microcontroller to determine which button is pressed, it first needs to pull each of the four columns (pins 1-4) either low or high one at a time, and then poll the states of the four rows (pins 5-8). Depending on the states of the columns, the microcontroller can tell which button is pressed.For example, say your program pulls all four columns low and then pulls the first row high. It then reads the input states of each column, and reads pin 1 high. This means that a contact has been made between column 4 and row 1, so button ‘A’ has been pressed.
When connecting the pins to the Arduino board, we connect them to the digital output pins, D9-D2.
You can download the Keypad library here: Keypad Library. When you download, change the name to folder to something other than Keypad. If the folder and the file you are importing have the same name, it won't work.
/*4x4 Matrix Keypad connected to Arduino This code prints the key pressed on the keypad to the serial port*/ #include <Keypad.h> const byte numRows= 4; //number of rows on the keypad const byte numCols= 4; //number of columns on the keypad //keymap defines the key pressed according to the row and columns just as appears on the keypad char keymap[numRows][numCols]= { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; //Code that shows the the keypad connections to the arduino terminals byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3 byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3 //initializes an instance of the Keypad class Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); void setup() { Serial.begin(9600); } //If key is pressed, this key is stored in 'keypressed' variable //If key is not equal to 'NO_KEY', then this key is printed out //if count=17, then count is reset back to 0 (this means no key is pressed during the whole keypad scan process void loop() { char keypressed = myKeypad.getKey(); if (keypressed != NO_KEY) { Serial.print(keypressed); } }
With this code, once we press a key on the keypad, it should show up on the serial monitor of the Arduino IDE once the code is compiled and uploaded to the Arduino board.
Tags: Keypad