Arduino 4x4 Matrix Array 16 Key Membrane Switch Keypad

By Kumantech | 16 June 2017 | 0 Comments
The 8P dupont head, spacing 2.54 mm, can be inserted in the pin to connect the circuit. The white sticker on the back of the keyboard can be firmly attached to the surface of the machine.
It is suitable for external expansion of single chip/


Detailed Pictures:
  

Test Code one:

#include     
#define KEY_ROWS 4
#define KEY_COLS 4
 
char keymap[KEY_ROWS][KEY_COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
 
byte colPins[KEY_COLS] = {9, 8, 7, 6};           
byte rowPins[KEY_ROWS] = {13, 12, 11, 10};
 
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, KEY_ROWS, KEY_COLS);
void setup()
{
  Serial.begin(9600);
}
  
void loop()
{
  char key = myKeypad.getKey();
  if (key)
{  
    Serial.println(key);  
  }
}




Test Code two:


#include
#include
#include
#define LED  13
#define KEY_ROWS 4   // The number of columns in the key module
#define KEY_COLS 4   // The number of rows of the key module
#define LCD_ROWS 2   // The number of columns of the LCD display
#define LCD_COLS 16  // The number of lines of an LCD display
 
// Key words (two-dimensional arrays) arranged in rows and columns
 
char keymap[KEY_ROWS][KEY_COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
 
byte colPins[KEY_COLS] = {8, 7, 6, 5};         // Key module, row 1-4
byte rowPins[KEY_ROWS] = {12, 11, 10, 9}; // Key module, column 1 ~ 4
 
// Initialize the Keypad
// Keypad:,Set the feet, module lines,module number, module row number
 
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, KEY_ROWS, KEY_COLS);
String passcode = "4321";
String inputCode = "";
bool acceptKey = true;
 
int N=1; 
 
LiquidCrystal_I2C lcd(0x3F, 16, 2);
void clearRow(byte n)
{
  byte last = LCD_COLS - n;
  lcd.setCursor(n, 1); // Move to line 2, "PIN:"
  for (byte i = 0; i < last; i++)
  {
   lcd.print(" ");
  }
  lcd.setCursor(n, 1);
}
 
void resetLocker()
{
  lcd.clear();
  lcd.print("knock...");
  lcd.setCursor(0, 1);  // Switch to line 2
  lcd.print("PIN:");
  lcd.cursor();
  inputCode = "";
}
 
void checkPinCode()
{
    if(N<4)
  {
    if (inputCode == passcode)
    {
    lcd.setCursor(0, 0);
    lcd.print("open the door");
    digitalWrite(LED,HIGH);
    acceptKey = false;
    inputCode = "";
    }
    else
    {
    lcd.setCursor(0, 0);
    lcd.print("ERROR...");
    lcd.setCursor(8, 0);
    lcd.print(N);
    N=N++;
    inputCode = "";
    }
  }
  else
  {
    acceptKey = false; 
    lcd.setCursor(0,0);
    lcd.print("Password locked");
   }
    delay(30);
}
 
void setup()
{
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
  digitalWrite(LED,LOW);
  lcd.init();      
  lcd.backlight(); 
  resetLocker();
}
 
void loop()
{
  char key = myKeypad.getKey();
 
  // Waiting for user input
 
  if ( acceptKey && key != NO_KEY)
  {
      if (key == '*')
      {
        clearRow(4); 
        inputCode = "";
      }
      else if (key == '#')
      { 
         checkPinCode();
         clearRow(4);
         inputCode = "";
       }
      else
      {
         inputCode += key;  // Store the user's keypad
         lcd.print('*');
       }
   }
 }



Code: https://mega.nz/#!eJ1ilQrI!2k-3U2ksC9OzctjG3c4Podg4LYaXgCYhdY3D9pvcLWA
Library: https://mega.nz/#F!fAFXmLjZ!Nu4DKoatz7eKO3ZgjaLIPQ

              https://mega.nz/#F!2dch1LRQ!kf52HRQ7gTNFq3-yPvLMHQ


Leave a Reply
Your email address will not be published.Required fields are marked. *
Name *
Email *
Content
Popular blog
Categories