[vc_row][vc_column][vc_column_text]
In the Arduino application system, a keypad is one of the indispensable components for human-computer interface. When the IO resources are rare, we would prefer to use a matrix keypad. In this post, we will show how to use a 4 x4 keypad with Arduino.[/vc_column_text][vc_tour][vc_tab title=”Parts List” tab_id=”1394672966-1-20″][vc_column_text]
- 1 x [bigcommerce link=”/arduino-uno-compatible-usb-board-r3/” target=”_blank”]Arduino UNO[/bigcommerce]
- 1 x 4*4 keypad
- Several jumper wires
[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1394672966-2-99″][vc_column_text][/vc_column_text][/vc_tab][vc_tab title=”Test code” tab_id=”1394674462264-2-1″][vc_column_text]
#include <Keypad.h> const byte ROWS = 4; const byte COLS = 4; //define the symbols on the buttons of the keypads char Keys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {2,3,4,5}; byte colPins[COLS] = {6,7,8,9}; //initialize an instance of class NewKeypad Keypad customKeypad = Keypad(makeKeymap(Keys),rowPins,colPins,ROWS,COLS); void setup() { Serial.begin(9600); Serial.println("Please press the keyboard:"); } void loop() { char key = customKeypad.getKey(); if(key!=NO_KEY) { Serial.print("Key Value : "); Serial.println(key); } }
[/vc_column_text][/vc_tab][vc_tab title=”Run test” tab_id=”1394674463370-3-1″][vc_column_text](1) Hook up everything according to the wiring diagram:
(2) Download the Arduino library in the attachment and save it to the Arduino IDE libraries:
(3) Open the ArduinoIDE and paste the test code into the IDE, compile and download:
(4)Open the serial Monitor, set the baud rate to 9600, press any key and you will see the corresponding key value in the monitor;
[/vc_column_text][/vc_tab][vc_tab title=”Download” tab_id=”1394674717547-4-4″][vc_column_text]
Arduino Library:keypad
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.