DIY Arduino based Digital Password Lock, What is 4x4 matrix Keypad?, How to Interface 16x2 LCD with Arduino Uno ?, Circuit Diagram of Arduino based Digital Password Lock, code of Arduino based Digital Password Lock
Digital Lock, DIY Arduino based Digital Password Lock, What is 4x4 matrix Keypad?, How to Interface 16x2 LCD with Arduino Uno ?, Circuit Diagram of Arduino based Digital Password Lock, code of Arduino based Digital Password Lock

Let's get started with this innovative Arduino tutorial where you will learn how to make a keyless, Passcode lock system using a 4X4 keypad to enter the passcode and a Solenoid Electromagnetic cabinet lock and a 16X2 LCD for display. It's better to make one rather than buying one. This system can be used in Doors, piggy bank, secret box, etc.

Components Required:

What is 4x4 matrix Keypad?

It is basically a two dimensional array of switches. This is 4x4 keypad matrix have two four pin connectors 4 for rows and 4 for columns. A matrix of rows and columns organizes the keys. A row and a column make contact when a key is pressed; otherwise, there is no connection between rows and columns.

What is 4x4 matrix Keypad?
 
What is 4x4 matrix Keypad?

 

The microcontroller grounds all rows by supplying 0 to the output latch to detect a pressed key. If the data read from columns equals 1111, no key has been pressed.

Process of scanning the Keys

Starting with the top row, the microcontroller can ground it by sending a low signal to only row R1.

  • Now read the columns; if all of the data is 1s, no key is pressed in that row, and the process continues for the next row.
  • R2 is the next row to be ground. Read the columns, look for any zeros, and repeat the procedure until the row is found.
  • E.g. If the data received is 1011 then row 2 is the row where the column is not equal to 1111.
  • After determining the row in which the key was pressed, we can quickly locate the key using the row and column values.

 

How to Interface 16x2 LCD with Arduino Uno?

LCD modules are a critical component in many Arduino-based embedded systems. As a result, understanding how to attach an LCD module to an Arduino is crucial when designing embedded systems. Here you will learn how to connect an Arduino to a 16x2 LCD display. 

The JHD162A is a 16x2 LCD module based on Hitachi's HD44780 driver. The JHD162A has 16 pins and can be used in 4-bit or 8-bit mode (using only four data lines) or (using all 8 data lines) respectively. In this case, the LCD module is set to 4-bit mode.

Before going into the details of the project, let’s have a look at the JHD162A LCD module. The schematic of a JHD162A LCD pin diagram is given below.

How to Interface 16x2 LCD with Arduino Uno ?, 16x2 LCD

Pinout:

  • Pin1(Vss): Ground pin of the LCD module.
  • Pin2(Vcc): Power to LCD module (+5V supply is given to this pin)
  • Pin3(VEE): Contrast adjustment pin. This is done by connecting the ends of a 10K potentiometer to +5V and ground and then connecting the slider pin to the VEE pin. The voltage at the VEE pin defines the contrast. The normal setting is between 0.4 and 0.9V.
  • Pin4(RS): Register select pin. The JHD162A has two registers namely command register and data register. Logic HIGH at RS pin selects data register and logic LOW at RS pin selects command register. If we make the RS pin HIGH and feed an input to the data lines (DB0 to DB7), this input will be treated as data to display on the LCD screen. If we make the RS pin LOW and feed an input to the data lines, then this will be treated as a command ( a command to be written to LCD controller – like positioning cursor or clear screen or scroll).
  • Pin5(R/W): Read/Write modes. This pin is used for selecting between read and write modes. Logic HIGH at this pin activates read mode and logic LOW at this pin activates write mode.
  • Pin6(E): This pin is meant for enabling the LCD module. A HIGH to LOW signal at this pin will enable the module.
  • Pin7(DB0) to Pin14(DB7):  These are data pins. The commands and data are fed to the LCD module though these pins.
  • Pin15(Backlight +): Anode of the back light LED. When operated on 5V, a 560 ohm resistor should be connected in series to this pin. In Arduino based projects the back light LED can be powered from the 3.3V source on the arduino board.
  • Pin16(Backlight -): Cathode of the backlight LED.


How does a Solenoid Lock Work?

Solenoid Electromagnet cabinet lock

A solenoid is a small electromagnet that moves or pulls a plunger to perform a task. In this situation, it either keeps the strike opening closed or allows it to swing open, allowing the door's lock latch to open without having to retrace it. Although the mechanical door lock latch is still engaged when a door strike is released, it is possible to force the door open from the outside (locked). The strike opening simply swings forward, and the latch in the frame's latch pocket is no longer held in place.

Circuit Diagram

Circuit Diagram of Arduino based Digital Password Lock

Arduino Code:

#include <Keypad.h>
#include<LiquidCrystal.h>
#include<EEPROM.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
char password[4];
char pass[4], pass1[4];
int i = 0;
int buzzer = A0;
int Relay = A5;
int staterelay = LOW;
char customKey = 0;

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};


byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3, 2, 1, 0}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void(* resetFunc) (void) = 0;
void setup()
{
pinMode(Relay, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(Relay, LOW);
digitalWrite(buzzer , LOW);
lcd.begin(16, 2);
lcd.print("Hatchnhack");
lcd.setCursor(0, 1);
delay(1000);
lcd.print("Smart Lock");
delay(1000);
digitalWrite(buzzer , HIGH);
delay(100);
digitalWrite(buzzer , LOW);
delay(50);
digitalWrite(buzzer , HIGH);
delay(200);
digitalWrite(buzzer , LOW);
delay(50);
digitalWrite(buzzer , HIGH);
delay(200);
digitalWrite(buzzer , LOW);
delay(100);
digitalWrite(buzzer , LOW);
lcd.clear();
lcd.print("KEYPAD-LOCKED");
lcd.clear();
lcd.print(" Passcode Please:");
lcd.setCursor(0, 1);
for (int j = 0; j < 4; j++)
pass[j] = EEPROM.read(j);


}
void loop()
{
customKey = customKeypad.getKey();
if (customKey == '#')
change();

if (customKey == '*')
resetFunc();


if (customKey)

{
password[i++] = customKey;
lcd.print("*");

}

if (i == 4)
{ i = 0;
delay(200);
for (int j = 0; j < 4; j++)
pass[j] = EEPROM.read(j);
if (!(strncmp(password, pass, 4)))
{
i = 0;
digitalWrite(Relay, HIGH);
lcd.clear();
lcd.print("Passkey Accepted");
digitalWrite(buzzer , HIGH);
delay(100);
digitalWrite(buzzer , LOW);
delay(50);
digitalWrite(buzzer , HIGH);
delay(90);
digitalWrite(buzzer , LOW);
delay(30);
digitalWrite(buzzer , HIGH);
delay(200);
digitalWrite(buzzer , LOW);
delay(100);
digitalWrite(buzzer , HIGH);
delay(200);
digitalWrite(buzzer , LOW);
delay(50);
digitalWrite(buzzer , HIGH);
delay(500);digitalWrite(buzzer , LOW);
delay(100);
lcd.setCursor(0, 1);
lcd.print("#-Change");
lcd.print("*-Lock");
}

else
{
digitalWrite(Relay, LOW);

lcd.clear();
lcd.print("Access Denied...");
digitalWrite(buzzer , HIGH);
delay(1000);

lcd.clear();
lcd.print("restarting...");
delay(5000);
i = 0;
resetFunc();


}

}
}

void change()
{
int j = 0;
lcd.clear();
lcd.print("Current Passcode:");
lcd.setCursor(0, 1);
while (j < 4)
{
char key = customKeypad.getKey();
if (key)
{
pass1[j++] = key;
lcd.print(key);

}
key = 0;
}
delay(500);

if ((strncmp(pass1, pass, 4)))
{
lcd.clear();
lcd.print("Wrong Passkey...");

lcd.setCursor(1, 1);
lcd.print("DENIED");
digitalWrite(buzzer , HIGH);
delay(2000);
customKey = 0;
resetFunc();
}
else
{
j = 0;

lcd.clear();
lcd.print("New Passcode:");
lcd.setCursor(0, 1);
while (j < 4)
{
char key = customKeypad.getKey();
if (key)

{
pass[j] = key;
lcd.print(key);
EEPROM.write(j, key);
j++;

}
}
lcd.print(" Done...");
delay(1000);
digitalWrite(Relay, LOW);
resetFunc();
}


}
16x2 lcd4x4 matrix keypadArduino projectBuzzerDiy projects

Leave a comment

All comments are moderated before being published