Code Lock Extreme Electronic

download Code Lock Extreme Electronic

of 19

Transcript of Code Lock Extreme Electronic

  • 8/10/2019 Code Lock Extreme Electronic

    1/19

    AVR ProjectATmega8 Based Smart Code Lock

    Here is a project for beginners using Atmel AVR ATmega8. The project uses some techniques that

    are very useful for designers to learn and utilize.

    Alphanumeric LCD Module Interfacing.

    44 Keypad interfacing.

    PWM Control of LED(Used to dim the back-light of LCD, like in some Nokia Phones)

    Basic Circuit design for AVR MCUs

    Connecting relays and other current demanding devices.

    AVR Studioand project management.

    compiling using free avr-gcc compiler.

    UsingeXtreme BurnerAVRto burn hex code to AVR MCU.

    NOTE:

    Dont waste time finding each part running from shop to shop. Get all the parts with exact

    specification in a ready to use kit!Purchase ATmega8 based smart code lock KIT.

    http://extremeelectronics.co.in/avr-tutorials/using-lcd-module-with-avrs/http://extremeelectronics.co.in/avr-tutorials/4x3-matrix-keypad-interface-avr-tutorial/http://extremeelectronics.co.in/avr-tutorials/4x3-matrix-keypad-interface-avr-tutorial/http://extremeelectronics.co.in/avr-tutorials/introduction-to-pwm-pulse-width-modulation/http://extremeelectronics.co.in/avr-tutorials/introduction-to-pwm-pulse-width-modulation/http://extremeelectronics.co.in/avr-tutorials/part-iv-the-hello-world-project/http://extremeelectronics.co.in/avr-tutorials/part-iv-the-hello-world-project/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://store.extremeelectronics.co.in/ATmega8-Based-Smart-Code-Lock-KIT.htmlhttp://store.extremeelectronics.co.in/ATmega8-Based-Smart-Code-Lock-KIT.htmlhttp://store.extremeelectronics.co.in/ATmega8-Based-Smart-Code-Lock-KIT.htmlhttp://store.extremeelectronics.co.in/ATmega8-Based-Smart-Code-Lock-KIT.htmlhttp://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/part-iv-the-hello-world-project/http://extremeelectronics.co.in/avr-tutorials/introduction-to-pwm-pulse-width-modulation/http://extremeelectronics.co.in/avr-tutorials/4x3-matrix-keypad-interface-avr-tutorial/http://extremeelectronics.co.in/avr-tutorials/using-lcd-module-with-avrs/
  • 8/10/2019 Code Lock Extreme Electronic

    2/19

    Fig.: ATmega8 Based Code Lock

    http://extremeelectronics.co.in/avrprojects/Images/CodeLockIso.jpghttp://extremeelectronics.co.in/avrprojects/Images/CodeLockIso.jpg
  • 8/10/2019 Code Lock Extreme Electronic

    3/19

    Fig.: ATmega8 Based Code Lock Project

    Functions of the Project.

    This device can be used to code protect any electrical device (like an electronic door, lock orsafe).

    The user must enter a correct password to gain access. The password is entered using the built in

    44 keypad matrix. The mainLCD Moduleis used to display messages to the user. As soon as

    correct password is entered the relay is activated. This is indicated by a LED which is placed near the

    relay. The relay remains on as long as the user wishes. You just need to press a key to deactivate the

    relay.

    After typing four digit password you must press the "OK"button (S8). At anytime you may pressthe "Cancel"key (S12 )to clear the input (e.g. when you enter any incorrect digit)

    The smart code lock has the feature to change the password too. For this enter a special password

    which is 0000, as soon as the system receives this special password it switches to change password

    mode. Here you need to enter the old password to gain permission, then enter the new password.

    The smart code lock also support power saving feature. The backlight of LCD turns off automatically

    when the system is idle for few seconds. The cool thing about this is that it usesPWM to control the

    brightness of LCD Backlight.So the dimming is very smooth and it is like those used in many mobile

    phones.

    http://extremeelectronics.co.in/avrprojects/Images/CodeLockTop.jpghttp://en.wikipedia.org/wiki/Safehttp://en.wikipedia.org/wiki/Safehttp://en.wikipedia.org/wiki/Safehttp://shop.extremeelectronics.co.in/product_info.php?cPath=25&products_id=32http://shop.extremeelectronics.co.in/product_info.php?cPath=25&products_id=32http://shop.extremeelectronics.co.in/product_info.php?cPath=25&products_id=32http://extremeelectronics.co.in/avr-tutorials/introduction-to-pwm-pulse-width-modulation/http://extremeelectronics.co.in/avr-tutorials/introduction-to-pwm-pulse-width-modulation/http://extremeelectronics.co.in/avr-tutorials/introduction-to-pwm-pulse-width-modulation/http://extremeelectronics.co.in/avr-tutorials/introduction-to-pwm-pulse-width-modulation/http://extremeelectronics.co.in/avrprojects/Images/CodeLockTop.jpghttp://extremeelectronics.co.in/avr-tutorials/introduction-to-pwm-pulse-width-modulation/http://extremeelectronics.co.in/avr-tutorials/introduction-to-pwm-pulse-width-modulation/http://shop.extremeelectronics.co.in/product_info.php?cPath=25&products_id=32http://en.wikipedia.org/wiki/Safe
  • 8/10/2019 Code Lock Extreme Electronic

    4/19

    Making it yourself!

    You can fabricate the circuit on any general purpose PCB or breadboard. The schematic and the

    BOM (Bill of Material is given below). To save you from lots of trouble we have made a quality PCB of

    the same! If youpurchasethe PCB, you just need to solder different components at their proper placeon the PCB and you are ready to go.

    Burn the HEX file (given at the end of article) to the ATmega8 MCU using anysuitable

    programmerand plug it into the 28 PIN IC Socket.

    After assembling the circuit power it on using a 12V 500ma Center Positive DC Wall adaptor (you can

    use one that is used for mini TVs or Game Consols or Your DSL Modem). Adjust the variable resistor

    RV1 (just below the LCD module, on the left side, yes the blue thing!) until the LCD Shows some text.

    Schematic for ATmega8 based Smart Code Lock

    Fig.: Complete Schematic (Click to Enlarge/Print)

    Bill of Materials (BOM)Part List

    01 330 ohm resistor (2 Nos) R3, R5

    02 4k7 Resistor (3 Nos) R2, R4, R6

    http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avrprojects/Images/codelock_schematic.gifhttp://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841
  • 8/10/2019 Code Lock Extreme Electronic

    5/19

    03 200 Ohm Resistor R1

    04 0.1uF Ceramic Disk Capacitor (4 Nos) C1, C3, C4, C5

    05 1N4007 Diode (2 Nos) D1, D3

    06LED

    5mmAny ColourD4

    07 ATmega8L-8PUGeneral purpose 8 bit MCU U1

    087805

    Voltage RegulatorU2

    09 Power Connector 2 Way CON1

    10 PCB Mountable Relay RL1

    11 On/Off Switch SW1

    12 DC Socket X1

    13 162 LCD Module LCD1

    14 10K Preset (Blue Plastic POT) RV1

    15 28 PIN Narrow IC Socket

    16 BC548 Transistor(2 Units) Q1, Q2

    17 Push Buttons (16 Units)

    18 ATmega8 Based Smart Code Lock PCB

    Firmware Source Code

    The firmware source code is written in a professional was that may seems confusing to a n00b

    programmer. The thing is that every piece of related functions are stored in a separate source files.

    That means the the project is composed of several C source file. Each C file has set of related

    functions (like LCD Interfacing Routines or EEPROM Access). You must use AVR Studio as a project

    manager and WinAVR as compiler. Both the software must be installed in your PC. In the project

    folder their is a file with name "code_lock.aps" , this is the main AVR Studio Project file. Load it in

    AVR Studio. You can see the various files that are part of the project in the left hand pane as shown

    below. Double click any file to load in the editor. After a file has been loaded in editor you can view

    and change it.

    http://shop.extremeelectronics.co.in/product_info.php?cPath=24_41&products_id=91http://shop.extremeelectronics.co.in/product_info.php?cPath=24_41&products_id=91http://shop.extremeelectronics.co.in/product_info.php?cPath=24_41&products_id=91http://shop.extremeelectronics.co.in/product_info.php?cPath=22&products_id=29http://shop.extremeelectronics.co.in/product_info.php?cPath=22&products_id=29http://shop.extremeelectronics.co.in/product_info.php?cPath=24_29&products_id=45http://shop.extremeelectronics.co.in/product_info.php?cPath=24_29&products_id=45http://shop.extremeelectronics.co.in/product_info.php?cPath=24_29&products_id=45http://shop.extremeelectronics.co.in/product_info.php?cPath=24_28&products_id=59http://shop.extremeelectronics.co.in/product_info.php?cPath=24_32&products_id=56http://shop.extremeelectronics.co.in/product_info.php?cPath=24_32&products_id=56http://shop.extremeelectronics.co.in/product_info.php?cPath=24_33&products_id=89http://shop.extremeelectronics.co.in/product_info.php?cPath=24_33&products_id=89http://shop.extremeelectronics.co.in/product_info.php?cPath=24_28&products_id=85http://shop.extremeelectronics.co.in/product_info.php?cPath=25&products_id=32http://shop.extremeelectronics.co.in/product_info.php?cPath=25&products_id=32http://shop.extremeelectronics.co.in/product_info.php?cPath=24_33&products_id=57http://shop.extremeelectronics.co.in/product_info.php?cPath=24_33&products_id=57http://shop.extremeelectronics.co.in/product_info.php?cPath=24_33&products_id=57http://shop.extremeelectronics.co.in/product_info.php?cPath=25&products_id=32http://shop.extremeelectronics.co.in/product_info.php?cPath=24_28&products_id=85http://shop.extremeelectronics.co.in/product_info.php?cPath=24_33&products_id=89http://shop.extremeelectronics.co.in/product_info.php?cPath=24_32&products_id=56http://shop.extremeelectronics.co.in/product_info.php?cPath=24_28&products_id=59http://shop.extremeelectronics.co.in/product_info.php?cPath=24_29&products_id=45http://shop.extremeelectronics.co.in/product_info.php?cPath=24_29&products_id=45http://shop.extremeelectronics.co.in/product_info.php?cPath=22&products_id=29http://shop.extremeelectronics.co.in/product_info.php?cPath=24_41&products_id=91http://shop.extremeelectronics.co.in/product_info.php?cPath=24_41&products_id=91
  • 8/10/2019 Code Lock Extreme Electronic

    6/19

    Fig.: AVR Studio Main Window

    The highest level file which contains the main application logic is "code_lock.c". This file containsthe main()function. The rest files are lower level files that provide service to the higher level files. If

    you want to customize the firmware you can easily do so by editing the file "code_lock.c", in most

    cases you do not have to touch the other C files.

    Building the Binary from the source code.

    You need to convert the high level human readable source code into machine language so that the

    AVR chip can execute it. The complete process of this conversion is called "Building" (yes,

    compilation is one of the steps of building). After build is complete you get a file called

    "code_lock.hex" which is placed inside a folder called "default" inside the project folder. You just needto program this hex file to the ATmega8 MCU using anysuitable programmer.

    http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/http://extremeelectronics.co.in/avr-tutorials/gui-software-for-usbasp-based-usb-avr-programmers/
  • 8/10/2019 Code Lock Extreme Electronic

    7/19

    Fig.: AVR Studio Build Button

    You can build the project using the "Build Active Configuration"button as shown above. You can

    also hit F7 button or Select Bui ld from Bui ld Menu.

    The Fuse bits must be set as follows. Consult your programmer software for more info.

    HIGH=D9

    LOW=E1

    Please note that the above is default for ATmega8, so if you purchased a new chip then you do

    not need to change them.

    If you are new to AVR Studio and WinAVR Please read the following article carefully.

    Hello World Project with AVR Studio and WinAVR.

    http://extremeelectronics.co.in/avr-tutorials/part-iv-the-hello-world-project/http://extremeelectronics.co.in/avr-tutorials/part-iv-the-hello-world-project/http://extremeelectronics.co.in/avr-tutorials/part-iv-the-hello-world-project/
  • 8/10/2019 Code Lock Extreme Electronic

    8/19

    avr-gcc program for Code Lock

    /**********************************************************************

    ********

    Title:

    ATmega8 Based Smart Code Lock.

    Description:

    A simple project for making a digital code lock. The main input

    device is

    a 4x4 Matrix Keypad. The main output is a 16x2 LCD Module.

    The user has to enter a correct password to gain access. On receipt

    of

    correct password the relay is energized, which can be used to

    operate

    and device like an electronic door.

    Their is facility for changing password.

    For More information visit

    http://www.eXtremeElectronics.co.in

    Author:

    Mandeep Tiwary under supervision of Avinash Gupta.

  • 8/10/2019 Code Lock Extreme Electronic

    9/19

    [email protected]

    [email protected]

    Copyright:

    eXtreme Electronics, India 2008- 2011

    Notice:

    No part of this work can be copied or published in electronic or

    printed form without proper permission from the Original Creators.

    ONLY INTENDED FOR EDUCATIONAL, HOBBY AND PERSONAL USE.

    COMMERCIAL USE IS STRICTLY PROHIBITED.

    Disclaimer of Warranty.

    THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY

    APPLICABLE LAW.

    EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR

    OTHER

    PARTIES PROVIDE THE PROGRAM AS IS WITHOUT WARRANTY OF ANY KIND,

    EITHER

    EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

    WARRANTIES

    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

    THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS

    WITH YOU.

    SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL

    NECESSARY

    SERVICING, REPAIR OR CORRECTION.

  • 8/10/2019 Code Lock Extreme Electronic

    10/19

    ***********************************************************************

    *******/

    #include

    #include

    #include

    #include "lcd.h"

    #include "keypad.h"

    #include "user_interface.h"

    #include "password_manager.h"

    //LCD Backlight i/o configuration

    #define LCDBL_PORT PORB

    #define LCDBL_DDR DDRB

    #define LCDBL_PIN PB1

    //Output relay i/o configuration

    #define RELAY_PORT PORTC

    #define RELAY_DDR DDRC

    #define RELAY_PIN PC0

    //Simple Delay Function

    voidWait(uint8_t n);

    //Relay Control Functions

    voidRelayOn();

  • 8/10/2019 Code Lock Extreme Electronic

    11/19

    voidRelayOff();

    //System Functions

    voidSystemInit();

    voidmain()

    {

    uint16_t password;

    //Initialize the system

    SystemInit();

    while(1)

    {

    password=InputNumber("Enter Password");

    //Match Password

    if(password==ReadPassFromEEPROM())

    {

    LCDClear();

    LCDWriteString("Access Granted");

    //Now Activate Relay

    RelayOn();

    Wait(15);

    LCDClear();

  • 8/10/2019 Code Lock Extreme Electronic

    12/19

    LCDWriteString("Press Any Key");

    //Now wait for any key

    while(GetKeyPressed()==255)

    {

    _delay_loop_2(10);

    }

    //Now DeActivate Relay

    RelayOff();

    Wait(2);

    }

    else if(password==0)

    {

    /*

    If user enters 0000 as password it

    indicates a request to change password

    */

    LCDClear();

    password=InputNumber("Old Password");

    if(password==ReadPassFromEEPROM())

    {

    //Allowed to change password

  • 8/10/2019 Code Lock Extreme Electronic

    13/19

    uint16_t NewPassword;

    NewPassword=InputNumber("New Password");

    WritePassToEEPROM(NewPassword);

    LCDClear();

    LCDWriteString("Success !");

    Wait(15);

    }

    else

    {

    //Not Allowed to change password

    LCDClear();

    LCDWriteString("Wrong Password !");

    Wait(15);

    }

    }

    else

    {

    LCDClear();

    LCDWriteString("Access Denied");

    RelayOff();

    Wait(15);

    }

  • 8/10/2019 Code Lock Extreme Electronic

    14/19

    }

    }

    voidSystemInit()

    {

    //Set LCD Backlight Pin as output

    LCDBL_DDR|=(1

  • 8/10/2019 Code Lock Extreme Electronic

    15/19

    WritePassToEEPROM(1234);

    }

    }

    voidWait(uint8_t n)

    {

    uint8_t i;

    for(i=0;i

  • 8/10/2019 Code Lock Extreme Electronic

    16/19

  • 8/10/2019 Code Lock Extreme Electronic

    17/19

    Fig.: Code Lock PCB(PurchaseHere)

    http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841
  • 8/10/2019 Code Lock Extreme Electronic

    18/19

  • 8/10/2019 Code Lock Extreme Electronic

    19/19

    Fig.: Code Lock PCB (PurchaseHere)

    Purchase Kit

    Dont waste time finding each part running from shop to shop. Get all the parts with exact

    specification in a ready to use kit!Purchase ATmega8 based smart code lock KIT.And help us

    create more and more free AVR projects.

    Downloads

    Complete AVR Studio Project (ZIP File)

    Precompiled hex file for burning to ATmega8 MCU

    PCB Layouts in PDF, DOC and PNG Formats.

    http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841http://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841http://store.extremeelectronics.co.in/ATmega8-Based-Smart-Code-Lock-KIT.htmlhttp://store.extremeelectronics.co.in/ATmega8-Based-Smart-Code-Lock-KIT.htmlhttp://store.extremeelectronics.co.in/ATmega8-Based-Smart-Code-Lock-KIT.htmlhttp://extremeelectronics.co.in/avrprojects/Codes/CodeLock/code_lock.ziphttp://extremeelectronics.co.in/avrprojects/Codes/CodeLock/code_lock_hex.ziphttp://extremeelectronics.co.in/avrprojects/Codes/CodeLock/code_lock_hex.ziphttp://extremeelectronics.co.in/avrprojects/Codes/CodeLock/CodeLockPCB.ziphttp://extremeelectronics.co.in/avrprojects/Codes/CodeLock/CodeLockPCB.ziphttp://extremeelectronics.co.in/avrprojects/Codes/CodeLock/CodeLockPCB.ziphttp://extremeelectronics.co.in/avrprojects/Codes/CodeLock/code_lock_hex.ziphttp://extremeelectronics.co.in/avrprojects/Codes/CodeLock/code_lock.ziphttp://store.extremeelectronics.co.in/ATmega8-Based-Smart-Code-Lock-KIT.htmlhttp://shop.extremeelectronics.co.in/product_info.php?cPath=50&products_id=841