10% Off For Your First Order, Code:Elephant10

Arduino Project: 4*4 Button Module

Posted by Fiona Su on


In the application system of microcontroller, keyboard is essential in man-machine dialogue. When you are short of a button, you can connect one to the I/O port of the controller; but when you need a lot of buttons with limited I/O port resources, this 4*4 Matrix Keypad is no doubt your best choice.
4*4 matrix keypad is the most applied keypad form. We need to master its keypad identification technology as entry to microcontroller world. Here, we will use an examples to illustrate the identification method of 4*4 matrix keypad. The key layout is in matrix form, so with only eight I/O ports, we can identify 16 buttons, saving lots of I/O port resources.

Pin layout for 4*4 Large Button module:

Hardware required:

  • Arduino board *1
  • USB cable *1
  • 4*4 Button Module*1
  • Active buzzer*1
  • Red M5 LED*1
  • 220Ω resistor*1
  • Breadboard *1
  • Breadboard jumper wires
  • Male to Female Dupont Line

Connection for REV4:

Connection for 2560 R3:

Sample program:

#include <Keypad.h>
int led = 10;
int buzzer = 11;
const byte ROWS = 4; // define row 4
const byte COLS = 4; // define column 4
char keys[ROWS][COLS] = {
// connect row ports of the button to corresponding IO ports on the board
byte rowPins[ROWS] = {9,8,7,6};	
// connect column ports of the button to corresponding IO ports on the board
byte colPins[COLS] = {5,4,3,2};
// call class library performance function of Keypad 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(led, OUTPUT);
pinMode(buzzer, OUTPUT);

void loop(){
digitalWrite(led, LOW); 
digitalWrite(buzzer, LOW); 
char key = keypad.getKey();
if (key != NO_KEY){
if (key =='1')
digitalWrite(led, HIGH); 

if (key =='2')
digitalWrite(buzzer, HIGH); 

Upload the program to the board, open serial monitor; press certain button on the module, it will display corresponding value as below picture shows:

When serial monitor prints 1, LED lights up; when it printing 2, the buzzer rings 1S.



Leave a comment

Please note, comments must be approved before they are published