--> Project V - 2. Electric Key with Password using Android (Arduino Based) | basic arduino tutorial

Thursday, August 10, 2017

Project V - 2. Electric Key with Password using Android (Arduino Based)

| Thursday, August 10, 2017
Electric Key with Password using Android




This device consists of Arduino UNO as the main system & controller of the system. Bluetooth Module is used as the sender and receiver of data transfer from smart phone (using Bluetooth SPP Pro.Apk). The Blutooth SPP Pro.Apk application on Smartphone / Android is used as a password data to determine whether the password is correct so that the key is open, and if the password is incorrect so that the key is closed. It's used also to change old password with new password. LCD is used for display when password entry or when we change the password and to show status of the door. Relay as an actuator that will control the selenoid directly. Last selenoid is used to open or close the door lock.

Hardware Requirement
  • HC-05 Bluetooth Module
  • 2x16 LCD Module
  • Relay with Single Channel Module
  • Solenoid
  • Buzzer
  • Arduino UNO
  • Power supply +5 Volt



                                   Buzzer | Source                        Solenoid Lock Door | Source


                        Relay Module with 1 Channel |  Source                        Buzzer | Source

Block Diagram


Schematic


Arduino - LCD Wiring



Arduino - Keypad Module Wiring


Arduino - Relay - Buzzer Wiring 



Source Code/Sketch


#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;
}
}

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. After 2 seconds, will appear a command to send data / character 'L' to lock device  (selenoid
    active)

Lock Please
Press L

8. Open Bluetooth Spp pro app, if not there you can install first Apk it is on the Download Link or
    you can also instal through the Play store with the Bluetooth keyword SPP Pro.
9. Select Bluetooth Device HC-05.


10. Tap the Connect Button


11. Select keyboard mode


12. Setting keyboard


13. Click on ClickMe button, change in BTN Name column with number 1 & BTN Down with  
      number 1 then click OK.


14. Setting all Buttons from 1 to 9 in the BTN Down field is filled in accordance with BTN Name.


15. Further on the left bottom corner column is filled with 'L / S' and on the bottom right corner is
      filled 'E / C' while in the middle column is filled with the number 0.


16. After all the buttons are completed in the settings then select Buttons set complate in the corner
       menu. The application is ready to use.

17. Press 'L' key to lock it

So LCD display as follows:

The door is locked

18. Next enter the locked door condition. To open it required a password that is a combination of 6
      digit number that is entered through the Application

Enter the password

19. For the initial password value, the password code is "111111" (number 1 six times). Press "1"
      number 6 times

Enter the password

20. If the password is correct then it will appear

Password is correct
Please enter

21. Buzzer will also read: "beep - beep", then the active relay and selenoid will open.

22. If password is incorrect

Incorrect Password


      The buzzer will rang: "beep .........(With long periode) " then you are prompted to enter the
      password again


Enter the password

23. 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

24. To change the password, make sure the dvice is locked

Enter the password


25. To change the password, press the E key (E)

hange the password
Old Password =

26.  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 =

27. If the password is correct then it will show:

Correct password

28. Approximately 2 seconds later will appear request a new password

New password

29. Enter the desired new password.

New password : xxxxxxx

30. Then the option appears to save the password or cancel. Press and hold "L / S" button about ½ 
      second if will save (change password) or press and hold "E / C" button about ½ second if cancel.

New Password : 234567

31. Press and hold the "L / S" key to save the new password.

Saving new password

32. Next will return to normal condition (lock closed).

enter the password


33. To unlock now use the new password.

34. OK.



Video for Project V - 2. Electric Key with Password using Android (Arduino Based)





Required File

Related Posts

No comments:

Post a Comment