• Home
  • Courses
  • Machines
    • Transformer
    • AC Motors
      • Induction Motor
      • Synchronous Motor
    • DC Motor
    • DC Generator
  • Power System
    • Circuit Breaker
    • Switchgear
    • Substation
    • Control System
    • Measurement
  • Electronics
  • Blog
  • Contact
    • Contact Us
    • Privacy Policy
Have any question?
[email protected]
Login
StudyElectrical.Com
  • Home
  • Courses
  • Machines
    • Transformer
    • AC Motors
      • Induction Motor
      • Synchronous Motor
    • DC Motor
    • DC Generator
  • Power System
    • Circuit Breaker
    • Switchgear
    • Substation
    • Control System
    • Measurement
  • Electronics
  • Blog
  • Contact
    • Contact Us
    • Privacy Policy

    Projects

    How to Make a Digital Lock Using Arduino?

    • Categories Projects, Arduino, Electronics
    digital lock arduino

    Digital code locks are most common in security systems. An electronic lock or digital lock is a device which has an electronic control assembly attached to it. They are provided with an access control system.

    This system allows the user to unlock the device with a password. The password is entered by making use of a keypad. The user can also set his password to ensure better protection.

    In this project, major components include a keypad, LCD and the controller Arduino. This article describes the making of an electronic code lock using Arduino.

    Table of Contents

    • Components Required
    • Digital Code Lock Circuit
    • Program Code for Arduino Digital Code Lock
    • Digital Lock Using Arduino Code
    • Related Articles

    Components Required

    The following components are required for making the digital code lock

    1. Arduino Uno
    2. 16×2 LCD Display
    3. 4×4 keypad
    4. Relay
    5. 1K Resistors Qty. 3
    6. BC548
    7. LEDs

    Digital Code Lock Circuit

    Code lock circuit is constructed around Arduino Uno, using LCD and keypad. 

    LCD and keypad forms the user interface for entering the password and displaying related messages such as “Invalid password”, “Door open”, etc. 

    Two LEDs are provided to indicate the status of door whether it is locked or open. To operate latch/lock we are using Relay which can be connected to the electronic actuator or solenoid.

    Digital Door Lock using arduino
     Digital Door Lock using Arduino

    Program Code for Arduino Digital Code Lock

    The program is constructed using two libraries “LiquidCrystal” and “Keypad”. 

    Program have different modules, Setup, Loop, Lock. 

    In setup, we initialize all the IO connections and LCD, Keypad. 

    In the main loop, we are taking pressed keys in array “code[]”, Once the four digits are entered we stop accepting keys. 

    We are using numeric keys and ‘C’, “=” key. ‘C’ key is used to lock or clear the display in case the wrong password is entered. 

    We can hide the entered password by putting Star character ‘*’.

    After entering the password ‘=’ key acts as ok. If the password is the correct door is kept unlocked for few seconds. If it is incorrect message will be displayed.

    Digital Lock Using Arduino Code

    /* Digital Code Lock Demo */
    #include <Keypad.h>
    #include <LiquidCrystal.h>
    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd (9, 8, 7, 6, 5, 4);
    const byte ROWS = 4; //four rows
    const byte COLS = 4; //four columns
    //define the cymbols on the buttons of the keypads
    char hexaKeys [ ROWS ][ COLS ] = {
    {‘7′,’8′,’9′,’/’},
    {‘4′,’5′,’6′,’*’},
    {‘1′,’2′,’3′,’-‘},
    {‘C’,’0′,’=’,’+’}
    };
    byte rowPins [ ROWS ] = {3, 2, 19, 18}; //connect to the row pinouts of the keypad
    byte colPins [ COLS ] = {17, 16, 15, 14}; //connect to the column pinouts of the keypad
    //initialize an instance of class NewKeypad
    Keypad customKeypad = Keypad ( makeKeymap ( hexaKeys ), rowPins , colPins , ROWS ,
    COLS );
    const int LED_RED =10; //Red LED
    const int LED_GREEN =11; //Green LED
    const int RELAY =12; //Lock Relay or motor
    char keycount =0;
    char code [4]; //Hold pressed keys
    //=================================================================
    // SETUP
    //=================================================================
    void setup (){
    pinMode ( LED_RED , OUTPUT );
    pinMode ( LED_GREEN , OUTPUT );
    pinMode ( RELAY , OUTPUT );
    // set up the LCD’s number of columns and rows:
    lcd . begin (16, 2);
    // Print a message to the LCD.
    lcd . print (“Password Access:”);
    lcd . setCursor (0,1); //Move coursor to second Line
    // Turn on the cursor
    lcd . cursor ();
    digitalWrite ( LED_GREEN , HIGH ); //Green LED Off
    digitalWrite ( LED_RED , LOW ); //Red LED On
    digitalWrite ( RELAY , LOW ); //Turn off Relay (Locked)
    }//
    =================================================================
    // LOOP
    //=================================================================
    void loop (){
    char customKey = customKeypad . getKey ();
    if ( customKey && ( keycount <4) && ( customKey !=’=’) && ( customKey !=’C’)){
    //lcd.print(customKey); //To display entered keys
    lcd . print (‘*’); //Do not display entered keys
    code [ keycount ]= customKey ;
    keycount ++;
    }
    if(customKey == ‘C’) //Cancel/Lock Key is pressed clear display and lock
    {
    Lock (); //Lock and clear display
    }
    if(customKey == ‘=’) //Check Password and Unlock
    {
    if(( code [0]==’1′) && ( code [1]==’2′) && ( code [2]==’3′) && ( code [3]==’4′)) //Match the
    password. Default password is “1234”
    {
    digitalWrite ( LED_GREEN , LOW ); //Green LED Off
    digitalWrite ( LED_RED , HIGH ); //Red LED On
    digitalWrite ( RELAY , HIGH ); //Turn on Relay (Unlocked)
    lcd . setCursor (0,1);
    lcd . print (“Door Open “);
    delay (4000); //Keep Door open for 4 Seconds
    Lock ();
    }
    else
    {
    lcd . setCursor (0,1);
    lcd . print (“Invalid Password”); //Display Error Message
    delay (1500); //Message delay
    Lock ();
    }
    }
    }
    //=================================================================
    // LOCK and Update Display
    //=================================================================
    void Lock ()
    {
    lcd . setCursor (0,1);
    lcd . print (“Door Locked “);
    delay (1500);
    lcd . setCursor (0,1);
    lcd . print (” “); //Clear Password
    lcd . setCursor (0,1);
    keycount =0;
    digitalWrite ( LED_GREEN , HIGH ); //Green LED Off
    digitalWrite ( LED_RED , LOW ); //Red LED On
    digitalWrite ( RELAY , LOW ); //Turn off Relay (Locked)
    }

    Related Articles

    • arduino program structure
      How to Structure an Arduino Program?

      If you are new to programming and want to understand how Arduino programs work, read…

    • Arduino Digital Voltmeter
      Arduino DC Digital Voltmeter

      A voltmeter is an instrument used for measuring electrical potential difference between two points in…

    • Automatic Irrigation System Using Arduino
      Automatic Irrigation System Using Arduino

      In this project, we will make an automatic irrigation system using Arduino microcontroller. Automatic Irrigation…

    • Controlling a Servo Motor with Arduino
      Controlling a Servo Motor with Arduino

      A servomotor is also defined as a rotary actuator that allows for very fine control…

    • maxresdefault
      An Introduction to the Arduino for Beginners

      What is Arduino? Arduino is an open-source platform used for building electronics projects. Arduino consists…

    • Automatic Light Controller arduino
      Arduino based Automatic Light Controller

      The automatic light controller offers energy saving and convenience in the areas with a photosensor…

    • Share:
    author avatar
    Electrical Engineer

    Previous post

    Basic Relays - Electromagnetic Attraction and Induction Relays
    November 1, 2016

    Next post

    IEC 61850 - Features and Advantages
    November 2, 2016

    You may also like

    dc bias characteristics of capacitor
    What is a capacitor’s DC bias characteristic?
    22 March, 2023
    passive components
    Understanding Passive Components in Electrical Engineering
    3 March, 2023
    used oscilloscope buying guide (1)
    Buying a Used Oscilloscope: A Guide to Help You Decide
    28 February, 2023

    Leave A Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Search Here

    From Blog

    dc motor troubles
    4 Major Troubles in a DC Motor with Reasons
    21May2014
    external-characteristics-of-dc-compound-generator.
    Characteristics of DC Compound Generator
    19Aug2014
    minimum oil circuit breaker
    Oil Circuit Breakers – Types, Working and Construction
    28Jun2016
    single-phase-Induction
    Single Phase Induction Motor – Working Principle and Construction
    09May2014

    Categories

    • Alternator
    • Arduino
    • Basic Electrical
    • Battery
    • Books
    • Cables
    • Capacitor
    • Career
    • Circuit Breaker
    • Control System
    • DC Generator
    • DC Generator MCQ
    • DC Generator Solved Problems
    • DC Motor
    • DC Motor MCQ
    • Drives
    • Electric Vehicles
    • Electrical Circuits
    • Electrical Machines
    • Electrical Relays
    • Electrical Safety
    • Electronics
    • Embedded System
    • Exams
    • Generation
    • Guest Post
    • HVDC
    • Instrumentation
    • Interview Questions
    • Locomotives
    • MCQ
    • Measurement
    • Microcontroller
    • Objective Questions
    • PCB
    • PLC
    • Power System
    • Problems and Solution
    • Projects
    • Resistor
    • Signals and Systems
    • Single Phase Motors
    • Substation
    • Switchgear
    • Synchronous Motor
    • Three Phase Induction Motor
    • Transformer
    • Transmission Line
    • Uncategorized

    Copyright © 2021 Study Electrical, Inc.

    © StudyElectrical.Com 2021

    Login with your site account

    Lost your password?