Security Panel System with using Keypad and LCD


In this tutorial we will learn how to make an Arduino Security Panel System with using Keypad and LCD Display.

We will be able to open the door by entering the correct password.

---

Hardware Required :

- Arduino Board - https://goo.gl/UyGYeF
- Keypad 4x4 - https://goo.gl/jtGlx5
- LCD 16x02 - https://goo.gl/8S27hc
- LED 
- Breadboard - https://goo.gl/yCa8hX
- Resistor 220ohm
- Potentiometer 10k - https://goo.gl/c90Uix

Recomended Site - https://goo.gl/3j489l

---

LCD 16x02 Connection:

The Arduino's +5V and GND will be connected to the pin of the breadboard
The LCD has 16 pins and the first one from left to right is the Ground (GND) pin
The second pin is the VCC which we connect the +5V pin on the breadboard.
Next is the Vo pin on which we can attach a potentiometer for the contrast of the display
The RS pin will be connected to the A0 pin of the Arduino.
The RW pin will be connected to the GND pin of the breadboard.
The E pin will be connected to the A1 pin of the Arduino.
The D4 pin will be connected to the A2 pin of the Arduino.
The D5 pin will be connected to the A3 pin of the Arduino.
The D6 pin will be connected to the A4 pin of the Arduino.
The D7 pin will be connected to the A5 pin of the Arduino.
The A (anode) pin will be connected to the +5V pin of the breadboard.
The K (cathode) pin will be connected to the GND pin of the breadboard.
The potentiometer's other pins will be connected to the +5V and GND pin of the breadboard.

---

Keypad 4x4 and LED Connections :

The keypad has 8 pins, 4 of them are for the rows and other 4 pin for the columns.
The keypad I'm using is 4x4. It has an additional connection input. The keypad used in the circuit diagram is 3x4.
The Keypad's pins will be connected respectively to the Digital 1-2-3-4-5-6-7-8 pin of the Arduino.
The Red and Green LED will be attached on the breadboard
The 220 ohm resistor will be connected to the anode leg of the LED
The LED cathode leg will be connected to the GND of the breadboard.
The LED resistor leg will be connected to the Digital 10-11 of the Arduino.

---

Source Code

We need to include the standard LiquidCrystal library for the LCD Display
The Keypad library needs to be additionally installed.
Get the Keypad Library - https://goo.gl/PUiBBA
Put the Keypad folder in "arduino\libraries\"
Then we need to define the LED pins
Define some variables needed for the program
Define the keys of the Keypad
/* Arduino Security System with the Keypad and LCD 
 * Creator Mert Kılıç - Mert Arduino Tutorial and Project
 * Please subscribe for support
 * Thanks
 */

#include <LiquidCrystal.h> //include LCD library (standard library)
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)

#define redLED 10 //define the LED pins
#define greenLED 11

char* password ="1234"; //create a password
int pozisyon = 0; //keypad position

const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;

char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad

  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins [rows] = {1, 2, 3, 4}; //pins of the keypad
byte colPins [cols] = {5, 6, 7, 8};

Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);

LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // pins of the LCD. (RS, E, D4, D5, D6, D7)

void setup(){

  lcd.begin(16, 2);
  pinMode(redLED, OUTPUT);  //set the LED as an output
  pinMode(greenLED, OUTPUT);
  setLocked (true); //state of the password
}

void loop(){

  char whichKey = myKeypad.getKey(); //define which key is pressed with getKey

  lcd.setCursor(0, 0);
  lcd.print("    Welcome");
  lcd.setCursor(0, 1);
  lcd.print(" Enter Password");

  if(whichKey == '*' || whichKey == '#' || whichKey == 'A' ||       //define invalid keys
  whichKey == 'B' || whichKey == 'C' || whichKey == 'D'){

    pozisyon=0;
    setLocked (true);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  Invalid Key!");
    delay(1000);
    lcd.clear();
  }
  if(whichKey == password [pozisyon]){

    pozisyon ++;
  }
  if(pozisyon == 4){
    setLocked (false);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("*** Verified ***");
    delay(3000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  Mert Arduino");
    lcd.setCursor(0, 1);
    lcd.print("Tutorial Project");
    delay(7000);
    lcd.clear();
  }
  delay(100);
}

void setLocked(int locked){
  if(locked){
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
    }
    else{
      digitalWrite(redLED, LOW);
      digitalWrite(greenLED, HIGH);
    }
  }