Tutorial: Arduino and Numeric Keypads – Part Two
Welcome back fellow arduidans!
This is the second part of our numeric keypad tutorial – in which we use the larger keypads with four rows of four buttons. For example:
Again, the keypad looks like a refugee from the 1980s – however it serves a purpose. Notice that there are eight connections at the bottom instead of seven – the extra connection is for the extra column of buttons – A~D. You can order a similar keypad from here. For this tutorial you will need the data sheet for the pinouts, so download it from here (.pdf).
To use this keypad is very easy, if you haven’t already done so, download the numeric keypad Arduino library from here, copy the “Keypad” folder into your ../arduino-002x/libraries folder, then restart the Arduino IDE.
Now for our first example – just to check all is well. From a hardware perspective you will need:
- An Arduino Uno or 100% compatible board
- A 4×4 numeric keypad
- An LCD of some sort. We will be using an I2C-interface model. If you are unsure about LCD usage, please see this tutorial
- If you don’t have an LCD – that’s ok. Our demonstration sketch also sends the key presses to the serial monitor.
- Keypad row 1 (pin eight) to Arduino digital 5
- Keypad row 2 (pin 1) to Arduino digital 4
- Keypad row 3 (pin 2) to Arduino digital 3
- Keypad row 4 (pin 4) to Arduino digital 2
- Keypad column 1 (pin 3) to Arduino digital 9
- Keypad column 2 (pin 5) to Arduino digital 8
- Keypad column 3 (pin 6) to Arduino digital 7
- Keypad column 4 (pin 7) to Arduino digital 6
- the extra column in the array char keys[]
- the extra pin in the array colPins[]
- and the byte COLS = 4.
Now for another example – we will repeat the keypad switch from chapter 42 – but allow the letters into the PIN, and use the LCD instead of LEDs for the status. In the following example, the PIN is 12AD56. Please remember that the functions correctPIN() and incorrectPIN() are example functions for resulting PIN entry – you would replace these with your own requirements, such as turning something on or off. You can download the sketch from here.
Now let’s see it in action:
So now you have the ability to use twelve and sixteen-button keypads with your Arduino systems.
If you have any suggestions with regards to our next article, leave a comment below and we’ll look into it. Furthermore, don’t be shy in pointing out errors or places that could use improvement. Why not follow us on twitter and facebook to keep up with new articles, news and other items of interest. Article by John Boxall for Little Bird Electronics.
Otherwise, have fun, stay safe, be good to each other – and make something!

