Electronic door codelock with PIC


This is my electronic codelock to use with an outdoor gate. The lock itself is implemented in software. It operates a relay (for example to open a door) for a few seconds if someone enters the valid code. The secret code can be changed any time after entering the current code. Note that in this application it’s not necessary to make an exact clock frequency with crystal (as seen on the schematic diagram), you can also use an RC type oscillator or other crystals.

I have the codelock design on my webpage for long and it is really poular. But it had some weaknesses like source code complexity, it needed an external 74LS138 and diodes because it was built on a general protoboard. Therefore I totally rewrote and redesigned it with simplicity in mind. The old design is still available here.


The version 2 codelock software has cool new features:

  • low power consumption due to keyboard wake-up
  • stores the code in the internal DATA EEPROM
  • the length of the code is user definable (actual is 4 numbers)
  • the running frequency is adjustable (actual is 10MHz)
  • output pulse width is adjustable (actual is 3 seconds)
  • code can be changed any time

The source code is freely downloadable. This is written for the PIC16F84, but you can easily adapt it to newer controllers like the 16F628, OTP versions with or without internal EEPROM. The first few lines contain the definitions of changeable parameters. If you are lazy, here is a compiled HEX file of the source intended to use with 10MHz crystal and P16F84(A). The codelock will work fine regardless of the actual frequency (the crystal you use) of PIC running, but the timing loop is calibrated to the frequency defined in the code (10MHz)

Electronic door codelock with PIC Schematicoperation

The keyboard, which is organized into a matrix looks like this:

ROW0 1 2 3 A
ROW1 4 5 6 B
ROW2 7 8 9 C
ROW3 * # D

You can use a 3×4 keyboard as well, because column 3 is not necessary in this application. # is used as ‘enter’ after you type in the valid code. The initial code is 1234 after programming the original source. You could activate the output with typing in:

1 2 3 4 #

* is used to change the code. Type in the actual code then press *. If you didn’t miss the actual code, the code change indicator LED will light up. Then type in the new code twice. Eg:

1 2 3 4 * 1 9 9 8 # 1 9 9 8 #

will change the code to 1998. The code changes immediately and permanently after typing the new code twice. If you miss entering the new code twice, the original code is kept.

If you don’t want anyone to be able to change the code, you can replace the ‘*’ key in the keytable to ‘#’. Or you can place the 3rd column inside your lock and use a key in this column coded ‘*’ to change the code. If you loose the actual code, you will need to access the DATA EEPROM of the controller with a programmer. The code can be read out or rewritten by the programmer.

posted by Pokas on 2003-03-19 23:44
Not work.
(list p=16f84
#include <p16f84.inc>
mhz EQU D’4′),MPASM


posted by Pokas on 2003-03-19 23:26


posted by dev on 2003-03-14 07:27
i am final year engineering student(ECE Dept)
we are doing a project in PC Based Oscilloscope.
We Need details of ADC 0804,LM 3914,LM 324,CD 4016,74244,7805
Expecting details from U.


posted by Stefan on 2003-03-13 19:22
Forgot the url to the schematic!
It’s not the best but hopefully you will understand. Atleased the pins we use are shown.
The url is: http://lisbeth.3fas.com/~mammuth/schema.jpg/Stefan


posted by Stefan on 2003-03-13 19:00
Can somebody please help!
New to this. I need help fast.
I need pic hexfile for a goldcard (pic16F84A & EEPROM 24LC16) that should send out a code when it gets power. Then I have a ic: pic 16F84, which i also need the hex-file for. This ic should recieve the code on one pin and if it’s the right code, it should send out a signal on another pin for 10 seconds. If it’s the wrong code it should do nothing. We will then use the outsignal in a transistor to close a circuit, like a relay.
The schematic we got is on:
Please help us, it is a school assignment that should be finished very soon. We thought we would make it but it seemed that assembler whas to hard for us. Please help us with the source, we will read it and probably learn something from it.
You can contact me either on [email protected] or ICQ: 14489649/Thanks in advance


posted by mohsen on 2003-03-13 09:06
please send for me additional information such as block diagram,circuit diagram blockdiagramfor code, component and any information about this project. thanks.


posted by Ernie on 2003-03-12 15:41
Hi everyone.i m studying alone electronics and i have just begun studying the pic microcontroller.if someone has this program for the pic i would be greatfull because i need a good example in order to understand a few things.it would also be good if u also sent some other URLs about electronics etc.Thank you.
[email protected]


posted by ahmad daqamseh on 2003-03-11 12:32
dear sir
iam a stuedent and i would you like to send me component and the diagram or the circuits of the door codelock on my e mail quickly.


posted by moorthi on 2003-03-11 12:09
the circuit is very nice


posted by DeLiMaVi on 2003-03-10 16:20



posted by fucker on 2003-03-10 06:10
this is the best item


posted by prashant on 2003-03-07 12:11
hi friends,
i am doing my graduation in electronics engg.. I am from india .i really need
your help.actually we have to do project in last yr of this cours.and i am searching for it if u have any idea related to micro processor based or related with robotcsORrealated with control panels then pls mail me on
[email protected]
[email protected]


posted by michael on 2003-03-06 21:39
deer sirs,
I am an chinese student.I have made a 89c2051 based code lock,but it could not change password,I can send it to you.I was very impressed by your website.I would be really thankful to you if you could send me a circuit which can define 2 different passwords and one master password.Master Password length is 8 digits and user password length is 4 digits.The master code is use to change user code.Can u plase give me the circuit schematic and the source code ,I need urgently
thank’s your help.
with best regards,


posted by jap on 2003-03-05 12:35
> If i take out the third column will I need to modify the code for the PIC

– no


posted by rah on 2003-03-05 06:16
dear sir
please send me circuit of fingerprint door access system


posted by DTG2003 on 2003-03-04 13:45
Hi i have a really important question to all

How i can read a pic with code protect ?

its really important for me is it impossible to read a Pic 16f628 with Code protect ??


posted by Ian on 2003-02-28 17:29
If i take out the third column will I need to modify the code for the PIC


posted by tufan on 2003-02-24 16:21
&#305; have got pic16f628 in the secret hex.&#305; dont read.
how programmer and software need for me…?thanks.
send my email pls…


posted by jeffrey yik on 2003-02-17 06:04
I need a circuit which can define 2 different passwords and one master password.Master Password length is 8 digits and user password length is 4 digits.The master code is use to change user code.Can u give me know what material is use for this project circuit.
I need urgently this circuit schematic.
thank’s your help.


posted by kunal.s.kalyanpur on 2003-02-15 16:15
I am an Indian student.I am currnetly doing a course on 8051 based microcontrollers.I was very impressed by your website.I would be really thankful to you if you could send me a list of some 8051 based projects.I was particularly interested in the automatic door opener and electronic door code lock.I am interested in trying out these projects uisng 8051.Could you please send me the circuit descriptions alone for these two using 8051 if you can.
with best regards,


posted by mohammad on 2003-02-15 08:26
dear sir
what is different between pic16f877 and pic16f877a?
how to use a/d module of pic16f877.please send to me a source code about
to use a/d module
thank you very much


posted by W.C.S. Ranasinghe on 2003-02-11 07:20
I’m a sri lankan student
i would like to know about more information plece send to my e-mail address


posted by daniel on 2003-02-10 15:39
es muy buena la cerradura si nesecitas los pcb de la placa ya los realise
con gusto lo envio
sin cargo


posted by daniel on 2003-02-10 15:37
es muy buena la cerradura si nesecitas los pcb de la placa ya los realise
con gusto lo envio
sin cargo


posted by markie on 2003-02-10 08:35
i’m markie and i am an engineering student..actually i want to ask you to pls help me with my project coz i really dont have any idea on what to do…it is an mpu based project..i like your idea of the codelock but it’s seems like is so difficult to do..i hope that you would give me a copy of the codelock coz i would want to do it for my project..
thanx…i hope that you’d be able to help me.


posted by Geoff on 2003-02-06 17:02
In the interests of security, I would suggest that additional measures are emplyed to make this fail-safe. A single failure could cause the relay to operate. An RF field, a voltage transient, or random component failure of the PIC chip could operate the transistor, as could failure of either the transistor or relay. My suggestion would be a watchdog circuit to make this fault tolerant and a triplicated output where you do not have to rely on a single device failure to render this insecure.


posted by jose on 2003-02-05 22:54
i have upgradet your circuit and bilt a new satelite to nasa id a codelock


posted by Amith Singh on 2003-02-04 20:49
I am a student of electronics in South Africa and will be doing a design project as part of my course. I would appreciate it if i could be supplied with more informatin on this lock and how the explaination of the entire program. Your help will be highly appreciated. Thank you.


posted by [email protected] on 2003-02-02 16:59
Siteniz cok guzel , elektronik devreyi inceledim ve yapiyorum.
istanbul / turkey.


posted by [email protected] on 2003-02-02 16:58
Siteniz cok guzel , elektronik devreyi inceledim ve yapiyorum.
istanbul / turkey.


posted by [email protected] on 2003-02-02 16:46
Siteniz cok guzel , elektronik devreyi inceledim ve yap&#305;yorum.
&#305;stanbul / turkey


posted by Muhammad Haider on 2003-01-31 08:22
HI i want a detailed information about pic code lock.
your help of me will be appreciated.
please send me complete information on my email.
[email protected]
[email protected]yahoo.com


posted by John on 2003-01-30 07:25
I’m trying to do a similar project with a PIC 16F877 or 16F874 using C language. If anyone can help, please feel free to e-mail me @ [email protected] Thanks


posted by Xenobius on 2003-01-29 17:32
Hello I have built your circuit and i got a broblem. When i connect it to 12v, the relay switches on and keeps ON !!

and also when i try to change the pic from 10mhz to 4 mhz the led keeps ON !!

also the relay woundt change to its normal stat even if i input the 1234# could you help ? thankyou v much


posted by Jamie on 2003-01-29 15:51
I’m a college student in my final year.
It would be very much appreciated if you could send me complete info regarding this electronic code lock project, it’ll would be very useful.
thanks again


posted by D.V.RAJENDRA on 2003-01-24 14:26
what a service you are doing.I wonder when i read your e-mails.
Can you suggest to a person who knows noting in electronics to become good at making products by using your help.


posted by Emmanuel-lyn on 2003-01-23 17:28
hello! im just wandering if this electronic codelock can be used as codelock for intercom. I hope you’ll find time to answer or explain this to me. Thanks and more power!


posted by sanza on 2003-01-23 05:24
im interisted with your project electronic door codelock, can this project be use in many doors? i mean, using a single project into a multiple doors with deffirent codelocks? can u show me a program of it? im confused with it….


posted by sanza on 2003-01-23 05:02
may qouastion
can i use of this source code for pic16f84 with 4MHZ at circui?
plase you send me source code with ferquancy pic of type 4MHZ
thank you .


posted by joshua on 2003-01-22 08:17
I’m trying to add this electronic door codelock as another feature in my project.Do u think how I can combine this circuit with another circuit…and can u provide me the layout,please.thank u.


posted by AIT TIMELLOUINE MOHAMED on 2003-01-21 12:18
J’ai l’honour de


posted by AIT TIMELLOUINE MOHAMED on 2003-01-21 12:10
J’ai l’honour de


posted by John Paul Aguiling on 2003-01-20 22:25
Hi! Thanks for posting the codelock combination. I hope you can send me more projects you have done. May be we can share PICs projects…


posted by dexter on 2003-01-19 09:56
im interisted with your project electronic door codelock, can this project be use in many doors? i mean, using a single project into a multiple doors with deffirent codelocks? can u show me a program of it? im confused with it….


posted by steve on 2003-01-15 23:04
i work for a company that uses plant machinces and other people keep using them so Would it be easy to convert this to a immobiliser like the code is entered then the realy diables the plant machine and them renter the code to turn it back on


posted by Liz on 2003-01-15 15:47
dear sir,

i’m a computer engineering student from the philippines. We are very much in need your help… We have this project in one of our subjects and we proposed a password enabled door. Our project would enable the user to enter a password and if he makes 3 consecutive mistakes, the door would lock. How will we wire the circuit using a parallel port? By the way, we are using Visual Basic… I’m hoping you could give us, if you won’t mind, the complete details of this project. thanks!


posted by jepoy on 2003-01-14 12:45
dear sir,
if i used pic16f84a and a 4MHZ crystal in this project, what are the possible changes i will made? pls email me the source code and hex file of the changes. pls send me.sir if can i have a favor of full detail about the cicuit tnx for all the information about PIC. ([email protected])jeff


posted by Hari krishnan on 2003-01-13 10:32
please give me information about same feature purely electronic basis


posted by emin on 2003-01-11 02:18
dear sir,
if i used pic16f84a and a 4MHZ crystal in this project, what are the possible changes i will made? pls email me the source code and hex file of the changes. pls send me. tnx for all the information about PIC.


posted by aris on 2003-01-10 03:58
hi sir, im aris a student. i really need your help. i have a project called “automatic door opener using barcode reader” the problem is the serial barcode reader. if we going to use it, is there a tendency that we overcome a multitask? pls. send me a shematic diagram to operate the door and what type of door will be using? thanks


posted by VANILDO on 2003-01-05 21:41


posted by sandeep on 2002-12-28 11:58
hello sir,
i’m sandeep from india and i’m doing my bachelor’s course in electronics.i need to make an elec lock as a part of my project.it should be suitable to me.i’ve written a program in ‘c’ language & acc to it a person with a correct password can enter the office etc.i need a lock circuit that connects the serial port of the PC to enable my project.so kindly give me the details of the reqd circuit as soon as possible with all details.i’ll be very grateful if u help me out


posted by jepoy on 2002-12-22 16:13
dear sir,
if i used pic16f84a and a 4MHZ crystal in this project, what are the possible changes i will made? pls email me the source code and hex file of the changes. pls send me. tnx for all the information about PIC.jeff


posted by Jean louis tisambi on 2002-12-20 14:22
I think that you can help me. We are working in the school project about electronic kill switch for a jeep. This kill switch has a keypad where you can enter pin number. If you enter three times the wrong number the system will be desabled and activating an alarm. In my group studends that should prepare the program they did program and in the circuit it does not work. So we decide now to use PIC microcontroller insted of 8031. I start writing my program but I am not sure to get it in few time because I just learn the PIC now, I do not have understood very well everything on PIC. I need your help if I can get something from you.
Maybe you find some orthograph error because my fisrt language is french.


posted by obing on 2002-12-16 14:31
ansaya saya!!!


posted by orimoyegun peter akinyemi on 2002-12-16 13:57
sir, I’m a student of ECE,lagos state university. I would like you to send me the full details of the circuit,program for the processor and other related informations. I am a 400level student and would like to use it for my project.


posted by bit_zero on 2002-12-14 08:57
can i have a copy too of the schematics and details and the .asm files,,,, i need ’em for my project….thanks and hey to peeps from the philippines…


posted by sadan on 2002-12-13 07:54
Fine, and kindly add some more projects with 8051/pic 16f84

keep the ball rolling

with regards


posted by [email protected] on 2002-12-12 10:31
Yello, how r u? I am fine. How was the party last nite?I am making a circuit board for my gcse’s. So far, I have 1 circuit board. I am supposed to have about 5. This circuit board that I am using, involves the 7225 chip.Can u give me some circuit boards which is for an electronically accessed safe. Remember I your friend. Thanks. [email protected]


posted by Adam on 2002-12-10 21:17
Dear Sir,

I am currently working on an alarm project in which i plan to incorporate your door lock circuit. I have the 20mhz version of the PIC. Can you please email me with details of what i need to change as I have limited knowledge of PIC’s.

Thank you very much.


posted by Rene on 2002-12-10 08:22
hi sir. i am an eng’g student here in the philippines. i’m doing a project proposal using 16F84A microcontroller. i am interested in your e.door codelock. can you include in your website the program you used to your e.door codelock. are all the materials you used available here in the philippines. thanks am lot.


posted by Jessie on 2002-12-08 01:42
Dear Sir,
i am a computer engineering student in the philippines. i am interested about your codelock project ,can i request the details on its materials and program.
i want to make one for my house. thank you very much.


posted by Benjamin on 2002-12-05 14:48
Por favor necesitaria saber si el circuito es posible tener varios codigos para distintos usuarios=?


posted by Sia Ying Foong on 2002-12-03 05:08
hello,i’m a third year student..and i’m going to do my first project….and i’m attract with your door code lock system..can you send me a details about this project..include the programming…and some circuit out there….

hope u can help me…


posted by jeffrey on 2002-12-02 18:30

thank you for sharing this kind of circuit.I’am a ECE student here in the phillipines. it is a big help in my project. i have made your codelock
wireless. thank you! thank you!thank you! thank you!thank you! thank you!



posted by Mark on 2002-11-26 13:30
Thenks for the door lock I have just bilt it so as my 4 year old son can not open our Electronic gate and it works grate


posted by Arnold T. Caluza on 2002-11-25 04:20

i would like to have some information about your design: electronic code lock.

specially the schematics and software of your design, i’m an Ece students her

in the philippines. we need to have a design on our microprocessor subject.

luckily i found your design on the net. PIC168F84 is too expensive, and we dont

have any universal programmer to use to decode the program. I would like to ask

if thier’s any microprocessor or microcontroller based project that you can

suggest. And i would like to know if the PIC16F84 has a built in program?

respectfully yours,



posted by marciano on 2002-11-21 02:23
can u give me just a simple project, an electronic toy


posted by Ali Ortakabakci on 2002-11-14 22:08
Hi i’m Ali From Turkey i will try it circuit but i don’t know english well
have u e-mail address Mustafa Deniz and Ersin Yücel May u send to me its Thanks


posted by zack on 2002-11-13 19:03
hi!i really need your help to do my thesis.i’m using PIC16F84.i hope u can e-mail any details about any project that u think is good for thesis using that PIC.thank u very much.i need it as soon as possible.


posted by jay-r antonio on 2002-11-07 16:26
hi jap!!

i like ur design about electronic codelock using pic.. can i know the program of these circuit on how will it respond?? thanx very much!!

more power!!


posted by Tom on 2002-11-06 02:42
This is a neat website, im impressed. I think ill build one of these next chance i get


posted by chyke on 2002-11-05 14:35
Please,I am an Electrical/Electronics Engineering student in a university here in Nigeria.
I am supposed to carry out a project on a related topic(E/E related topic of course).
Please give me a proper circuitry breakdown.


posted by Evandro on 2002-11-04 02:25
help i need schematic


posted by Pham Thu Hien on 2002-11-02 08:41
Hi every body!
I have to make an electric lock but I dom’t know where to begin. Can u help me from design the circuit? Please mail me, my e-mail is: [email protected]
Thanks a lot!


posted by Pham Thu Hien on 2002-10-31 13:47
Hi everybody!
I’m a student of Hanoi University of technology. Now I’m studying at Electric and Communication Department. My teacher asks me to make an electric lock but I don’t know where to begin. Can you help me from making the circuit?


posted by Law Chi Hang on 2002-10-31 10:57
Dear Jap,

I am a part-time evening student of High Certificate in Electronics and Communication Engineering, in Hong Kong. My lecturer of Project requires us to make a project that use 8051 microprocessor to control the all functions. I decide to make a electronic code lock. It is similar to your design but it is controlled by 8051 microprocessor, not the PIC chip. Unlucky, I am studying a subject of Microprocessor Engineering at initiation. That means my understanding of 8051 assemble program is very weak. I really hope that you can give me some assistance and design concept and assemble program help.

My proposal of the electronic code lock is as shown below:
The electronic code lock system is controlled by an assembly program in an 8051 microcontroller. The program can identify 3 (or more) sets of password, permit 3 times incorrect password input, has the master reset code and has a period control function.
Password and code length can be also changed any time through the k


posted by fraser on 2002-10-29 17:45
well hi if anyone has an old gcse electronics project on a burglar alarm involving a pic please could someone send it to me because i am having real trouble thanks


posted by vinod.kulkarni on 2002-10-28 05:28
Hi everybody,
I want one help from u people,I am trying to operate the 16f877 pic mc for 10 bit adc mode,but it is working like 8 bit only i don’t what the problem,can u anybody help me in solving this problem ,my emailid is [email protected]
posted by Vinod.Kulkarni on 2002-10-28 05:26
Hi everybody,
I want one help from u people,I am trying to operate the 16f877 pic mc for 10 bit adc mode,but it is working like 8 bit only i don’t what the problem,can u anybody help me in solving this problem
posted by david falzon on 2002-10-27 16:08
my name is david and i am from malta. i am seeking a car alarm circuit working at 12V dc and havin the transmitter to swith it on and off. if you can supply me with the schematic you have given me the greatest help that you imaginethanks in advance


posted by Fatih on 2002-10-25 15:25
Hi… I will try to run your circuit in ISIS Proteus5.2. But I don’t run it.
can circuit’s asm cod be to absence? can you help me pls?


For more detail: Electronic door codelock with PIC

Current Project / Post can also be found using:

  • pic16f88 timer circuit
  • pic16f877a code lock hex file and circuit diagram
  • projects microcontroller
  • pic 8-bit coded door entry
READ  How to Program a PIC Microcontroller to Build a Project

Leave a Comment

= 5 + 5

Read previous post:
keypad code lock
Dual programmable keypad code lock using PIC18F452

Open electrical doors with your secret code only! Here are the technical specifications: Up to two keypads may be connected...

Scroll to top