Anda di halaman 1dari 4

ConstruCtion

PIC mICroController-BAsed
eleCtronIC loCk
rish k.
s.v.n. ha
AnshumAn BezBorAh PIC16F877A microcontroller plays the
role of the processing unit. The MCU

A
n electronic lock allows is interfaced with a 44 matrix keypad
activation of an electric appli- and a 162 LCD to form the user inter- electronic door lock by interfacing the
ance only on entering the cor- face. Using this circuit, you can make output of the circuit with an electrically
rect password. Here we present such any electrical appliance password- actuated door lock. The system turns
an electronic locking system in which a protected. It can also be used as an on the appliance on entering a four-

Fig. 1: Circuit of PIC microcontroller-based electronic lock

digit password set by the user.

Circuit description
Fig. 1 shows the circuit of the PIC mi-
crocontroller-based electronic lock. It
can be divided into five sections: input
(44 matrix keypad), processing unit
(PIC16F877A MCU), appliance control-
ler (relay driver), display (162 LCD),
and power supply.
PIC16F877A MCU. The PIC-
16F877A is an 8-bit microcontroller
based on reduced instruction set com-
Fig. 2: Power supply circuit puter (RISC) architecture. It has 8k14-

w w w. e f y m ag . co m e l e c t ro n i c s f o r yo u J u n e 2 0 1 0 6 9
ConstruCtion
PArts List Relay driver. RC2 pin
Functions of Various Keys of the of Port C of the MCU is
Semiconductors:
IC1 - PIC16F877A microcontroller
Keypad and Their Labeling interfaced with the relay
IC2 - 7805 voltage regulator S.No. Row Column Label Operation/digit entry driver circuit (shown in
IC3 - 7806 voltage regulator
1 1 1 1 Digit 1 Fig. 3) to switch on or
LED1 - 5mm Light-emitting diode
D1 - 1N4148 diode 2 1 2 2 Digit 2 switch off the AC load
D2-D6 - 1N4007 diode 3 1 3 3 Digit 3 (appliance). A relay driver
T1 - SL100 transistor circuit is nothing but a sim-
4 1 4 Nil No operation allotted
Resistors (all -watt, 5% carbon unless stated ple electronic circuit that
otherwise):
5 2 1 4 Digit 4
6 2 2 5 Digit 5 drives an electromechani-
R1-R8, R10 - 4.7-kilo-ohm
R9 - 150-ohm 7 2 3 6 Digit 6 cal relay. In this project,
R11 - 10-kilo-ohm
8 2 4 Lock Lock or turn off
a 6V, single-changeover
R12 - 470-ohm relay is used for switching
the appliance
VR1 - 10-kilo-ohm preset
9 3 1 7 Digit 7 the appliance on or off.
Capacitors:
10 3 2 8 Digit 8 Transistor SL100 plays the
C1 - 1000F, 25V electrolytic
C2, C3 - 0.1F ceramic 11 3 3 9 Digit 9 role of the relay driver.
C4, C5 - 22pF ceramic
12 3 4 New Change the password Whenever the user
Miscellaneous:
13 4 1 C Clear or backspace enters the correct pass-
XTAL - 4MHz crystal oscillator word, RC2 pin goes high
X1 - 230V AC primary to 0-9V, 14 4 2 0 Digit 0
500mA secondary 15 4 3 Go Should be pressed after
(RC2=1). Consequently,
transformer entering the password transistor SL100 is trig-
- HD44780-based 162 LCD 16 4 4 Open Open the lock (asks for gered to energise the relay
RL1 - 6V, 1C/O relay password when pressed) and the appliance turns
S1-S17 - Push-to-on tactile switch
on. When RC2 is low
(RC2=0), the appliance turns off.
bit flash program memory, 368 bytes of Free-wheeling diode 1N4007 pro-
RAM and many other internal periph- tects the relay driver circuit from
erals like analogue-to-digital converter, the reverse voltage developed in
USART, timers, synchronous serial the relay coil.
port, compare captures and pulse- You can also use optocoupler
width modulation modules, EEPROM MCT2E to isolate the relay driver
and analogue comparators. circuit from the microcontroller
The job of the MCU in this project is circuit. Whenever the user enters
to receive signals from the input device the correct password, RC2 pin
(keypad) and take corresponding ac- goes high (RC2=1) and the inter-
tions. Whenever any key is pressed on Fig. 3: Relay driver circuit nal LED of the MCT2E IC glows,
the keypad, the software program in which, in turn, triggers the inter-
the MCU identifies the pressed key and 4 are connected to pins RB4 through nal transistor of MCT2E.
accordingly turns on or turns off the ap- RB7 of Port B, respectively. Power supply. Fig. 2 shows the
pliance. Simultaneously, it also displays 162 LCD. A Hitachi HD44780 power supply circuit. The 230V AC
a message on the LCD screen. 162 LCD is used to display various mains supply is stepped down to 9V
44 matrix keypad. A 44 matrix messages. It also displays an asterisk AC using step-down transformer
keypad is used to give commands and mark (*) for each digit of the password X1. The output from the secondary
the password to the MCU. It consists of entered. Control lines EN, RW and RS of the transformer is rectified by a
16 keys (S2-S17) arranged in the form of the LCD module are connected to bridge rectifier comprising diodes D3
of a square matrix of four rows and pins RA1, RA2 and RA3 of Port A of through D6 and filtered by capacitor
four columns. Each key in the matrix the MCU, respectively. Commands C1. The filtered output is regulated by
is labeled according to the operation and the data to be displayed are sent ICs 7805 and 7806 connected in paral-
assigned to it. The connections from to the LCD module in nibble mode lel to obtain the required 5V and 6V,
the pin-outs of the keypad to the from Port D of the MCU. The higher respectively.
MCU pins are shown in Fig. 1. Rows four data bits of the LCD (D4 through
1 through 4 are connected to pins RB3, D7) are connected to the lower nibble software
RB2, RB1 and RB0 of Port B of the of Port D (RD0 through RD3) of the The software code is written in C
MCU, respectively. Columns 1 through MCU. language and compiled using Hitech C

7 0 J u n e 2 0 1 0 e l e c t ro n i c s f o r yo u w w w. e f y m ag . co m
ConstruCtion

Fig. 4: Actual-size, single-side PCB for the PIC microcontroller-based electronic lock

Fig. 5: Component layout for the PCB

compiler in MPLAB IDE. MPLAB IDE series of MCUs. Its Lite edition comes
is a very powerful software develop- for free with newer versions of MPLAB
ment tool for Microchips MCUs. It can IDE like MPLAB v8.2 or v8.3, and it
be downloaded from www.microchip. can also be downloaded for free from
com free of cost. It consists of tools like www.htsoft.com.
text editor, assembler, cross compliers The tasks performed by the soft-
and simulator. Hitech C compiler is ware are:
meant for Microchips PIC10/12/16 1. Identify the key

w w w. e f y m ag . co m e l e c t ro n i c s f o r yo u J u n e 2 0 1 0 7 1
ConstruCtion
2. Take the action allotted to the EFYs May issue. key. The system should ask for the cur-
identified key The above description is available rent and new passwords. Press Go
The key identification is done by in a file named lock.c. Functions lcd_ each time after you enter the four-digit
identifying the row and the column to init( ), lcd_goto(int), lcd_clear( ) and password. The message Password
which the key belongs. Fig. 1 shows lcd_putch(char) are defined in a file Saved should appear for two seconds,
how the keypad is connected to Port B named lcd.c and the DelayMs(int) followed by the message Welcome.
of the MCU. The lower nibble of Port B function is defined in the delay.c file. Now you can turn on the device by
is declared as output pins (scan lines) Add all the three C fileslock.c, lcd. pressing Open and then entering the
and the upper nibble is declared as c and delay.cas source files to the new password that you have set. Key
input pins (return lines). The number MPLAB IDE project. Save the project C acts like Backspace key in a PCs
0Fh is written to Port B so that the file as Elock.mcp. Set configuration keyboard.
lower four bits become high and the bits properly before building the The only disadvantage of this
upper four bits become low. project. Select the oscillator as XT system is that the password set by the
Whenever a key is pressed, the up- and disable all other features like user is stored in the RAM and hence it
per nibble pin (return line) of Port B, to watchdog timer, power-up timer and is lost when the supply is switched off.
which the column containing the key is brownout detection. After successfully When the supply is switched on again,
connected, goes high. Thus the column building the project, the Elock.hex the system is reset with the default
is identified. Column identification file is generated. Burn it into the chip password 1234.
is done using a switch-case block in using a suitable programmer, e.g.,
the main program. On identifying MPLAB ICD2. Construction
the column, the rowfind(int) function A single-side, solder-side PCB layout
is called, which does the job of row testing for the PIC microcontroller-based elec-
identification. To identify the row, Once the program is burnt into the tronic lock is shown in Fig. 4 and its
scan lines are made low one by one in chip and the hardware setup is ready, component layout in Fig. 5.
sequence and status of the return line the user can test the system. When the Connect the 44 matrix keypad and
corresponding to the key is checked. If power supply is switched on, message 162 LCD to PIC16F877A microcon-
it becomes low, the key belongs to that Welcome is displayed on the LCD troller as shown in Fig. 1. Complete
scan line or row. The row and column screen. The default password set in the the remaining connections also as
numbers are stored in two global vari- program is 1234. shown in Fig. 1. Connect the appliance
ables row and col. A key debounc- To turn on the appliance, press to be controlled to RC2 (pin 17) of Port
ing delay of 20 ms is provided in the Open key. The system will ask for C through the relay-driver circuit as
program by calling the DelayMs(20) the password. Enter the password as shown in Fig. 3. Connect 6V power
function. 1234 and press Go. The appliance supply from the power supply circuit
After identifying the key, the ac- should turn on (RC2=1) and the mes- to the relay driver circuit. The 5V sup-
tion( ) function is called in the main sage Password Accepted should be ply required by the microcontroller
program, to perform the action corre- displayed for two seconds followed by is obtained from the 7805 regulator
sponding to the identified key. the message Lock Open. output.
The detailed procedure for devel- To turn off the appliance, press EFY note. The complete project
oping the project using MPLAB IDE, Lock. The appliance should immedi- folder (named Elock.zip) containing
compiling the same using Hitech C ately turn off (RC2=0) and the message the source code and related files is
compiler and burning the executable Lock Closed should be displayed on included in this months EFY-CD and
hex file to the microcontroller was the LCD screen. also available on www.efymag.com
explained in Construction section of To set a new password, press New website.

7 2 J u n e 2 0 1 0 e l e c t ro n i c s f o r yo u w w w. e f y m ag . co m

Anda mungkin juga menyukai