The following shows an example using the Adafruit Keypad Arduino library.

Install Keypad Library

You can install the Keypad library via the Library Manager.

Tools -> Manage Libraries...

Open it, search for 'keypad', and click Install on the one labeled Adafruit Keypad.

Example

For this example we will use the 3x4 Matrix Keypad (PID3845). Here is the wiring.

In the Arduino IDE open the example:

File -> Examples -> Adafruit Keypad -> keypad_test

Find these lines of code up near the top:

Download: file
// define your specific keypad here via PID
#define KEYPAD_PID3844

and change it to this to match the keypad being used:

Download: file
// define your specific keypad here via PID
#define KEYPAD_PID3845

Upload the sketch and then open the Serial Monitor

Tools -> Serial Monitor

Try pressing the buttons. You should see text like this:

Note that each press produces two messages. One for the down (pressed) and one for the up (released).

This guide was first published on Nov 06, 2018. It was last updated on Nov 06, 2018.
This page (Arduino) was last updated on Aug 14, 2020.