Interface 16x2 Alphanumeric LCD And4x4 Matrix Keypad With Raspberry Pi3




We are a bunch of passionate, enthusiastic and talented engineers with a craze on robotics and em...

In this instructables, we explain how to interface 16x2 LED and 4x4 matrix keypad with Raspberry Pi3.

We use Python 3.4 for developing the software. You can choose Python 2.7 also, with little alterations

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials Required

    We require the following components

  • Raspberry Pi 3
  • 5V 2A Adaptor for Pi
  • 8GB micro SD
  • 16x2 Alphanumeric LCD
  • 4x4 matrix Keypad
  • Dot PCB (medium size) or Breadboard
  • Berg Strip
  • Jumper Wire
  • 10K pot
  • Ethernet Cable (for establishing VNC connection with Laptop)

Step 2: Hardware Setup

We did not Include the steps for hardware setup such as burning OS to the micro SD and VNC interface. You have to find other resources for these procedures.

Insert OS pre-loaded 8GB Micro SD card into Rapberry Pi 3. Connect Raspberry Pi to Laptop by Ethernet Cable. Make the hardware as described in the wiring diagram.

16x2 LCD

We use 4-bit mode lcd interface, so the required pins for Control singals are RS, EN, D4, D5, D6, D7 which is connected to GPIOs of Raspberry Pi.

4x4 Matrix Keypad

Install Python package for 4x4 and 4x3 matrix keypad so that interrupt based operations are performed. Thus no need to scan keypad’s rows and columns all the time. Here internal pull-up used thus no external pull-up resistor required.

Connect Raspberry Pi to web, then open terminal and type the following:

sudo python3.4 -m pip install pad4pi

Step 3: Wiring Diagram

LCD Pins:

  • LCD_RS = 21
  • LCD_E = 20
  • LCD_D4 = 26
  • LCD_D5 = 19
  • LCD_D6 = 13
  • LCD_D7 = 6

KeyPad pins:

Column Pins = 17, 15, 14, 4
Row Pins = 24, 22, 27, 18

You can choose any GPIO pins for interfacing LCD and Keypad, just change pin number in the code. You can either use breadboard or PCB for interfacing LCD and Keypad.

Step 4: Python Code

You can download the code directly. Run with python 3.4 in your Raspberry Pi 3. Or copy the text and paste it in new script file of python 3.4.

Run the progam:

LCD will display the text "Welcome" in the first line if the connections you made are correct. The Keypad data is displayed in the second line.

Step 5: Output Preview

I have added Keyboard interrupt, so that if you terminate program LCD will display Good bye

Raspberry Pi Contest 2017

Participated in the
Raspberry Pi Contest 2017

Be the First to Share


    • Assistive Tech Contest

      Assistive Tech Contest
    • Reuse Contest

      Reuse Contest
    • Made with Math Contest

      Made with Math Contest

    4 Discussions


    Question 3 months ago

    which type of communication is it, i2c or spi ?


    1 year ago

    i made this and followed all of the steps.. but when it came to the code when i run it it has an error that says "no module named pad4pi". i all ready did type "pip install pad4pi" in the terminal and restarted my pi. but no luck can you please help.


    1 year ago on Step 5

    When I made This Projects, the wires started smoking and I had to take them out. the LCD did light up and after I put the second wire in the resistor(the blue-white thing), The LCD stopped and the wires started smoking and I had to break the circuit.

    1 reply

    Reply 1 year ago

    Please check vcc and ground pins are connected properly. Refer pinout of LCD and Raspberry Pi which used.