Sei sulla pagina 1di 39

AN INDUSTRY ORIENTED MINI PROJECT

on

DIGITAL CODE LOCKING SYSTEM USING


ARDUINO UNO
Submitted in partial fulfillment of the requirements
for the award of the degree of

BACHELOR OF TECHNOLOGY
In
Electronics & Communication Engineering
By

CH.SAI PRAVEEN KUMAR

(11891A0406)

CH. PRAVEEN

( 11891A0407)

D.SAI VAMSEE MOHAN

(11891A0408)

Under the guidance of

Mr.Vikas Kumar Tiwari


(Assistant Professor)

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING

VIGNAN INSTITUTE OF TECHNOLOGY AND SCIENCE


(Affiliated to Jawaharlal Nehru Technological University)
Vignan Hills, Deshmukhi village, Pochampally Mandal, Nalgonda Dt.
Telangana 508284
08685226625
08685226600

2011-15

AN INDUSTRY ORIENTED MINI PROJECT


on

DIGITAL CODE LOCKING SYSTEM USING


ARDUINO UNO
Submitted in partial fulfillment of the requirements
for the award of the degree of

BACHELOR OF TECHNOLOGY
In
Electronics & Communication Engineering
By

CH.SAI PRAVEEN KUMAR

(11891A0406)

CH. PRAVEEN

( 11891A0407)

D.SAI VAMSEE MOHAN

(11891A0408)

Under the guidance of

Mr.Vikas kumar Tiwari


(Assistant Professor)

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING

VIGNAN INSTITUTE OF TECHNOLOGY AND SCIENCE


(Affiliated to Jawaharlal Nehru Technological University)
Vignan Hills, Deshmukhi village, Pochampally Mandal, Nalgonda Dt.
Telangana 508284
08685226625
08685226600

2011-15

DECLARATION

We hereby declare that project entitled Digital Code Locking System Using
Arduino Uno is bonafide work duly completed by me/us. It does not contain any part
of the project or thesis submitted by any other candidate to this or any other institute
of the university.
All such materials that have been obtained from other sources have been duly
acknowledged.
CH.SAIPRAVEEN KUMAR
(Regd No.11891A0406 )

CH.PRAVEEN
(Regd No.11891A0407)

D.SAI VAMSEE MOHAN


(Regd No.11891A0408)

VIGNAN INSTITUTE OF TECHNOLOGY AND SCIENCE


DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

CERTIFICATE
This is to certify that the thesis work titled Digital Code Locking System Using Arduino
Uno submitted by CH.SAI PRAVEEN KUMAR(11891A0406), CH.PRAVEEN
(11891A0407),D.SAI VAMSE MOHAN(11891A0408) in partial fulfillment of the
requirements for the award of the degree of Bachelor of Technology in Electronics &
Communication Engineering to the Vignan Institute Of Technology And Science,
Deshmukhi is a record of bonafide work carried out by him/her under my guidance and
supervision.
The results embodied in this project report have not been submitted in any university
for the award of any degree and the results are achieved satisfactorily.

Mr. Dinesh Kumar

Guide: Mr. Vikas kumar Tiwari

(Head of The Department)

(Assistant Professor)

(External Examinar)

ACKNOWLEDGEMENT
We would like to extend our deepest gratitude to our CEO Mr. Shravan Boyapati and
principle Dr M.Venkata Ramana for his patronage and encouragement.
We also take this opportunity to express our heartfelt thanks to the Head of Department
Mr.N.Dinesh Kumar for his valuable insights and support.
This project has been a great learning experience for our team members for we found
the work very challenging and interesting ,and we experienced as much joy in seeing it
to completion as we had during the design stages.
It goes with out saying that the project would not have seen the light of the day
without the constant guidance and technical knowhow provided by our guide/mentor
Mr.Vikas Kumar Tiwari(Assistant Professor ECE Dept). His willingness to motivate
us contributed tremendously to our project.
Finally we would like to thank the lab authorities and other faculty for obliging us with
their help and guidance whenever sought

ABSTARCT
Security is a prime concern in our daily life. Everyone wants to be as much secure
as possible. So people are using many methods to protect their houses, properties etc.
This project uses a arduino based digital locking system. Here an Arduino
Uno(ATmega328) 16x2 LCD display ,a 4x4 matrix KEYPAD are used. When the
password is entered through the keypad if the password is matched with the stored
password then it gets displayed in lcd saying UNLOCKED .If the passwords do not
match then it displays WRONG PASSWORD AND LOCKED.
Here we use an Arduino Uno (ATmega328) which has 32kb flash memory. It
stores the program which we write & it is erasable i.e whenever we want to set a new
code we can reprogram it. There is keypad through which we can enter the security
code (password). There is an lcd to display the password which we enter.

TABLE OF CONTENTS
Topic

Page no.

Acknowledgement..

Abstract..

ii

Table of contents

iii

List of figures

iv

1. Introduction..

1.1 Overview

1.2 Required components.. .

2. Literature and Survey.

3. Block Diagram.

3.1 Introduction on ARDUINO UNO ..

3.2 ARDUINO UNO.

3.3 Pin diagram of ATmega328....

11

3.4 LCD.

12

3.5 KEYPAD.

13

4. Flow chart..

15

5. Hardware Implementation..

17

5.1 Interfacing LCD with Arduino.

17

5.2 Interfacing Keypad with Arduino.

18

5.3 Digital Code Lock Using Arduino Uno

19

6. Results and Discussions

20

7. Conclusion and Future scope.

21

7.1 Advantages.

21

7.2 Disadvantages... 22
7

7.3 Applications.. 23
8. Biblography. 24
9. Appendix. 25

LIST OF FIGURES
3.1 BLOCK DIAGRAM. 4
3.2 ARDUINO BOARD.. 6
3.3 PinDiagram of ATmega328.. 11
3.4 Pin Diagram of LCD. 12
3.5 4x4 Matrix Keypad 13
5.1 Interfacing LCD to Arduino 17
5.2 Interfacing 4x4 matrix Keypad to Arduino. 18
5.3 Digital Code Lock Using Arduino.. 19

1. INTRODUCTION
1.1 OVERVIEW:
objective:
Security is a prime concern in our day-today life. Everyone wants to be as much
secure as possible. An access control for doors forms a vital link in a security chain.
The Arduino based digital lock for Doors is an access control system that allows only
authorized persons to access a restricted area. The system is fully controlled by the
ATmega328 microcontroller which 32kb of flash memory . When the entered password
equals with the password stored in the memory then it displays UNLOCKED on the
lcd display.
Digital Security' gives individuals the freedom to embrace the digital lifestyle
confidently engage in everyday interactions across all digital devices. According to
Olivier Piou, CEO of global digital security company .Gemalto, digital security has
a key role to play in the digital revolution. Yet fear of fraud, identity theft, and other
concerns are holding people back from making the most of (what the digital revolution
has to offer). They need to feel that the wealth of devices and services available are
both convenient to use and trustworthy. "Digital security affects all aspects of the digital
lifestyle,

which,

among

others,

comprises

computers

and

the

internet,

telecommunications, financial transactions, transportation, healthcare and secure


access.
When considering the security measures that are typically installed within homes
and properties, they often are systems that are not effective and not of much use. With
9

the number of contemptible acts like robberies, ransacking and vandalism, the absence
of competent security solutions is an open invitation to trouble. Digital cameras are
extremely useful devices that ensure the safety of your property when you are away at
work on or vacation. With technological advancements you can now implement strong
measures to keep trouble makers away
We have seen the security personnel checking the employees identification cards at
the entrances to avoid illegal entry. The employees sign a register at the entrance before
getting in. This is still being practiced in most of the companies. However, the
disadvantages are that, when there is a necessity of providing control at many locations
inside the company, a person at each point will not be an economical way of
implementing it.
Then came were the punch cards. Employees possess cards, which are punched
when they enter into the building. But it had disadvantages. Workers started to practice
buddy punching, for their co-workers.
Although these techniques are good ,they are time consuming and costly ,so instead of
these we are using a digital lock which has security code so as to prevent the
unauthorized to access. Here we are using Arduino Uno which uses an
ATmega328microcontroller.This microcontroller checks the password 5 digit password
entered then it grants access shown in the lcd display

1.2 REQUIRED COMPONENTS :

Arduino Uno R3

4x4 Matrix Keypad

16x2 LCD Display

Jumper wires

10

2.LITERATURE SURVEY
To underline the work done in this project and to establish acquaintance with the
subject, it is necessary to study the history of the problem statement being investigated
by summarizing aspects of the work that has been done in this regard, both in the past
as well as that which is being pursued now.

Design and Implementation of a Digital Code Lock Annie P. Oommen1,


Rahul A P, Pranav V, Ponni S, Renjith Nadeshan International Journal of
Advanced Research in Electrical,Electronics and Instrumentation
Engineering(An ISO 3297: 2007 Certified Organization) Vol. 3, Issue 2,
February 2014

Development of a Programmable Electronic Digital Code lock system Oke


Alic O.*, Adigun Adebisi A., Falohun Adeleye S., and Alamu F. O.
International Journal of Computer and Information Technology (ISSN: 2279
0764) Volume 02 Issue 01, January 2013

11

3. BLOCK DIAGRAM

4x4 MATRIX

INCOMING
CODE

KEYPAD
POWER SUPPLY

ARDUINO UNO
(ATmega328)

(16X2)LCD DISPLAY

12

3.1 BLOCK DIAGRAM

3.1 INTRODUCTION ON ARDUINO UNO


About Arduino :
Arduino is an open source computer hardware and software company, project and
user community that designs and manufactures kits for building digital devices and
interactive objects that can sense and control the physical world.
The project is based on a family of microcontroller board designs manufactured
primarily by Smart Projects in Italy, and also by several other vendors, using various
8-bit Atmel, AVR microcontrollers or 32-bit Atmel ARM processors. These systems
provide sets of digital and analog I/O pins that can be interfaced to various extension
boards and other circuits. The boards feature serial communications interfaces,
including USB on some models, for loading programs from personal computers. For
programming the microcontrollers, the Arduino platform provides an Integrated
Development Environment (IDE) based on the Processing project, which includes
support for C and C++ programming languages.

13

3.2 ARDUINO UNO:


The Arduino Uno is a microcontroller board based on the ATmega328. It has 14
digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a
16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a
reset button. It contains everything needed to support the microcontroller; simply
connect it to a computer with a USB cable or power it with a AC-to-DC adapter or
battery to get started.

3.2 Arduino Uno board

14

Power:
The Arduino Uno can be powered via the USB connection or with an external power
supply. The power source is selected automatically External (non-USB) power can
come either from an AC-to-DC adapter (wall-wart) or battery. The adapter can be
connected by plugging a 2.1mm center-positive plug into the board's power jack. Leads
from a battery can be inserted in the Gnd and Vin pin headers of the POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less
than 7V, however, the 5V pin may supply less than five volts and the board may be
unstable. If using more than 12V, the voltage regulator may overheat and damage the
board. The recommended range is 7 to 12 volts.
The power pins are as follows:

VIN : The input voltage to the Arduino board when it's using an external power
source (as opposed to 5 volts from the USB connection or other regulated power
source). You can supply voltage through this pin, or, if supplying voltage via
the power jack, access it through this pin.
5V: This pin outputs a regulated 5V from the regulator on the board. The board
can be supplied with power either from the DC power jack (7 - 12V), the USB
connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the
5V or 3.3V pins bypasses the regulator, and can damage your board. We don't
advise it.

3.3V: A 3.3 volt supply generated by the on-board regulator. Maximum current
draw is 50 mA.

GND. Ground pins.

IOREF. This pin on the Arduino board provides the voltage reference with
which the microcontroller operates. A properly configured shield can read the
IOREF pin voltage and select the appropriate power source or enable voltage
translators on the outputs for working with the 5V or 3.3V.

Memory:

15

The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of
SRAM and 1 KB of EEPROM (which can be read and written with the EEPROM
library).
Input and Output pins:
Each of the 14 digital pins on the Uno can be used as an input or output,
using pinmode() ,digital write(), and digital read()functions. They operate at 5 volts.
Each pin can provide or receive a maximum of 40 mA and has an internal pull-up
resistor (disconnected by default) of 20-50 kOhms. In addition, some pins have
specialized functions:

Serial: 0 (RX) and 1 (TX): Used to receive (RX) and transmit (TX) TTL serial data.
These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL
Serial chip.

External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a


low value, a rising or falling edge, or a change in value.

PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analog Write
() function.

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI


communication using the SPI library.

LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH
value, the LED is on, when the pin is LOW, it's off.

The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of
resolution (i.e. 1024 different values). By default they measure from ground to 5
volts, though is it possible to change the upper end of their range using the AREF pin
and the analogReference() function. Additionally, some pins have specialized
functionality:

TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using
the Wire Library. There are a couple of other pins on the board:

AREF. Reference voltage for the analog inputs. Used with analogRefernce
()Reset. Bring this line LOW to reset the microcontroller. Typically used to add a
reset button to shields which block the one on the board.

16

Communication:
The Arduino Uno has a number of facilities for communicating with a computer,
another Arduino, or other microcontrollers. The ATmega328 provides UART TTL
(5V) serial communication, which is available on digital pins 0 (RX) and 1 (TX).
An ATmega16U2 on the board channels this serial communication over USB and
appears as a virtual com port to software on the computer. The '16U2 firmware uses the
standard USB COM drivers, and no external driver is needed. However on windows a
.inf file is required. The Arduino software includes a serial monitor which allows simple
textual data to be sent to and from the Arduino board. The RX and TX LEDs on the
board will flash when data is being transmitted via the USB-to-serial chip and USB
connection to the computer (but not for serial communication on pins 0 and 1).
A Software Serial library allows for serial communication on any of the Uno's digital
pins.

The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino
software includes a Wire library to simplify use of the I2C bus; see
the documentation for details. For SPI communication, use the SPI library.
Programming
The Arduino Uno can be programmed with the Arduino software. Select "Arduino
Uno from the Tools > Board menu (according to the microcontroller on your board).
The ATmega328 on the Arduino Uno comes preburned with a boot loader that allows
you to upload new code to it without the use of an external hardware programmer. It
communicates using the original STK500 protocol (reference, C header files).We can
also bypass the boot loader and program the microcontroller through the ICSP (InCircuit

Serial

Programming)

header

using

Arduino

ISP

or

similar.

The ATmega16U2 (or 8U2 in the rev1 and rev2 boards) firmware source code is
available .The ATmega16U2/8U2 is loaded with a DFU bootloader, which can be
activated by:

On Rev1 boards: connecting the solder jumper on the back of the board (near the map
of Italy) and then resetting the 8U2.
17

On Rev2 or later boards: there is a resistor that pulling the 8U2/16U2 HWB line to
ground, making it easier to put into DFU mode.

You can then use Atmels FLIP

software (Windows) or the DFU programmer (Mac OS X and Linux) to load a new
firmware. Or you can use the ISP header with an external programmer (overwriting the
DFU boot loader).
Automatic (Software) Reset: Rather than requiring a physical press of the reset
button before an upload, the Arduino Uno is designed in a way that allows it to be
reset by software running on a connected computer. One of the hardware flow control
lines (DTR) of theATmega8U2/16U2 is connected to the reset line of
the ATmega328 via a 100 nano farad capacitor. When this line is asserted (taken low),
the reset line drops long enough to reset the chip. The Arduino software uses this
capability to allow you to upload code by simply pressing the upload button in the
Arduino environment. This means that the bootloader can have a shorter timeout, as
the lowering of DTR can be well-coordinated with the start of the upload.
This setup has other implications. When the Uno is connected to either a computer
running Mac OS X or Linux, it resets each time a connection is made to it from software
(via USB). For the following half-second or so, the bootloader is running on the Uno.
While it is programmed to ignore malformed data (i.e. anything besides an upload of
new code), it will intercept the first few bytes of data sent to the board after a connection
is opened. If a sketch running on the board receives one-time configuration or other
data when it first starts, make sure that the software with which it communicates waits
a second after opening the connection and before sending this data.
The Uno contains a trace that can be cut to disable the auto-reset. The pads on either
side of the trace can be soldered together to re-enable it. It's labeled "RESET-EN". You
may also be able to disable the auto-reset by connecting a 110 ohm resistor from 5V to
the reset line;
USB Overcurrent Protection
The Arduino Uno has a resettable polyfuse that protects your computer's USB ports
from shorts and overcurrent. Although most computers provide their own internal
protection, the fuse provides an extra layer of protection. If more than 500 mA is applied
18

to the USB port, the fuse will automatically break the connection until the short or
overload is removed.
Physical Characteristics
The maximum length and width of the Uno PCB are 2.7 and 2.1 inches respectively,
with the USB connector and power jack extending beyond the former dimension. Four
screw holes allow the board to be attached to a surface or case. Note that the distance
between digital pins 7 and 8 is 160 mil (0.16"), not an even multiple of the 100 mil
spacing of the other pins.

Microcontroller used in Arduino uno is ATmega328.


3.3 PIN DIAGRAM OF ATMEGA328:

3.3 Pin Diagram of ATmega328

Features of ATmega328:

8-Bit Microcontroller

is a low-power CMOS 8-bit microcontroller

Advanced RISC Architecture

32 x 8 General Purpose Working Registers

32K Bytes of In-System Self-Programmable Flash progam memory


19

1K Bytes EEPROM

2K Bytes Internal SRAM

Write/Erase Cycles: 10,000 Flash/100,000 EEPROM

Operating Voltage 1.8 - 5.5V for ATmega328

Clock speed -20MHz

On-chip Analog Comparator

Two 8-bit Timer/Counters

One 16-bit Timer/Counter

Temperature range : -40C to 85C

3.4 LCD
LCD DISPLAY (16x2):
The dot-matrix liquid crystal display controller and driver LSI displays
alphanumeric, characters, and symbols. It can be configured to drive a dotmatrix liquid crystal display under the control of a 4 or 8-bit microprocessor.
Since all the functions such as display RAM, character generator, and liquid
crystal driver, required for driving a dot-matrix liquid crystal display are
internally provided on one chip, a minimal system can be interfaced with this
controller/driver. A single HD44780U can display up to two 8-character lines
(16 x 2).
A 16 x 2 line LCD module is used to display user information.Generally
the lcd can br connected to the Arduino or any microcontroller in two ways.

3.4 Pin diagram of 16x2 LCD


20

VLED-

VLED+

DB7

DB6

DB5

DB4

R/W

DB3

RS

DB2

VEE

DB1

VCC

DB 0

VSS

ENABLE

LCD(16x2)

The first way of connecting the LCD is by using only 4 data pins of the lcd .By using
only 4 data pins we can transmit the data from the microcontroller to the lcd i.e the
message or text which we want to display. The second method is by using all the 8 data
pins provided and connecting them to the microcontroller.

3.5 KEYPAD(4X4 matrix keypad):

C1 - C4

R1-R4

3.5 4x4 matrix Keypad


The keypad which is used here is a 4x4 matrix keypad which has 4 rows and 4
columns. We require 8 pins of the keypad are to be connected to the 8 pins of the
arduino uno board.

21

The internal arrangement of the keypad is shown below which is nothing but the
interconnection of switches.

3.6 nterconnection of switches inside the keypad

There are many methods depending on how you connect your keypad with your
controller, but the basic logic is same. We make the coloums as i/p and we drive the
rows making them o/p, this whole procedure of reading the keyboard is called scanning.
In order to detect which key is pressed from the matrix, we make row lines low one
by one and read the columns. Let us say we first make Row1 low, then read the
columns. If any of the key in row1 is pressed will make the corresponding column as
low i.e if second key is pressed in Row1, then column2 will give low. So we come to
know that key 2 of Row1 is pressed. This is how scanning is done. So to scan the keypad
completely, we need to make rows low one by one and read the columns. If any of the
button is pressed in a row, it will take the corresponding column to a low state which
tells us that a key is pressed in that row. If button 1 of a row is pressed then Column 1
will become low, if button 2 then column2 and so on

22

4. FLOWCHART

START

Interface keypad and lcd to the


Arduino

Initialization of LCD:
4 bt & 2line display

Display on and cursor Blinking


DISPLAY:UNLOCKED
Display on
and cursor Blinking

Clear display screen

23

Enter the password through


the keypad

Display on LCD

Check the
password

equal

DISPLAY:UNLOCKED

STOP

24

Not equal
Display :WRONG
PASSWORD AND
LOCKED

5. HARDWARE IMPLEMENTATION
5.1 INTERFACING LCD WITH ARDUINO :
In our project we are connecting the lcd display in the 4bit mode i.e we are using
only 4 data pins (DB4,DB5,DB6,DB7) to transmit the information from the controller
to the lcd. The rest of the data pins are not given any connection.
Apart from this we connect the VSS pin to GND, VDD pin to 5v power supply on
the arduino board ,RS pin to digital pin 12 on the arduino board, ENABLE pin to the
digital pin 11on the arduino board and the data pins DB4,DB5,DB6,DB7 to the digital
pins 5,4,3,2 on the arduino respectively.

Circuit diagram:

Fig 5.1 Interfacing 16x2 LCD to Arduino

25

5.2 INTERFACING 4x4 KEYPAD WITH ARDUINO:


Here the 4x4 keypad is connected to the Arduino with the help of 8 male-male
jumper wires. The ROWs(R1-R4)are connected to the A1,A0,8,9 pins of the Arduino
and the COLs(C1-C4) are connected to 10,11,12,13 digital pins of the arduino.
It is shown in the below circuit diagram

Fig 5.2 Interfacing Keypad to


Arduino

Initally all the columns are made high(input),and all the rows are
madelow(output),whenever a key is pressed the corresponding row and column
becomes low thus a keypress is detected.

26

5.3 DIGITAL CODE LOCK USING ARDUINO UNO :

Fig 5.3 Digital Code Lock Using Arduino

27

6. RESULTS AND DISCUSSIONS

6.1 INTRODUCTION
After the complete system design is completed, the hardware and software is tested for any
connection errors. Once it is clear that the connections are all fine the project working is
tested. Then the Arduino board is powered from the board we can power the lcd so there is no
need of external power supply for LCD

6.2 OBSERVATIONS AND RESULTS


The LCD displays the message Set 5 Digit Password as soon as it is powered and the
password is enterd through the keypad.When we press A it checks whether the
password entered is matching with the stored password and displays the message
accordingly .When ever wrong password is entered then it displays wrong password
and locked.

28

7. CONCLUSION AND FUTURE SCOPE


7.1 ADVANTAGE:
Use of RFID technology can increase business productivity and reduce associated costs.
To ensure that companies benefit from the advantages RFID provides it is important to
understand how to adopt this technology. By analyzing current practices and procedures
eight main areas of benefit can be identified. These are:
Improved Productivity and Cost Avoidance.
Decreased Cycle Time and Taking Costs Out.
Reduced Rework.
Reduced Business Risk & Control of Assets.
Improved Security and Service.
Improved Utilization of Resources.
Increased Revenues.
Exception Management.

7.2 DISADVANTAGE:
The disadvantages are that, when there is a necessity of providing control at many
locations inside the company, a person at each point will not be an economical way of
implementing it.
Then came were the punch cards. Employees possess cards, which are punched
when they enter into the building. But it had disadvantages. Workers started to practice
buddy punching, for their co-workers.

29

7.3 APPLICATIONS:
The term access control refers to the practice of restricting entrance to a
property, a building or a room to authorized persons. Integrated and controller
based access control numeric and alphabetic keyless entry keypads with
programmable features for the access control of single openings. The various
applications are as follows.
Industrial facilities
Commercial buildings
Airports, civil transportation
Convention halls
Psychiatric care centres
Museums and fine art galleries
Ware houses
Technology centres
Government and military
Long term care facilities
Drug rehabilitation centres

30

BIBILOGRAPHY
REFERENCE BOOKS

Programming in C++ : E.BALAGURU SWAMY

WEBSITES:
http://arduino.cc/en/Tutorial/LiquidCrystal
http://playground.arduino.cc/Code/Library
http://www.instructables.com/id/password-Lock-with-Arduino
http://www.circuitstoday.com/digital-code-lock-using-arduino

31

APPENDIX
CODE FOR DIGITAL CODE LOCK USING ARDUINO :
#include<LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
int row[]={A1,A0,8,9};// Defining row pins of keypad connected to Arduino pins
int col[]={10,11,12,13};//Defining column pins of keypad connected to Arduino
int i,j,lcd_count,count=1,key_id=0,flag,entry=0;// See About the Program
int col_scan;// Variable to identify a key press
char temp_press; // Variable to hold value of key press
char check[6],pass[6]; // See About the Program

void setup()
{
lcd.begin(16,2);
for(i=0;i<=3;i++)
{
pinMode(row[i],OUTPUT);
pinMode(col[i],INPUT);
digitalWrite(col[i],HIGH);
}
lcd.print("SET 5 Digit PASS");
}

/* Main Program Begins */

void loop()
{
while(entry<=4)// Password Setting Loop begins
{
32

SetPassword();
}
// Password Setting Loop Ends

key_id=0;
keyscan(); // Scan for a Key Press

/* Actions on Key Press begins */

if(key_id==1) // Condition to Check Key is Pressed


{
check[count]=temp_press;
count++;

/* Condition to Unlock Begins*/

if(temp_press=='A')
{
checkPassword();
if(flag==0)
{
lcd.setCursor(0,0);
lcd.print("UNLOCKED");

}else{
lcd.setCursor(0,0);
lcd.print("WRONG PASSWORD");
delay(200);
lcd.clear();
lcd.print("LOCKED");
}
33

count=1; // Resetting the counter variable


}

/* Condition to Unlock Ends*/

/* Condition to Change Password Begins */

else if(temp_press=='C')
{
checkPassword();
if(flag==0)
{
lcd.setCursor(0,0);
lcd.print("ENTER NEW PASS");
key_id=0;
entry=0;
}else{
lcd.setCursor(0,0);
lcd.print("WRONG PASSWORD");
}
count=1; // Resetting the counter variable
}

/* Condition to Change Password Ends */

/* Condition to LOCK Begins*/

else if(temp_press=='B')
{
lcd.setCursor(0,0);
lcd.print("LOCKED");
34

count=1; // Resetting the counter variable


}
/* Condition to LOCK Ends*/
}

/* Actions on Key Press Ends*/


}

/* Main Program Ends */

void SetPassword() // Subroutine to SET User Defined Password


{
keyscan();
if(key_id==1)
{
if(temp_press=='A'||temp_press=='C'||temp_press=='B') // Condition to Check for an
Invalid Keypress
{
lcd.setCursor(0,0);
lcd.print("INVALID KEYS");
entry=0;
}
else

{
pass[entry]=temp_press;

}
}
key_id=0;

35

if(entry==5)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PASSWORD SET & LOCKED");
}} // Subroutine to SET Password ENDS

char keyscan()// Subroutine to Scan Keypad for a Keypress


{
for(i=0; i<=3; i++)
{
digitalWrite(row[0],HIGH);
digitalWrite(row[1],HIGH);
digitalWrite(row[2],HIGH);
digitalWrite(row[3],HIGH);
digitalWrite(row[i],LOW);
for(j=0; j<=3; j++)
{
col_scan=digitalRead(col[j]);
if(col_scan==LOW)
{
key_id=1;
entry++;
temp_press=keypress(i,j);
lcd.setCursor(lcd_count++,1);
lcd.print(temp_press);
if(temp_press=='A'||temp_press=='C'||temp_press=='B')
{
lcd_count=0;
lcd.clear();
}
36

delay(300);
break;
}}
}}// Subroutine to Scan Keypress Ends

char keypress(int i, int j) // Subroutine to Identify the value of Key pressed


{
if(i==0&&j==0)
{
return('1');
}
if(i==0&&j==1)
{
return('2');
}
if(i==0&&j==2)
{
return('3');
}
if(i==0&&j==3)
{
return('A');
}
if(i==1&&j==0)
{
return('4');
}
if(i==1&&j==1)
{
return('5');
}
37

if(i==1&&j==2)
{
return('6');
}
if(i==1&&j==3)
{
return('B');
}
if(i==2&&j==0)
{
return('7');
}
if(i==2&&j==1)
{
return('8');
}
if(i==2&&j==2)
{
return('9');
}
if(i==2&&j==3)
{
return('C');
}
if(i==3&&j==0)
{
return('*');
}
if(i==3&&j==1)
{
return('0');
38

}
if(i==3&&j==2)
{
return('#');
}
if(i==3&&j==3)
{
return('D');
}
} // Subroutine to identify Keypress Ends

void checkPassword() // Subroutine to Check User Input Data with SET Password
{
flag=0;
for(i=1;i<=5&&flag==0;i++)
{
if(check[i]==pass[i])
{
flag=0;
}
else
{flag=1;
}}} // Subroutine to check password ends

39

Potrebbero piacerti anche