Keypad Access 4x4 With Arduino

by sfeelectronics in Circuits > Arduino

3878 Views, 26 Favorites, 0 Comments

Keypad Access 4x4 With Arduino

keypad3.jpeg

The 4x4 keypad is a composite of 16 keys arranged like a matrix. The method used for accessing 4x4 keypad with matrix scanning method. The 4x4 keypad requires 8 pins to access it, ie 4 pins for the columns and 4 pins for the line. How the scanning method works is that the column pin takes the LOW logic interchangeably, then the line pin performs the readings in turn as well.

Materials You Need

You will need:

  • Arduino
  • Keypad 4x4
  • Jumper Wires

Pin Out

  1. PIN A3 --> pin to 0 row
  2. PIN A2 --> pin to 1 row
  3. PIN A1 --> pin to 2 row
  4. PIN A0 --> pin to 3 row
  5. PIN 4 --> pin to 0 colomn
  6. PIN 5 --> pin to 1 colomn
  7. PIN 6 --> pin to 2 colomn
  8. PIN 7 --> pin to 3 colomn

Schematic

keypad2.jpeg
keypad3.jpeg

Connect each component as the picture above.

Code

#include <Keypad.h> //import library keypad
const byte ROWS = 4; //number of colomn
const byte COLS = 4; //number of row
char hexaKeys[ROWS][COLS] = {
 {'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'*','0','#','D'}
};
byte rowPins[ROWS] = {A3, A2, A1, A0}; //pin used for row
byte colPins[COLS] = {4, 5, 6, 7}; //pin used for colomn
//initialization variable
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
 Serial.begin(9600);
}
 
void loop(){
 char customKey = customKeypad.getKey();
 
 if (customKey){
   Serial.println(customKey);
 }
}

Output

kepad5.png

Check the output!