37

A keypad allows you to interact with a microcontroller. You can salvage these keypads from old telephones or you can purchase them from most electronics store for less than \$2.

They come in wide variety of shapes and sizes. The most commons sizes are 3×4 and 4×4 and you can get keypads with with words, letters and numbers written on the keys.

Description
These keypads very popular among the Arduino tinkerers. They are very cheap and you can use them with any microcontroller (MCU).

### 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 2: How It Works?

A membrane keypad is a matrix consisting of rows and columns. Each key is assigned to a certain row and column.

On a 12 button keypad you have 4 rows and 3 columns. The first key would make a link between Row 1 and Column 1 (R1C1). 2 would be R1C2, 3 R1C3, * R4C1, 9 R3C3 and so on.

## Step 3: Arduino With Membrane Keypad

You need the following components to make this circuit:

Schematics
Follow the next schematics. If your keypad is different from the one below, try to search for the datasheet online.

Here’s the library you need for this project:

2.Install the Keypad library in your Arduino IDE by moving the unzipped folder to: Arduino\Libraries

If your keypad doesn’t work with code below you might have to change the connections from the previous schematics.

Search the web or go to the store that sold you the keypad to find the datasheet for your keypad.

Note: If your keypad has more keys you can change lines 3 and 4 to add the right number of rows and columns. Then in line 5 you can change the array to match your keypad keys.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const byte ROWS = 4; // number of rows

const byte COLS = 3; // number of columns

char keys[ROWS][COLS] = {

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

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

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

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

};

byte rowPins[ROWS] = {8, 7, 6, 5}; // row pinouts of the keypad R1 = D8, R2 = D7, R3 = D6, R4 = D5

byte colPins[COLS] = {4, 3, 2}; // column pinouts of the keypad C1 = D4, C2 = D3, C3 = D2

void setup() {

Serial.begin(9600);

}

void loop() {

if (key != NO_KEY)

Serial.println(key);

}

## Step 6: Demonstration

In this project when you press a key, it’s displayed the value in your serial montior. Here’s what you should see in your Arduino IDE serial monitor when you start pressing the keypad keys.

## Step 7: Conclusion

Now you can create an interface for your Arduino using a keypad. You could also add an LCD to this project.

I hope you found this guide useful. Share this post with a friend that also likes electronics!

## Recommendations

• ### Internet of Things Class

22,781 Enrolled