Following is the list of contents:
- 1: Introduction to Arduino Keypad
- 2: Working of Arduino Keypad
- 3: Arduino 4X4 Keypad Pinout
- 4: Interfacing Arduino Nano with 4X4 Keypad
- Conclusion
1: Introduction to Arduino Keypad
An Arduino keypad is a type of input device that can be used to interface with an Arduino microcontroller. It typically consists of a matrix of buttons or keys that can be used to input numeric or alpha-numeric data.
The keypad is connected to the Arduino via a set of digital pins and can be used in a variety of applications such as password protection systems, data entry systems, or as a simple input method for interactive projects.
The Arduino keypad library allows for easy programming and implementation of the keypad, providing functions for reading the state of the keys and detecting button presses.
2: Working of Arduino Keypad
The working of an Arduino keypad involves a combination of hardware and software components. On the hardware side, the keypad typically consists of a matrix of buttons or keys that are connected to the Arduino via a set of digital pins.
The keypad is designed to send a unique signal to the Arduino for each button press, which the microcontroller can then interpret and process.
On the software side, the Arduino keypad library provides a set of functions that can be used to read the state of the keys and detect button presses. These functions allow the user to define the behavior of the keypad.
The Arduino code reads the digital input pins connected to the keypad and identifies the button press by checking the voltage level on those pins. It then sends the corresponding ASCII code, or the number pressed to the microcontroller, where the code written by the user processes it further.
3: Arduino 4X4 Keypad Pinout
The pinout for an Arduino 4×4 keypad typically consists of 8 pins, 4 for the rows and 4 for the columns. Here is an example of the pinout for a 4×4 keypad:
It is worth noting that the pinout may vary depending on the specific keypad you are using and the wiring scheme you choose.
4: Interfacing Arduino Nano with 4X4 Keypad
To read input from Keypad first we have to install the Keypad Library in Arduino IDE. After that, using the digital pins and library code, we can read data from the keypad.
4.1: Installing the Required Libraries
Open library manager in IDE and search keypad library by Mark Stanley. Install the library in IDE:
After installing the keypad library, we can now interface it with the Arduino Nano board.
4.2: Schematic
Connect Arduino Nano with keypad as displayed in image:
Following is the pin configuration table of Arduino Nano with keypad:
Keypad Pin | Arduino Nano |
---|---|
Row 1 | D2 |
Row 2 | D3 |
Row 3 | D4 |
Row 4 | D5 |
Column 1 | D9 |
Column 2 | D10 |
Column 3 | D11 |
Column 4 | D12 |
4.3: Hardware
In hardware Arduino Nano can be seen on a breadboard connected with keypad using jumper wires:
4.4: Code
Open IDE and upload Keypad code to Arduino Nano board:
const byte ROWS = 4; /*Define Keypad Rows*/
const byte COLS = 4; /*Define Keypad Columns*/
char Keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
};
byte rowPins[ROWS] = {9,10,11,12}; /*Initialized Arduino Pins for Rows*/
byte colPins[COLS] = {2,3,4,5}; /*Initialized Arduino Pins for Columns*/
Keypad myKeypad = Keypad(makeKeymap(Keys), rowPins, colPins, ROWS, COLS); /*Function for Keypad*/
void setup(){
Serial.begin(9600); /*Baud Rate for Serial Communication*/
}
void loop(){
char Key = myKeypad.getKey(); /*Take input from Keypad*/
if (Key){ /*If Key is pressed display the output*/
Serial.println(Key);
}
}
Code started by including the keypad library. At the start of the code the dimension of the keypad is defined. As we are using the 4X4 keypad so total Rows and Columns are defined.
Next using the keypad library function code will read the input if any button is pressed. Serial baud rate is initialized to display the pressed button on the IDE serial monitor:
4.5: Output
Once the code is uploaded press a key on the keypad you will see the same output on the Serial monitor of IDE:
We have completed the interfacing of Arduino Nano with Keypad.
Conclusion
Arduino Nano is a compact microcontroller board that has a number of GPIO pins to interface different sensors. Using the digital pins, a Keypad can be interfaced. We can read different numbers through Arduino digital pins and display them on the serial monitor of the IDE.