Keypad Access 4x4 With Arduino
by sfeelectronics in Circuits > Arduino
3878 Views, 26 Favorites, 0 Comments
Keypad Access 4x4 With Arduino
The 4x4 keypad is a composite of 16 keys arranged like a matrix. The method used for accessing 4x4 keypad with matrix scanning method. The 4x4 keypad requires 8 pins to access it, ie 4 pins for the columns and 4 pins for the line. How the scanning method works is that the column pin takes the LOW logic interchangeably, then the line pin performs the readings in turn as well.
Materials You Need
You will need:
- Arduino
- Keypad 4x4
- Jumper Wires
Pin Out
- PIN A3 --> pin to 0 row
- PIN A2 --> pin to 1 row
- PIN A1 --> pin to 2 row
- PIN A0 --> pin to 3 row
- PIN 4 --> pin to 0 colomn
- PIN 5 --> pin to 1 colomn
- PIN 6 --> pin to 2 colomn
- PIN 7 --> pin to 3 colomn
Schematic
Connect each component as the picture above.
Code
#include <Keypad.h> //import library keypad
const byte ROWS = 4; //number of colomn const byte COLS = 4; //number of row char hexaKeys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {A3, A2, A1, A0}; //pin used for row byte colPins[COLS] = {4, 5, 6, 7}; //pin used for colomn
//initialization variable Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){ Serial.begin(9600); } void loop(){ char customKey = customKeypad.getKey(); if (customKey){ Serial.println(customKey); } }
Output
Check the output!