Toll-Free Customer Support 24/7

4x4-matrix keypad aurdino code

/*
* Project name:
4x4 keypad
* Copyright
(c) Researchdesignlab.com
* Description:

* Test configuration:
MCU: ATMEGA328
Dev.Board: Arduino uno
Oscillator: 16 MHz
Software: Arduino

*/


#include <Keypad.h>
#include <LiquidCrystal.h> // initialize the library with the numbers of the

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

/*
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9
* LCD D4 pin to digital pin 10
* LCD D5 pin to digital pin 11
* LCD D6 pin to digital pin 12
* LCD D7 pin to digital pin 13
* LCD R/W pin to ground */

 

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'}, //define the cymbols on the buttons of the keypads
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad


Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad

void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
}

void loop()
{
char customKey = customKeypad.getKey();

if (customKey)
{
lcd.setCursor(0,1);
lcd.print(customKey);
}
}

 

Back to top