You are on page 1of 22

MicRocoNtRolleR-bASedcode locK

SUNIL KUMAR

ode locks can be constructedusing digital and timer ICs em-ploying pushbuttons or keypadsfor entering the code for authenticationand operation of the code lock. How-ever, such circuits would require alarge number of ICs.On the other hand, a microcon-troller-based code lock will requirev e r y f e w p e r i p h e r a l c o m p o n e n t s . With the cost of microcontrollers nowdropping to the equivalent cost of ap-proximately four digital ICs, it makessense to design simple logic circuitsusing microcontrollers and free versionof programming languages. Althoughfree-version-language code length isnormally limited to around 2 kB, butthat is adequate for small projects likethis one.This simple code lock project isbased on a 20-pin ATMEL microcon-troller AT89C2051. It employs a 4-digitsequential code with time-out securityfeature. In addition to the microcon-troller, the circuit uses a single ad-ditional IC (CD4050) and a transistorto drive a relay. Although the projectuses a liquid-crystal display (LCD), itis useful for design and developmentalpurpose only and is not really an es-sential part of the circuit. The same canbe removed from the circuit withoutany change in the software.As regards LCD modules, these areavailable in 14- or 16pin packages. The16-pin variety has an additional back-light option. Popular brands availablein India are Lampex, Hantronix andHitachi. Most other models also have the same pin conguration. The model used in this project is Lampex LM162001 6 - c h a r a c t e r 2 - l i n e a l p h a n u m e r i c dot-matrix display with backlight op-tion. However, you may also use anyother branded/unbranded LCD forthe purpose. cru srpn A s a l r e a d y m e n t i o n e d , t h e p r o j e c t makes use of ATMEL AT89C2051 mi-crocontroller, in 20-pin DIP package, which supports 2 kB of ash-based program memory. A 6MHz crystal isused for providing the clock. Port-1 ofthe microcontroller is used to drive theLCD in 4-bit mode with 10-kilo-ohmp u l l - u p r e s i s t o r s . T h e 1 0 - k i l o - o h m potentiometer controls the contrast ofthe LCD panel. It works better when itswiper is nearer to ground potential.Timer 0 of 89C2051 is used as aninternal counter that increments a vari-able every second. This variable is usedin the project to time out the delay forentering the code.After initialisation, the software
Fig. 1: Circuit of microcontroller-based code lock

60 A u g u s t

ConstruCtion
2 0 0 6

e l e c t r o n i c s w w w. e f y m CMYK

f o r Ag .

y o u co m

switches on Ready LED and waitsfor a 4-digit code to be entered. Thevalid code for this project is 1324. Thecode is entered using the seven inputswitches that are connected to portParts List

Semiconductors: IC1 - AT89C2051microcontrollerI C 2 - C D 4 0 5 0 n o n - i n v e r t i n g bufferIC3 - 7805 +5V regulatorT1 - 2N2222 npn transistor D1-D5 - 1N4007 rectier diode LED1-LED3 - 5mm LED Resistors (all -watt, 5% carbon): R1, R2, R4 - 220-ohmR3 - 150-ohmR5 - 10-kilo-ohmRNW1, RNW2 - 10-kilo-ohm resistornetworkVR1 - 10-kilo-ohm preset Capacitors: C1 - 10F, 16V electrolyticC2, C3 - 22pF ceramic diskC4, C6 - 0.1F ceramic diskC5 - 1000 F, 25V electrolytic Miscellaneous: X
TAL

3. Port-3 does not have the bit P3.6and hence the same is ignored by thesoftware. Two LEDs at port-1 are inter-faced to P1.0 and P1.1 pins to provideReady and Relay On indication viarespective LEDs.The P1.1 line is also interfaced torelay driver transistor T1 through a buf-fer to switch on a 12V relay, which canactivate an electrically operated lock.T i m e r 0 i s s t a r t e d o n t h e f i r s t keystroke to validate the remainingt h r e e d i g i t s , p r o v i d e d t h e s e d i g i t s are entered within ve seconds. If not, the software loops back to theinitial state. After three unsuccess-ful attempts, the circuit will wait forabout 10 seconds (before acceptingthe next keystroke) to avoid unwantedtampering attempts. All these timingscan be changed through the software program to suit your specic require -ments. Power supply (Fig. 2). A c o n - ventional regulated power supplyc i r c u i t e m p l o y i n g a s t e p d o w n transformer followed by bridge rec-tifier, smoothing capacitor and 5Vregulator is used to meet the supplyrequirement for the code lock circuitshown in Fig. 1.
Fig. 2: Power supply Fig. 3: Actual-size, single-side PCB of microcontroller-based code lock Fig. 4: Component layout for the PCB

- 6MHz crystalRL1 - 5V, 100-ohm, 1C/O re-layS1- S8 - Push-to-on switchS9 - On/off switchX1 - 230V AC primary to 9V,250mA secondarytransformer- 16-character2-line LCD(male-53 pins used)- Bergstick connector(female- 36 pins used)- 1m long, 4-core ribbon

You might also like