ad space

Arduino Keypad and LCD Interfacing with Code

In this Arduino electronics tutorial, you will learn how to interface Arduino with keypad and LCD, how to use Arduino Keypad library and how to code Arduino Keypad with LCD. Here we will be using 4x3 Keypad and 16x2 LCD. Also at the end you will find video demonstration of how it works.

4x3 Keypad, LCD and Arduino on Breadboard

Below picture shows 4x3 membrane keypad, 16x2 LCD with Arduino UNO on a breadboard. 

The interfacing is explained using wiring diagram below.

4x3 Membrane Keypad 

We will be using 4x3 Keypad as shown in the figure below. This type of keypad is called membrane keypad and  are inexpensive and popular among hobbies.  The surface of membrane keypad are soft and flexible and when pressed create a connection with the underlying circuit. Underneath each key is a coil shaped are inductors which induces current/voltage signal when a key is pressed.

Membrane keypad are build using 3 layers. The top and bottom layer are made up of conductive materials while the middle one is non-conductive. When key is not pressed or that is key is open, the middle layer prevents the top and bottom from coming into contract. But when key is pressed and closed, the middle layer creates a small hole that allows the top and bottom layer to come into contact and induce current/voltage.

As you can see from the figure, the keypad has 7 pins with 4 rows and 3 columns. The keypad starts with rows and ends with the column. In the figure, the first 4 rows are labelled as R1, R2, R3 and R4 and the 3 columns are labelled as C1, C2 and C3.

Interfacing Keypad and LCD with Arduino

In the picture below you can see how to interface 4x3 Keypad and LCD with Arduino.


In the schematic diagram above, we have connected the pins 7, 8, 9 and 10 of Arduino to the four row pins R1, R2, R3 and R4 of the 4x3 keypad. Similarly, the Arduino pins 11, 12 and 13 are connected to the three columns C1, C2 and C3 of the keypad. 

We have used the pins A5, 2, 3, 4, 5 and 6 to connect Arduino to the 16x2 LCD. The pin A5 and 2 are connected to the RS and E pins of the LCD respectively. The pins 3, 4, 5 and 6 are connected to the D4, D5, D6 and D7 of the LCD. The R/W pin of the LCD is grounded. A 10KOhm potentiometer is connected to the LCD with its middle pin to the Vee. The other sides of the POT is connected to +5V and ground respectively. The Vss and Vdd of LCD are connected to the ground and +5V supply.

Program Code for Keypad Arduino with LCD

The program code for Arduino to work with 4x3 membrane keypad and LCD is provided below. In this simple code example, we monitor for any key press and when a key is pressed we sent that key pressed to the LCD.

#include <Keypad.h>

#include <LiquidCrystal.h>


// initialize the LCD

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


const byte rows = 4; // set display to 4 rows

const byte cols = 3; // set display to 3 columns

char keys[rows][cols] =

{{'1','2','3'},

{'4','5','6'},

{'7','8','9'},

{'*','0','#'}};

byte rowPins[rows] = {7, 8, 9, 10};

byte colPins[cols] = {11, 12, 13};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols);


void setup () {

      lcd.begin(16, 2);

      lcd.print("Enter Number:");

      delay(3000);

      lcd.clear();

}


void loop() {

char key = keypad.getKey();

if (key != NO_KEY){

		lcd.print(key);

    }

}

 In this program we have used the Arduino Keypad Library. You can install the keypad library by going to Arduino IDE > Tools > Manage Libraries and search for keypad.h and install the one by Mark Stanley and Alexander Brevig as shown in the picture below.

keypad library
Figure: keypad library

Video Demonstration of 4x3 Membrane Keypad Interfacing with LCD and Arduino

Below video shows demo.


You might be interested in other similar tutorials.

Seven Segment Display with Arduino and Shift Register

LCD Display of Temperature and Humidity using DHT11 & Arduino with Code

Post a Comment

Previous Post Next Post