Electronic combination lock based on PIC16f84

Electronic combination lock

description

This is my electronic combination lock to use with an outdoor gate. The functionality is implemented in software. It turns on a relay (usually to open a door) for a few seconds if someone enters the valid code. Alternatively, it works as an ON/OFF switch, which toggles the relay each time the code is entered. This relay can operate a power-to-open type electric strike with a shorting contact or a power-to-hold type electromagnetic lock with a breaking contact (we need the relay because these locks usually work with AC, not DC). The code can be changed any time after entering the current code.

Electronic combination lock

Current consumption of the circuit is low, because the PIC sleeps most of the time, and wakes up only for processing key presses. If you don’t have a crystal, you can use the RC oscillator of the PIC16F84 as well, just check the PIC datasheets for details on oscillator configurations. The 16F628 already contains an internal RC oscillator, so no crystal is needed.

operation

type in the correct code and use # as ‘enter’. The initial code is 1234 after programming the un-modified HEX file. 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.

Electronic combination lock Schematic

software

Essentially, all software versions work the same. You can download and customize the source code for the version you choose. The first few lines of the code contain definitions of changeable parameters. If you are lazy, you can simply download the HEX files already compiled with default values. The definitions:

mhz EQU D'4'
this value is used for delay calibration. Of course, the code will run with different speed hardware as well, but faster or slower than intended.
pulsewidth EQU 'D'150'
this value is used to set the delay of the output pulse. To calculate the delay in seconds, use pulsewidth * 20 ms
clen EQU 4
this value sets the length of the code. The length is always fixed, and you can set it much higher, until you have available RAM on the chip

More details on the source code can be found here.

hardware

The keypad is actually a collection of push-buttons, organized into a matrix. It looks like this:

If you have a different layout keypad, you can change the definition of the buttons (keytable) in the source code. The keytable contains four lines, each consisting of four characters:

You can use a 3×4 keypad or a 4×4 keypad. The advantage of the bigger keypad is that you can use the extra letters in codes. Connect the keypad wires to the lock by the labels (ROW0 to ROW0, COL0 to COL0, and so on). In case of using a 3×4 keypad, simply leave the COL3 input unconnected, no other modification is required. If you don’t have a keypad, you can even wire one from push-buttons.

Use a power source with DC output between 8 and 30 volts, min 200 mA (or higher, depending on your relay current) to power the lock.

The relay specifications are not given here, because you can choose from many. Choose the relay voltage based on your incoming voltage. If you use 12VDC to power your lock, choose a 12V DC relay. Choose the relay switch ratings based on what you intend to switch with it. For an electric strike, use one capable of switching at least 2A/24V.

The component labeled ‘BUZZER’ is a passive ceramic piezo sounder. Do not use buzzers with internal (sound generator) electronics and/or with low-impedance speaker coils in it.

Read more: Electronic combination lock based on PIC16f84

Leave a Comment

Your email address will not be published. Required fields are marked *