Arduino uno + 4×4 Keypad Matrix + LCD i2c screen

Hello everyone, this is the simplest way to use a keypad with an Arduino UNO.


Keypad pins (from 8 to 1) it’s written on the kaypad, are wired with the Arduino UNO digital pins from (9 to 2).

LCD display is wired on 5v, GND, SDA with Analog4 and SCL with Analog5

Don’t forget to download the libraries if you don’t have them already, go to Arduino IDE, Sketch, Include libraries, Manage libraries, then search for the name of the library as in the code and install it.

Hope you enjoy


//Hello, This is the code to use a 4x4 keypad matrix with and Arduino and show the result on an LCD screen
//You should wire you keypad from 8to1 (keypad pins) to 9to2 Arduino digital pins

#include <Keypad.h> //The keypad and LCD i2c libraries
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 //defining the LCD pins
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
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'}

byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3 //if you modify your pins you should modify this too
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()
            lcd.begin (16,2);
            lcd.home ();
            lcd.print("Press a key");

void loop()
         char keypressed = myKeypad.getKey();
         if (keypressed != NO_KEY)
//            Serial.println(keypressed); Uncomment this to show it on the serial monitor too

2 thoughts on “Arduino uno + 4×4 Keypad Matrix + LCD i2c screen

Add yours

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

Up ↑

%d bloggers like this: