KEYPAD

 

A keypad is one of the most commonly used input devices in microprocessor applications. In a standard keypad wired as an X-Y switch matrix, normally-open switches connect a row to a column when pressed. If a keypad has 12 keys, it is wired as 3 columns by 4 rows. A 16 key pad would have 4 columns by 4 rows. Some time ago, I bought a couple of 3×4 membrane keypads from eBay. As usual it’s packed with zero documentation, thus it took couple of hours to get to work. Anyway the keypad is a perfect blend of art and technology with a price tag far below rubies!

HOW KEYPADS WORK

 

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:
  1. When a button is pressed, the column pin is pulled LOW since the current from the HIGH column flows to the LOW row pin:
  1. 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:
  1. 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.

 

CONNECT THE KEYPAD AND LCD with Arduino

Once the libraries are installed, connect the ground and Vcc pins of the LCD to the Arduino, then connect the LCD’s SDA and SCL pins according to the table below for the different Arduino boards:

Then connect the keypad to the Arduino. It should look something like this (for an Arduino Uno):

Interfacing With Arduino:

CODE FOR OUTPUT TO AN LCD

 

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <Keypad.h>

 

const byte ROWS = 4;

const byte COLS = 4;

 

char hexaKeys[ROWS][COLS] = {

  {‘1’, ‘2’, ‘3’, ‘A’},

  {‘4’, ‘5’, ‘6’, ‘B’},

  {‘7’, ‘8’, ‘9’, ‘C’},

  {‘*’, ‘0’, ‘#’, ‘D’}

};

 

byte rowPins[ROWS] = {9, 8, 7, 6};

byte colPins[COLS] = {5, 4, 3, 2};

 

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

 

LiquidCrystal_I2C lcd(0x21, 16, 2); 

 

void setup(){

  lcd.backlight();

  lcd.init();

}

 

void loop(){

  char customKey = customKeypad.getKey();

  if (customKey){

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print(customKey);

  }

}’

 

Application:

  • Used in typing in calculator
  • Used in mobiles phones
  • Provide input data as a input device
  • Different types of electronic devices

 

 

Reference:

http://keypadcreator.com/index.php?option=com_content&view=category&layout=blog&id=901&Itemid=59&lang=en

http://www.mt-system.ru/sites/default/files/docs/documents/keypad%20application%20note_v1.0.pdf

https://en.wikipedia.org/wiki/Keypad

https://www.elprocus.com/types-interfacing-devices-applications-with-microcontroller/