Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

Sequential code lock for automatic gate

By Ashutosh Bhatt

The password based lock for any access control systems is very common now a day. If there is a password lock for any gate/door, then the gate or door only opens when correct password is entered. Mostly in such system numeric keypad is given to enter password. Sequential code lock differs here with normal password lock system. It does not have full numeric keypad with 10 to 12 switches. Instead it has 2 to 3 switches only. The user has to enter correct sequence of numeric digits just like sequential locks available in briefcases. When the numeric digits are arranged in correct sequence it unlocks.

In this project, the user has to first set the correct sequence of digits by scrolling them from 0 to 9 pressing only 1 button only, similar to scrolling and setting digit in briefcase lock. User has to set all digits one by one to complete the sequential code. The project is build using micro controller AT89C52. It uses LCD to display various messages. The stepper motor is used to give illustration of opening and closing gate.

Circuit description

Circuit Diagram of 8051 Microcontroller based Sequential Code Lock System

Fig. 1: Circuit Diagram of 8051 Microcontroller based Sequential Code Lock System

·Port P1 is configured as input and 3 push buttons are connected to pins P1.0 to P1.2 as such when button is pressed that pin gets 0 as an input

·   Port P0 is an output port and it drives data pins of LCD D0 – D7. Further two pins of port P2 P2.7 and P2.6 are connected to control pins       of LCD Rs and E. The third control pin RW is permanently connected to ground to make LCD always write enable

·   A 1 K pot is connected to brightness control pin Vee of LCD to vary its brightness

·   Port P3 pins P3.4 – P3.7 drives stepper motor through motor driver chip ULN2003A. The motor opens or closes the gate

·   A 12 MHz crystal is connected between XTAL pins along with two biasing capacitors of 33 pf. It provides clock signal to micro controller

Circuit operation:

·   When the system is powered ON, the gate is closed and the message is displayed on LCD as “To open gate Enter code”

·   To enter code the user has to press digit key. He has to keep pressing digit key again to scroll all the digits from 1 to 0. Like pressing key       once will display digit 1, pressing key twice displays digit 2, likewise 3, 4, 5,….. up to 0 and again starts from 1

·   Once he reaches to desire digit, to set the digit he has to press second button to set the digit as 1st digit of code. After setting first digit         the cursor shifts to second digit position

·   Again user has to scroll digits starting from 1 and reach to desire digit using 1st button. Set the second digit of code by pressing 2nd button

·   Similarly user has to set 4 digit code. Once 4 digit code is set, user will press enter button

·   When enter button is pressed, the micro controller will compare the entered code with programmed code

·   If they match the motor rotates clockwise to open the gate and message is displayed on LCD as “gate open”. After 5 seconds again motor     rotates anticlockwise to close the gate and LCD displays “gate close” and then again the default message “To open gate Enter code” is           displayed

·   But if the code does not match then motor stands still and warning message displayed as “wrong code”. Also if wrong code is entered for 3     times, the system enters into infinite loop (that means it hangs). It can come out of the loop only when reset button is pressed to reset the     system again.

Project Source Code

###


#include 

#include

 

#define ON 0

#define OFF 1

 

sbit rs = P2^7;

sbit en = P2^6;

sbit unlock_led = P2^0;

sbit lock_led = P2^1;

 

unsigned int number_count=0,code_num[4],code_digit=0,set_count=0,gate_flag=0;

unsigned int code_lock_num = 1122,attempt=0,reset_flag=0;

 

void dly()

  {

       int y,z;

       for(z=0;z<100;z++)

        for(y=0;y<1000;y++);

  }   

void motor_delay()

 {

       int p;

       for(p=0;p<2000;p++);

 }

void wait_for_5_sec()

 {

        int r,s;

       for(r=0;r<100;r++)

         for(s=0;s<10000;s++);

 }    

void lcd_delay()

 {

       int y;

       for(y=0;y<2000;y++);

 }

void writecmd(unsigned char a)

{

       lcd_delay();

       rs = 0;

       P0 = a;     

       en = 1;     

       en = 0;     

}

void writedat(unsigned char b)

{

       lcd_delay();

       rs = 1;            

       P0 = b;

       en = 1;     

       en = 0;     

}

 

void writestr(unsigned char *s)

{

       unsigned char l,i;

       l = strlen(s);

       for(i=0;i

       {

             writedat(*s);

             s++;        

       }     

}

void lcd_init()

  {

       writecmd(0x3C);

       writecmd(0x0E);

       writecmd(0x01);

       writestr("To open gate");

       writecmd(0xC0);

       writestr("Enter code:");

  }   

void initialize()

  {

       P1=0xFF;

       P0=0x00;

       P2 = 0x00;

       P3 = 0x00;

       }     

void open_gate()

  {

       unsigned int i;    

       writecmd(0x01);

       writestr("Gate open");          

       for(i=0;i<128;i++) 

       {

              P3 = 0x8F;

             motor_delay();

             P3 = 0x4F;

             motor_delay();

             P3 = 0x2F;

             motor_delay();

             P3 = 0x1F;

             motor_delay();

       }

       wait_for_5_sec();

       writecmd(0x01);

       writestr("Gate closed");  

       for(i=0;i<128;i++) 

        {

             P3 = 0x1F;

             motor_delay();

             P3 = 0x2F;

             motor_delay();

             P3 = 0x4F;                                    

             motor_delay();

             P3 = 0x8F;

             motor_delay();

        }

       }           

void number()

{

        if(set_count==0) writecmd(0xCB);

        else if (set_count==1) writecmd(0xCC);

        else if(set_count==2) writecmd(0xCD);

        else if(set_count==3) writecmd(0xCE);        

        number_count++;

        if(number_count==1) {writedat(0x31);}

        else if(number_count==2) {writedat(0x32);}

        else if(number_count==3) {writedat(0x33);}

        else if(number_count==4) {writedat(0x34);}

        else if(number_count==5) {writedat(0x35);}

        else if(number_count==6) {writedat(0x36);}

        else if(number_count==7) {writedat(0x37);}

        else if(number_count==8) {writedat(0x38);}

        else if(number_count==9) {writedat(0x39);}

        else if(number_count==10){writedat(0x30);number_count=0;}

}

void set_number()

{

       set_count++;                    

       code_num[code_digit]=number_count;

       number_count=0;           

       code_digit++;             

}

void enter_number()

  {

       unsigned int tmp;

       tmp= code_num[0]*1000+code_num[1]*100+code_num[2]*10+code_num[3];

       if(tmp == code_lock_num)

       {

             unlock_led = ON;   

             lock_led = OFF;                               

             open_gate();

              gate_flag=1;

             set_count=0;

             code_digit=0;

             attempt=0;

       }

       else

         {

             writecmd(0x01);

             writestr("wrong code");

             attempt++;

             if(attempt==3)

                {

                    writecmd(0x01);

                    writestr("attempts over");

                    writecmd(0xC0);

                    writestr("System Hang");

                    reset_flag=1;

                 }

             else

               {

                    writecmd(0xC0);

                    writestr("try again");

                    gate_flag=1;

                    set_count=0;

                    code_digit=0;

               }

             }     

       }           

void main()

 {

       initialize();

again: lcd_init();

       gate_flag=0;

       unlock_led = OFF;  

       lock_led = ON;

back:  P1=0xFF;

       while(P1==0xFF);

       switch(P1)

        {

          case 0xFE:

                  number();

                  dly();

                  break;

          case 0xFD:

                set_number();

                dly();

                break;

         case 0xFB:                           

             enter_number();

              dly();

             break;

         }

       if(reset_flag==1) goto infinit;        

       else if(gate_flag==0) goto back;

       else goto again;

       infinit:while(1);

  }

###

 


Circuit Diagrams

Circuit-Diagram-8051-Microcontroller-Based-Sequential-Code-Lock-System

Project Video


Filed Under: Circuit Design, Electronic Projects

 

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • PS2 Keyboard To Store Text In SD Card Using Arduino Circuit Setup On Breadboard
    How To Use PS2 Keyboard To Store Text In SD Card Using Arduino- (Part 42/49)
  • Wireless Path Tracking System Using Mouse, XBee And Arduino Circuit Setup On Breadboard
    How To Make A Wireless Path Tracking System Using Mouse, XBee And Arduino- (Part 43/49)
  • How to Make a Wireless Keyboard Using Xbee with Arduino- (Part 44/49)
  • Making Phone Call From GSM Module Using Arduino Circuit Setup On Breadboard
    How to Make Phonecall From GSM Module Using Arduino- (Part 45/49)
  • How to Make a Call using Keyboard, GSM Module and Arduino
    How To Make A Call Using Keyboard, GSM Module And Arduino- (Part 46/49)
  • Receiving SMS Using GSM Module With Arduino Prototype
    How to Receive SMS Using GSM Module with Arduino- (Part 47/49)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • Renesas delivers intelligent sensor solutions for IoT applications
  • Microchip Technology releases AVR-IoT Cellular Mini Development Board
  • Qualcomm acquires Cellwize to accelerate 5G adoption and spur infrastructure innovation
  • MediaTek’s chipset offers high-performance option for 5G smartphones
  • Nexperia’s new level translators support legacy and future mobile SIM cards

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • about ATmega328 ADC pins
  • Tuning the antenna to be conjugately matched to input impedance of the die
  • Netlist physical name update
  • nt1065_USB3 gnss receiver
  • LLC HB with synchronous rectifiers can be very dodgy?

RSS Electro-Tech-Online.com Discussions

  • undefined reference header file in proteus
  • Capacitor to eliminate speaker hum
  • Decapped Chip On Board
  • Sony KV-A2913E (chassis AE1C) auto shuts off after one minute
  • CRT TV repair
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering