How to connect and use 4×4 Keypad using Raspberry Pi?

Non classé Raspberry Pi tutorial

In this post, we will show you, step by step, how to connect and use a 4 × 4 keypad with the Raspberry Pi mini-computer.

Many websites talk about this keypad, but to our knowledge, no one of these websites is covering in details the entire setup process of this simple but useful input device. In this post, we will show you all the required wiring , the libraries and the code necessary to use this type of keyboards a Raspberry Pi based project.

In this tutorial, we assume that you are familiar with the following:

  • Access to your Raspberry Pi via ssh
  • Ability to use the terminal to execute simple commands, such as creating files, etc.
  • The following components are also needed for this tutorial:
    • Raspberry Pi model B + or higher (here I use a RPi B+)
    • A classic 4 × 4 keyboard:
    • 8 male / female wires to connect the keybpad to the GPIO of your Pi

Wiring the 4×4 keypad to the Raspberry Pi

The following picture clearly depict the required to wire the 4×4 keypad to the Raspberry Pi:


Installation of required libraries

In order to be able to access the GPIO pins of your Raspberry Pi from python scripts, you have to install the  “RPi.GPIO” library. To do so, we have to execute the following command:

In addition, to simplify the access to the keypad, we have to install the “pad4pi” library. In order, to install this library, we have first install “pip” through the follwing command:

Once “pip” is installed, execute the following command to install the “pad4pi” library:


Cloning of the keypad controller to the Raspberry Pi

Now, we just need to move to the folder in which we would like to install the controller. For instance, if you would like to install this folder inside the home folder of the current user, just type the following command in a terminal:

Then, to clone the controller to your Raspberry Pi, just execute the following command:

This command will clone the entire project inside a new folder “Simple_4x4_KeypadControllerForRaspberryPi”

You can rename this folder to “keypadController” using the following command:


How to use this controller?

In order to use this controller, you have to navigate to the keypad controller folder containing “” file and add the execution permission to this file using the following command:

Then, execute this file using the following command (in the same folder):

Note: After finishing the modification of the behavior of various keys of the Keypad, you can add the following line to the crontab using the (crontab -e) command to launch the controller at the starting of the Raspberry Pi:

What is the default behavior of this controller?

By pressing the keys on the keypad, the script prints the names of the various keys pressed in the terminal.

If you found this tutorial useful, share it to your friends 🙂