This tool consists of Arduino UNO as the main system & controller of the system. The keypad is used to input the password code data to determine whether the password is correct so that the lock is open or the password is incorrect so that the key is closed. In other that, it also used to change old password with new password. LCD is used to display password entry or password change menu. Relays as actuators that will directly control the solenoid. Solenoid is used to open or close the key.
Hardware Requirement
- Relay Module 5V with Single Channel
- Arduino UNO
- Solenoid Lock Door Module
- 4x4 Keypad Module
- 16 x 2 LCD Module
- A Buzzer
- Power supply +5 Volt
- Jumper
Block Diagram
Schematic
Arduino - LCD Wiring
Arduino - 4 x 4 Keypad Module Wiring
Arduino - Relay - Buzzer Wiring
Source Code/Sketch
How it Works
1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino
4. POWER SUPPLY DO NOT EXCHANGE BETWEEN 12V AND 9V !!!
7. Next will appear command to lock (selenoid active)
8. Press the hastage (#) button to lock it.
9. On locked door condition. To open it required a password that is a combination of 6 digit numbers
are entered through the keypad
10. For the initial password value, the password code is "111111" (number 1 six times). Press "1"
number 6 times
11. If the password is correct then it will appear
12. The buzzer will also rang : "beep - beep", then the active relay and selenoid will open.
13. If the password you've entered is incorrect
The buzzer will rang: "beep .........(With long periode) " then you are prompted to enter the
password again
14. The chance of entering a password is 3 times. If it is 3 times the password is inccorrect, then it must wait 5 minutes to be able to enter password again
15. To change the password, make sure the dvice is locked
16. To change the password, press the star key (*)
17. Next, enter the old password. If the device has not been changed its password, then The initial
password is: "111111" (number 1 six times)
18. If the password is correct then it will show:
19. Approximately 2 seconds later will appear request a new password
20. Enter the desired new password.
21. Then the option appears to save the password or cancel. Press "D" if will save (change password)
or "C" if cancel.
22. Press "D" to save the new password.
23. Next will return to normal condition (closed).
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
unsigned char key,menu,urut;
unsigned char pw1,pw2,pw3,pw4,pw5,pw6,i;
unsigned char pw_kpd1,pw_kpd2,pw_kpd3,pw_kpd4,pw_kpd5,pw_kpd6;
unsigned char cek,cnt;
unsigned char fkpd;
char pw[7],pw_kpd[7];
char s,t;
//----------------------------INISIALISASI KONEKSI LCD 2X16
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
//----------------------------INISIALISASI KONEKSI KEYPAD 4X4
const byte ROWS=4;
const byte COLS=4;
char keys[ROWS][COLS]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS]={A0,A1,A2,A3};
byte colPins[COLS]={10,11,12,13};
Keypad keypad = Keypad(makeKeymap(keys),rowPins, colPins, ROWS, COLS);
void setup()
{
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(8,0);
digitalWrite(9,0);
lcd.begin(16, 2);
lcd.print(" Kunci Elektrik");
lcd.setCursor(0,1);
lcd.print("Dengan Password");
delay(2000);
//---------------------cek alamat 0
cek=EEPROM.read(0);
if(cek==0xFF){
cek=1;
EEPROM.write(0,'1');
pw1='1'; EEPROM.write(1,'1');
pw2='1'; EEPROM.write(2,'1');
pw3='1'; EEPROM.write(3,'1');
pw4='1'; EEPROM.write(4,'1');
pw5='1'; EEPROM.write(5,'1');
pw6='1'; EEPROM.write(6,'1');
}
else{
pw1=EEPROM.read(1);
pw2=EEPROM.read(2);
pw3=EEPROM.read(3);
pw4=EEPROM.read(4);
pw5=EEPROM.read(5);
pw6=EEPROM.read(6);
}
fkpd=0;
delay(200);
}
void loop()
{
//----------------------------- display time
digitalWrite(8,1);
lcd.clear();
lcd.print("Silakan kunci...");
lcd.setCursor(0,1);
lcd.print("Tekan #");
fkpd=2;
goKeypad();
lcd.clear();
lcd.print("Pintu Terkunci");
delay(3000);
pass:
lcd.clear();
lcd.print("Masukan Password");
lcd.setCursor(0,1);
fkpd=1;
menu=0;
goKeypad();
if(menu==4) goto pass;
}
//---------------------------- keypad
void goKeypad(){
do{
key=keypad.getKey();
if(key != NO_KEY){
if(key=='*' && fkpd==1){
lcd.clear();
lcd.print("Ganti Password");
lcd.setCursor(0,1);
lcd.print("PW lama=");
menu=1;
delay(300);
}
else if(key=='#' && fkpd==2){
fkpd=0;
digitalWrite(8,0);
delay(250);
}
else if ((key=='C')&&(fkpd == 1)){ //C
if(menu==3){
lcd.clear();
lcd.print("PW baru:");
menu=2;
for(t=0;t<6;t++)pw_kpd[t]=' ';
cnt=0;
}
else if(menu==2){
menu=4;
fkpd=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
cnt=0;
}
else if((menu==1)||(menu==0)){
menu=4;
fkpd=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
cnt=0;
}
delay(250);
}
else if (key=='D'&& menu==3){
lcd.clear();
lcd.print("Simpan PW Baru..");
EEPROM.write(1,pw_kpd[0]);
EEPROM.write(2,pw_kpd[1]);
EEPROM.write(3,pw_kpd[2]);
EEPROM.write(4,pw_kpd[3]);
EEPROM.write(5,pw_kpd[4]);
EEPROM.write(6,pw_kpd[5]);
EEPROM.write(0,1);
pw1 = pw_kpd[0];
pw2 = pw_kpd[1];
pw3 = pw_kpd[2];
pw4 = pw_kpd[3];
pw5 = pw_kpd[4];
pw6 = pw_kpd[5];
fkpd = 0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
delay(3000);
menu = 4;
}
else if(menu<2 && fkpd==1 && key!='A' && key!='B'
&& key!='C' && key!='D' && key!='*' && key!='#'){
cek_password();
}
else if(menu==2 && fkpd==1&& key!='A' && key!='B'
&& key!='C' && key!='D' && key!='*' && key!='#'){
entri_password();
}
}
}
while(fkpd);
}
void cek_password(){
pw_kpd[cnt]=key;
cnt++;
lcd.print('*');
// lcd.print(char(key));
if((cnt==6)&&(menu==0)){
delay(500);
if((pw1==pw_kpd[0])&&(pw2==pw_kpd[1])&&(pw3==pw_kpd[2])&&(pw4==pw_kpd[3])&&(pw5==pw_kpd[4])&&(pw6==pw_kpd[5])){
lcd.clear();
lcd.print("Password Benar");
lcd.setCursor(0,1);
lcd.print("Silakan Masuk");
digitalWrite(8,1);
digitalWrite(9,1);
delay(200);
digitalWrite(9,0);
delay(200);
digitalWrite(9,1);
delay(200);
digitalWrite(9,0);
cnt=0;
fkpd=0;
s=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
delay(3000);
}
else {
lcd.clear();
lcd.print("Password Salah");
s++;
if(s < 3){
digitalWrite(9,1);
delay(2000);
digitalWrite(9,0);
lcd.clear();
lcd.print("Masukan Password");
lcd.setCursor(0,1);
cnt=0;
for(t=0;t<6;t++)
pw_kpd[t]=' ';
}
else if (s==3){
lcd.clear();
lcd.print("Anda 3x Salah");
lcd.setCursor(0,1);
lcd.print("Tunggu 5 Menit");
for(i=0;i<75;i++){
digitalWrite(9,1);
delay(2000);
digitalWrite(9,0);
delay(2000);
}
lcd.clear();
lcd.print("Masukan Password");
lcd.setCursor(0,1);
cnt=0;
s=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
}
}
}
else if((cnt==6)&&(menu==1)){
if((pw1==pw_kpd[0])&&(pw2==pw_kpd[1])&&(pw3==pw_kpd[2])&&(pw4==pw_kpd[3])&&(pw5==pw_kpd[4])&&(pw6==pw_kpd[5])){
lcd.clear();
lcd.print("Password Benar");
lcd.setCursor(0,1);
delay(2000);
lcd.clear();
lcd.print("PW baru:");
cnt=0;
menu=2;
s=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
}
else {
s++;
if(s < 3){
lcd.clear();
lcd.print("Password Salah");
cnt=0;
delay(2000);
lcd.clear();
lcd.print("Ganti Password");
lcd.setCursor(0,1);
lcd.print("PW lama=");
for(t=0;t<6;t++)pw_kpd[t]=' ';
}
else if (s==3){
lcd.clear();
lcd.print("Anda 3x Salah");
lcd.setCursor(0,1);
lcd.print("Tunggu 5 Menit");
for(i=0;i<75;i++){
digitalWrite(9,1);
delay(2000);
digitalWrite(9,0);
delay(2000);
}
lcd.clear();
lcd.print("Ganti Password");
lcd.setCursor(0,1);
lcd.print("PW lama=");
cnt=0;
s=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
}
}
}
}
void entri_password(){
lcd.print(char(key));
pw_kpd[cnt]=key;
cnt++;
if(cnt==6){
lcd.setCursor(0,1);
lcd.print("D=save,C=cancel");
menu=3;
cnt=0;
}
}
#include <LiquidCrystal.h>
#include <EEPROM.h>
unsigned char key,menu,urut;
unsigned char pw1,pw2,pw3,pw4,pw5,pw6,i;
unsigned char pw_kpd1,pw_kpd2,pw_kpd3,pw_kpd4,pw_kpd5,pw_kpd6;
unsigned char cek,cnt;
unsigned char fkpd;
char pw[7],pw_kpd[7];
char s,t;
//----------------------------INISIALISASI KONEKSI LCD 2X16
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
//----------------------------INISIALISASI KONEKSI KEYPAD 4X4
const byte ROWS=4;
const byte COLS=4;
char keys[ROWS][COLS]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS]={A0,A1,A2,A3};
byte colPins[COLS]={10,11,12,13};
Keypad keypad = Keypad(makeKeymap(keys),rowPins, colPins, ROWS, COLS);
void setup()
{
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(8,0);
digitalWrite(9,0);
lcd.begin(16, 2);
lcd.print(" Kunci Elektrik");
lcd.setCursor(0,1);
lcd.print("Dengan Password");
delay(2000);
//---------------------cek alamat 0
cek=EEPROM.read(0);
if(cek==0xFF){
cek=1;
EEPROM.write(0,'1');
pw1='1'; EEPROM.write(1,'1');
pw2='1'; EEPROM.write(2,'1');
pw3='1'; EEPROM.write(3,'1');
pw4='1'; EEPROM.write(4,'1');
pw5='1'; EEPROM.write(5,'1');
pw6='1'; EEPROM.write(6,'1');
}
else{
pw1=EEPROM.read(1);
pw2=EEPROM.read(2);
pw3=EEPROM.read(3);
pw4=EEPROM.read(4);
pw5=EEPROM.read(5);
pw6=EEPROM.read(6);
}
fkpd=0;
delay(200);
}
void loop()
{
//----------------------------- display time
digitalWrite(8,1);
lcd.clear();
lcd.print("Silakan kunci...");
lcd.setCursor(0,1);
lcd.print("Tekan #");
fkpd=2;
goKeypad();
lcd.clear();
lcd.print("Pintu Terkunci");
delay(3000);
pass:
lcd.clear();
lcd.print("Masukan Password");
lcd.setCursor(0,1);
fkpd=1;
menu=0;
goKeypad();
if(menu==4) goto pass;
}
//---------------------------- keypad
void goKeypad(){
do{
key=keypad.getKey();
if(key != NO_KEY){
if(key=='*' && fkpd==1){
lcd.clear();
lcd.print("Ganti Password");
lcd.setCursor(0,1);
lcd.print("PW lama=");
menu=1;
delay(300);
}
else if(key=='#' && fkpd==2){
fkpd=0;
digitalWrite(8,0);
delay(250);
}
else if ((key=='C')&&(fkpd == 1)){ //C
if(menu==3){
lcd.clear();
lcd.print("PW baru:");
menu=2;
for(t=0;t<6;t++)pw_kpd[t]=' ';
cnt=0;
}
else if(menu==2){
menu=4;
fkpd=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
cnt=0;
}
else if((menu==1)||(menu==0)){
menu=4;
fkpd=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
cnt=0;
}
delay(250);
}
else if (key=='D'&& menu==3){
lcd.clear();
lcd.print("Simpan PW Baru..");
EEPROM.write(1,pw_kpd[0]);
EEPROM.write(2,pw_kpd[1]);
EEPROM.write(3,pw_kpd[2]);
EEPROM.write(4,pw_kpd[3]);
EEPROM.write(5,pw_kpd[4]);
EEPROM.write(6,pw_kpd[5]);
EEPROM.write(0,1);
pw1 = pw_kpd[0];
pw2 = pw_kpd[1];
pw3 = pw_kpd[2];
pw4 = pw_kpd[3];
pw5 = pw_kpd[4];
pw6 = pw_kpd[5];
fkpd = 0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
delay(3000);
menu = 4;
}
else if(menu<2 && fkpd==1 && key!='A' && key!='B'
&& key!='C' && key!='D' && key!='*' && key!='#'){
cek_password();
}
else if(menu==2 && fkpd==1&& key!='A' && key!='B'
&& key!='C' && key!='D' && key!='*' && key!='#'){
entri_password();
}
}
}
while(fkpd);
}
void cek_password(){
pw_kpd[cnt]=key;
cnt++;
lcd.print('*');
// lcd.print(char(key));
if((cnt==6)&&(menu==0)){
delay(500);
if((pw1==pw_kpd[0])&&(pw2==pw_kpd[1])&&(pw3==pw_kpd[2])&&(pw4==pw_kpd[3])&&(pw5==pw_kpd[4])&&(pw6==pw_kpd[5])){
lcd.clear();
lcd.print("Password Benar");
lcd.setCursor(0,1);
lcd.print("Silakan Masuk");
digitalWrite(8,1);
digitalWrite(9,1);
delay(200);
digitalWrite(9,0);
delay(200);
digitalWrite(9,1);
delay(200);
digitalWrite(9,0);
cnt=0;
fkpd=0;
s=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
delay(3000);
}
else {
lcd.clear();
lcd.print("Password Salah");
s++;
if(s < 3){
digitalWrite(9,1);
delay(2000);
digitalWrite(9,0);
lcd.clear();
lcd.print("Masukan Password");
lcd.setCursor(0,1);
cnt=0;
for(t=0;t<6;t++)
pw_kpd[t]=' ';
}
else if (s==3){
lcd.clear();
lcd.print("Anda 3x Salah");
lcd.setCursor(0,1);
lcd.print("Tunggu 5 Menit");
for(i=0;i<75;i++){
digitalWrite(9,1);
delay(2000);
digitalWrite(9,0);
delay(2000);
}
lcd.clear();
lcd.print("Masukan Password");
lcd.setCursor(0,1);
cnt=0;
s=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
}
}
}
else if((cnt==6)&&(menu==1)){
if((pw1==pw_kpd[0])&&(pw2==pw_kpd[1])&&(pw3==pw_kpd[2])&&(pw4==pw_kpd[3])&&(pw5==pw_kpd[4])&&(pw6==pw_kpd[5])){
lcd.clear();
lcd.print("Password Benar");
lcd.setCursor(0,1);
delay(2000);
lcd.clear();
lcd.print("PW baru:");
cnt=0;
menu=2;
s=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
}
else {
s++;
if(s < 3){
lcd.clear();
lcd.print("Password Salah");
cnt=0;
delay(2000);
lcd.clear();
lcd.print("Ganti Password");
lcd.setCursor(0,1);
lcd.print("PW lama=");
for(t=0;t<6;t++)pw_kpd[t]=' ';
}
else if (s==3){
lcd.clear();
lcd.print("Anda 3x Salah");
lcd.setCursor(0,1);
lcd.print("Tunggu 5 Menit");
for(i=0;i<75;i++){
digitalWrite(9,1);
delay(2000);
digitalWrite(9,0);
delay(2000);
}
lcd.clear();
lcd.print("Ganti Password");
lcd.setCursor(0,1);
lcd.print("PW lama=");
cnt=0;
s=0;
for(t=0;t<6;t++)pw_kpd[t]=' ';
}
}
}
}
void entri_password(){
lcd.print(char(key));
pw_kpd[cnt]=key;
cnt++;
if(cnt==6){
lcd.setCursor(0,1);
lcd.print("D=save,C=cancel");
menu=3;
cnt=0;
}
}
How it Works
1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino
4. POWER SUPPLY DO NOT EXCHANGE BETWEEN 12V AND 9V !!!
5. MAXIMUM FOR SELENOID OPEN (UNLOCK) IS 60 SECONDS !!! TURN ON SELENOID FOR
MORE THAN 60 SECOND CAN CAUSE SELENOID BROKEN !!! (DEPENDS ON SOLENOID
WHICH YOU USE)
6. LCD Initial display
Electric Key
with Password
7. Next will appear command to lock (selenoid active)
Lock Please
Press #
8. Press the hastage (#) button to lock it.
The door is locked
9. On locked door condition. To open it required a password that is a combination of 6 digit numbers
are entered through the keypad
Enter the password
number 6 times
Enter the password
11. If the password is correct then it will appear
Password is correct
Please enter
12. The buzzer will also rang : "beep - beep", then the active relay and selenoid will open.
13. If the password you've entered is incorrect
Incorrect Password
The buzzer will rang: "beep .........(With long periode) " then you are prompted to enter the
password again
Enter the password
14. The chance of entering a password is 3 times. If it is 3 times the password is inccorrect, then it must wait 5 minutes to be able to enter password again
3x incorrect password
wait for 5 minutes
15. To change the password, make sure the dvice is locked
Enter the password
16. To change the password, press the star key (*)
Change the password
Old Password =
17. Next, enter the old password. If the device has not been changed its password, then The initial
password is: "111111" (number 1 six times)
Change the password
Old Password =
18. If the password is correct then it will show:
Correct password
19. Approximately 2 seconds later will appear request a new password
New password
20. Enter the desired new password.
New password : xxxxxxx
21. Then the option appears to save the password or cancel. Press "D" if will save (change password)
or "C" if cancel.
New Password : 234567
22. Press "D" to save the new password.
Saving new password
23. Next will return to normal condition (closed).
enter the password
24. To unlock now use the new password.
25. OK.
Video for Project V - 1. Electric Key with Password using Keypad Module (Arduino Based)
Required File
No comments:
Post a Comment