Simple keypad tutorial

I am in need of some guidance with connecting a 12 button keypad to the Spark Core. To get started, I have been looking at a membrane matrix keypad from AdaFruit which has some example Arduino code ( - shown below:

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

This all looks well and good and from what I understand, I would change the rowPins and colPins values to be the actual Spark.IO pins D0, D1, D3, D4 and D5, D6, D7.

With regards to the code shown above, this would obviously need to be pasted somewhere and from the Arduino website, it would suggest that this goes above “void setup()” line (

keypad.h would get created as a new file via the Spark.IO Web interface (copying and pasting the code from the actual keypad.h file from the link in the last paragraph). Are any other files required? For example, the ZIP download from the Arduino website includes a utility folder, a file called Keypad.cpp and keywords.txt.

In the setup method, the following goes:


and in loop() goes:

char key = keypad.getKey();

if (key != NO_KEY){

This all seems too easy and before running off to buy keypads and more cores, could anyone confirm whether this will work?

I haven’t had a closer look, but the logic behind such a keypad is very simple, so I’m sure it’ll work.
I’m also convinced that you’d need the `keypad.cpp’ since there will be all the code required to do the scanning and interpreting of the key strokes.
But as said, it won’t be anything too hard to understand when you actually read the code.

keyword.txt is not required, it just helps the Arduino IDE to do code highlighting and some other editor stuff.

As for the utility folder, have a browse through the files therin, that will give you some clue if you’ll need it for your project or not.

A quick update for anyone who comes across this thread from Google - I finally got back to this little project but have abandoned it without being able to get it working. The code I originally posted above doesn’t work and unfortunately, as much as I want to get this working, I just don’t have the time. Sorry to anyone who finds this thread in Google hoping for a simple keypad tutorial - there isn’t one :disappointed:

Referencing the original arduino tutorial, the setup method has a few more pieces of set up:

void setup()
  digitalWrite(ledpin, HIGH);

and the loop says:

char key = kpd.getKey();
  if(key)  // Check for a valid key.
    switch (key)
      case '*':
        digitalWrite(ledpin, LOW);