top of page
Writer's picturejugaad club

Session 6 : Matrix keypad

Introduction:

Most of the applications of embedded systems require keypads to take the user inputs, especially in the case where an application requires more keys. With simple architecture and an easy interfacing procedure, matrix keypads are replacing normal push buttons by offering more inputs to the user with the lesser I/O pins. As a Human Machine Interface (HMI) keypad plays a major role in vital microprocessor and microcontroller-based projects and equipment. Therefore, this article gives you a brief idea about the matrix keypad.

A Matrix keypad is the most commonly used input device in many of the application areas like digital circuits, telephone communications, calculators, ATMs, and so on. A matrix keypad consists of a set of push-button or switches which are arranged in a matrix format of rows and columns. These keypads are available in configurations like 3×4 and 4×4 based on the application it is implemented for.



4X4 KEYPAD MODULE Applications:

Case1: When easy to use INPUT, a device is needed. For control systems or embedded systems, there will be a time where human interaction is needed. Like a coffee machine needs a choice selection. In those cases, using a 4X4 KEYPAD MODULE is the best solution.

Case2: The input module can only have few pins. If certain applications are developed of processors with few pins, then that system cannot afford to provide more pins to INPUT DEVICE. At that time using KEYPAD MODULE is ideal, as it can give 16 key inputs for using 8 terminals.

Case3: For a professional look. Using KEYPAD MODULE can give a more professional view of the system than other key INPUT DEVICES.

  • Security systems.

  • Vending machines.

  • Industrial machines.

  • Engineering systems.

  • Measuring instruments.

  • Data entry for Embedded Systems

  • Hobby projects.

  • Anywhere an INPUT device is needed.


Construction:

The buttons on a keypad are arranged in rows and columns. A 3X4 keypad has 4 rows and 3 columns, and a 4X4 keypad has 4 rows and 4 columns:


Beneath each key is a membrane switch. Each switch in a row is connected to the other switches in the row by a conductive trace underneath the pad. Each switch in a column is connected the same way – one side of the switch is connected to all of the other switches in that column by a conductive trace. Each row and column is brought out to a single pin, for a total of 8 pins on a 4X4 keypad:


Pressing a button closes the switch between a column and a row trace, allowing current to flow between a column pin and a row pin.

The schematic for a 4X4 keypad shows how the rows and columns are connected:

The Arduino detects which button is pressed by detecting the row and column pin that’s connected to the button.

This happens in four steps:

1. First, when no buttons are pressed, all of the column pins are held HIGH, and all of the row pins are held LOW:

2. When a button is pressed, the column pin is pulled LOW since the current from the HIGH column flows to the LOW row pin:

3. The Arduino now knows which column the button is in, so now it just needs to find the row the button is in. It does this by switching each one of the row pins HIGH, and at the same time reading all of the column pins to detect which column pin returns to HIGH:

4. When the column pin goes HIGH again, the Arduino has found the row pin that is connected to the button:

From the diagram above, you can see that the combination of row 2 and column 2 could only mean that the number 5 button was pressed.



PROGRAMMING THE KEYPAD :


Circuit Diagram:


Code:

#include <Keypad.h>             
#include <LiquidCrystal.h>        

LiquidCrystal lcd(5, 4, 3, 2, A4, A5);

const byte ROWS = 4; //Four rows
const byte COLS = 4; //Four columns
char keys[ROWS][COLS] = {
 {'1','2','3','A'},   // Values for each key in the 4x4
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'*','0','#','D'}
};
byte rowPins[ROWS] = {A0, A1, 11, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
int LCDRow = 0;

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
 Serial.begin(9600);
 lcd.begin(16, 2);
 lcd.setCursor(LCDRow, 0);
 }
 
void loop(){
 char key = keypad.getKey();
 
 if (key){                       // Display key value
 Serial.println(key);   
 lcd.print(key);
 lcd.setCursor (++LCDRow, 0);
 }
}



Check out the session on our youtube:





Written By:

Dipanshu

2nd year ECE

University Institute of Engineering and Technology, Panjab University

51 views0 comments

Recent Posts

See All

Comments


bottom of page