Electronic Door Locks using PIC Microcontroller

Hello friends, hope you are having fun. Today, I am going to share two types of Electronic Door Locks design using PIC Microcontroller and simulated in Proteus ISIS software. We all know about Electronic Door Locks as we have seen them in many homes. In electronic door locks, there's some password that is only known to some persons. Now if you enter the wrong password then the door won't open up and will ask for the password again. And if you keep on trying the wrong password then it will start the buzzer or can alert the concerned person via SMS etc. So, such electronic door locks are quite common in our society and are considered among the best electronic door locks.

Today, I am going to share a similar project in which I have simulated an Electronic Door lock using PIC Microcontroller. I have used PIC18F452 Microcontroller and the compiler I have used for designing the code in MikroC Pro For PIC and the simulation is designed in Proteus ISIS. The code and the Proteus simulation are given for download below. You can also design this project using Arduino or any other microcontroller like 8051 Microcontroller. Let's start with this project.

Note:

Electronic Door Locks using PIC Microcontroller

I have divided this Electronic Door Locks Project into few parts, and I have explained them separately. You can download the complete project along with the Proteus simulation by clicking the below button. But as I always suggest don't just download it, also design it on your own so that you learn more from it:

Electronic Door Locks using PIC Microcontroller

Project Overview of Smart Door Lock

  • In this smart door lock project, I have used a solenoid along with a relay.
  • We all know that in order to lock a door we have to use either a DC Motor or some solenoid, which should be connected with the manual lock of the door.
  • Now, all we need to do is to move that motor according to our needs automatically. Like if I move the motor in one direction, the door goes locked and if I move it in opposite direction then it got unlocked.
  • So, in my simulation, I have used a solenoid valve for locking purposes and I have represented it using Inductors in my simulation.
  • Moreover, I have used Serial Terminal as a communication medium, means we are gonna input for password etc in the serial monitor.
  • I have also used EEPROM in this project to save the current password.
  • There's an option in this project to change the password, so if the user changed the current password then the new password will be saved in EEPROM.
  • So, even if the device restarts, the newly changed password will remain active as it's saved in EEPROM.
  • If the user entered the wrong password then the system will for the password again.
  • But if the user entered the wrong password three consecutive times, the system will shut down and will start blinking the RGD lights, which I have used as an indication.

Schematics Diagram of Smart Door Lock

  • Let's first design the schematics diagram of the Electronic Smart Door Lock using a PIC Microcontroller.
  • I have designed the schematic in Proteus ISIS software as it's the best simulating software.
  • The schematic diagram is shown in the below figure:
  • It's quite clear from the above figure that I have used a PIC Microcontroller as the brain of the system.
  • I have a serial terminal, which is used to take inputs from the users.
  • I have used two relays and in order to drive those relays, I have used transistors.
  • Transistors are converting 5V coming from Microcontroller into 12V which are driving relays.
  • Moreover, I have also used optocouplers, which are just used for protection.
  • Finally, I have used three LEDs that are acting as RGB and will just indicate the wrong password.
  • These two relays are actually actuating the solenoid which will lock or unlock the door.
  • There's no active solenoid component available in Proteus that's why I have used a simple inductor.
  • Now, let's have a look at the programming code for this project.

Programming Code of Electronic Door Lock

  • I have designed the programming code for PIC Microcontroller in MkiroC Pro for PIC compiler.
  • You should have a look at these Top 3 PIC C Compilers and can select the one you like.
  • The PIC Microcontroller used in this Electronic door locks project is PIC18F4520. You can also use other PIC Microcontrollers like PIC16F877a etc.
  • You can use any other PIC Microcontroller if you want. You just need to change it in simulation and in code settings.
  • Now here's the complete programming code for Electronic Door Locks using PIC Microcontroller:
 char Indata;
 char P1 = '1';
 char P2 = '2';
 char P3 = '3';
 int PassCheck = 0;
 int WrongCheck = 0;
 int CPassCheck = 0;
 

void Initialization()
{
      UART1_Init(9600);
      TRISD = 0;
      PortD = 0;
      P1 = EEPROM_Read(0x01);
      P2 = EEPROM_Read(0x02);
      P3 = EEPROM_Read(0x03);
}

void PassChange()
{
            while(1)
            {
                  if (UART1_Data_Ready())
                  {
                        Indata = UART1_Read();

                        if(CPassCheck == 2){
                             CPassCheck = 3; 
                             EEPROM_Write(0x03, Indata); 
                             P3 = EEPROM_Read(0x03);}
                        if(CPassCheck == 1){
                             CPassCheck = 2; 
                             EEPROM_Write(0x02, Indata); 
                             P2 = EEPROM_Read(0x02);}
                        if(CPassCheck == 0){
                             CPassCheck = 1; 
                             EEPROM_Write(0x01, Indata); 
                             P1 = EEPROM_Read(0x01);}
                        UART1_Write_Text("*");
                        if(CPassCheck == 3){break;}
                  }
            }
            
            UART1_Write(10);
            UART1_Write(13);
            UART1_Write(10);
            UART1_Write(13);
}

void CorrectPass()
{
            UART1_Write(10);
            UART1_Write(13);
            UART1_Write(10);
            UART1_Write(13);
            UART1_Write_Text("Select one of the below Options: ");
            UART1_Write(10);
            UART1_Write(13);
            UART1_Write(10);
            UART1_Write(13);
            UART1_Write_Text("1) Press Y to Lock.");
            UART1_Write(10);
            UART1_Write(13);
            UART1_Write_Text("2) Press N to Unlock.");
            UART1_Write(10);
            UART1_Write(13);
            UART1_Write_Text("3) Press C to Change Password.");
            UART1_Write(10);
            UART1_Write(13);
            UART1_Write(10);
            UART1_Write(13);
            UART1_Write_Text("Waiting for Response: ");
            
            while(1)
            {
                  if (UART1_Data_Ready())
                  {
                        Indata = UART1_Read();

                        if((Indata == 'Y') || (Indata == 'y')){
UART1_Write_Text("Y"); 
PortD.F0 = 1; 
PortD.F1 = 0; 
UART1_Write(10); 
UART1_Write(13); 
UART1_Write(10); 
UART1_Write(13); break;}
                        if((Indata == 'N') || (Indata == 'n')){
UART1_Write_Text("N"); 
PortD.F0 = 0; 
PortD.F1 = 1; 
UART1_Write(10); 
UART1_Write(13); 
UART1_Write(10); 
UART1_Write(13); break;}
                        if((Indata == 'C') || (Indata == 'c')){
UART1_Write_Text("C"); 
UART1_Write(10); 
UART1_Write(13); 
UART1_Write(10); 
UART1_Write(13); 
UART1_Write_Text("Enter New Password: "); 
PassChange();break;}


                  }
            }
}

void WrongPass()
{
         int x = 0;
         PortD.F5 = 1;
         while(1)
         {

             PortD.F2 = 1;
             Delay_ms(100);
             PortD.F2 = 0;
             PortD.F3 = 1;
             Delay_ms(100);
             PortD.F3 = 0;
             PortD.F4 = 1;
             Delay_ms(100);
             PortD.F4 = 0;
             x = x + 1;
             if(x > 30){break;}
         }
         PortD.F5 = 0;
}


void main() {
      Initialization();

      do
      {
          UART1_Write_Text("Enter Password: ");
          while(1)
          {
                if (UART1_Data_Ready())
                {
                      Indata = UART1_Read();

                      if((Indata == P1) && (PassCheck == 0)){PassCheck = 1;}
                      if((Indata == P2) && (PassCheck == 1)){PassCheck = 2;}
                      if((Indata == P3) && (PassCheck == 2)){PassCheck = 3;}

                      if((Indata == 13) && (PassCheck == 3)){
PassCheck = 0; 
WrongCheck = 0; 
UART1_Write(10); 
UART1_Write(13); 
UART1_Write_Text("Correct Password.");
CorrectPass();break;}
                      if((Indata == 13) && (PassCheck != 3)){
PassCheck = 0; 
UART1_Write(10); 
UART1_Write(13); 
UART1_Write_Text("Wrong Password."); 
WrongCheck = WrongCheck + 1; 
if(WrongCheck == 3){WrongPass();}
UART1_Write(10); UART1_Write(13); 
UART1_Write(10); UART1_Write(13);break;}
                      UART1_Write_Text("*");
                }
          }

      } while(1);
}
  • I have placed checks on the Enter button like when the user presses Enter button then it will check either password is correct or wrong and then will decide and on or off the respective relays.
  • Moreover, the third option is to change the password and you can see right after the change password, I have used EEPROM commands to save the password for later use.
  • Let's now start the simulation and test our project.
Note: If you are not much familiar with relays, then you should read these tutorials on relays:

Electronic Door Lock Simulation Result

  • We have seen all the details about the project and I am quite confident that now you can quite easily design this project on your own.
  • So, now let's start the simulation and have a look at the results.
  • When you start your simulation then you will have such a screen:
  • Now you can see, it's asking for a password in the Virtual Terminal.
  • The default password set is "123". So, I am gonna give it 123.
  • Now, when I gave it the correct password, it asked for the correct option.
  • I have added a total of 3 options to it, which are shown in the above figure.
  • So, if the user presses Y then it will lock the door and if he presses N then it will unlock the door and last option is to change the password which is set for C.
  • So, that's how this project is working.
  • Similarly, if I gave it the wrong password the nit will ask for try again for 3 times and then will set off the RGB lights to warn.
  • Complete demonstration and working of this project is given in the below video:

That's all for the electronic smart door lock project using PIC Microcontroller. I hope you have enjoyed it. Will meet you guys in the next tutorial soon. Till then take care and have fun. :)

Electronics Projects

Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a complete list of Electronics Projects which I have posted on our blog. I hope you are gonna enjoy these electronics projects. Most of these electronics projects are designed using Proteus simulation software. I have also uploaded these simulations in the respective project tutorial. So, you can download those projects and can learn from them a lot. If you ask me then I suggest that instead of downloading these electronics projects simulations, you should design them on you own so that you learn from them. I know you are gonna do mistakes but you won't learn unless you do mistakes. :)

All these projects are completely designed by our team so other bloggers are welcome to share them on their blogs to share the knowledge but do mention our blog link as a favor. Moreover, if you guys got into any trouble in any of these tutorials then ask in comments and I will try my best to resolve them as fast as I could. I will keep on updating this list. Whenever I post some new electronics project on my blog, I will share the link here. So, its like we are having all electronics projects in one place. I hope you are gonna like it. I have divided these electronics projects in sections depecding upon the microcontroller used for designing them. I have used Arduino , PIC Microcontroller and 8051 Microcontroller usually for designing electronics projects so I have divided it in the same category. Let's get started with it:

Electronics Projects

I have divided these projects in separate sections as posting them all at once will make them a mess. So, I have divided them according to their types and I think it will be easy to read them out that way. So, first of there's Arduino based Electronics Proejcts and after that I have posted electronics projects on PIC Microcontroller and finally on 8051 Microcontroller. I have also added few projects on 555 Timer at the end. So, let's start with it:

Arduino based Electronics Projects

All these below electronics projects are designed using Arduino board. If you are interested in Arduino then you should check Arduino Projects where I have posted all about Arduino and have posted many tutorials on it. Here I am posting only those Arduino links where's electronics is involved. On the Arduino main page you will also find Arduino Library for Proteus which is designed by our team and will be really helpful to you if you wanna design the simulation of Arduino based projects in Proteus.

PIC based Electronics Projects

Here's a list of PIC Microcontroller based electronics projects. These are not much but I am gonna add more soon. Most of these PIC Microcontroller projects are designed in Proteus software. Their simulations and programming code are also given in these projects which you can download and use. But as I always say don't just copy paste them. Instead design them on your own so that you learn from them.

8051 based Electronics Projects

Here's a list of 8051 Microcontroller based Electronics Projects. These are all design in Proteus software and their simulations are also given in the respective project to download. I am gonna add more soon in this section as I am working on many projects which involves 8051 Microcontroller. I will update the list soon.

555 Timer based Electronics Projects

These are 555 Timer based Electronics Projects. These are also designed in Proteus software. You can download the simulations as well in these links. Its kind of a bonus here :) but you 555 Timer is used quite a lot in simple projects because microcontroller become costly for simple projects and also there's no need of programming 555 Timer.

So, that's all for today. I hope you are gonna enjoy these Electronics Projects. Actually I am compiling things on my blog and giving them a proper arrangement. :) If you have any suggestion please post in the comments. So, take care and have fun !!! :)

   
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir