Ceska verze

Simple code lock

This is a very simple numeric code lock (combination lock). It is controlled by a microcontroller IO1 - Atmel AVR ATTiny24A (or older ATTiny24 or ATTiny24V), program to download and set bits you can find below. The microprocessor is clocked at 1 MHz frequency (8MHz internal RC oscillator and division by 8). Code (0-31 digits) is stored in EEPROM and thus is retained even when power is removed. The code can be changed without having to reprogram the processor. A standard 12-key keypad controls the code lock. It is matrix connected into a rectangle 3 x 4 with keys 0-9, *, #. Keys are scanned matrix way in columns from right to left with a frequency of about 100Hz. To indicate the status of the code lock three LEDs and piezo beeper are used. Capacitor C1 should be placed as close as possible to the microcontroller IO1. AVR idle consumption at 5V is about 0.3 to 0.5 mA. Total current consumption of this combination lock depends mainly on consumption of LEDs and output load. Resistors R1, R2 and R3 determine the current and thus the brightness of the corresponding LEDs. 5V can be obtained from a higher voltage using a simple circuit with the 7805.
     Modes of operation:
With the jumper DP1 (Mode selector) you can select one of the operating modes:
1 = code to unlock, single button to lock
2 = code to unlock, code to lock
3 = 2s pulse
4 = 6s pulse
5 = 18s pulse
In mode 1, it is necessary to enter the code to unlock. It can be locked without entering the code. In mode 2, it is necessary to enter a code both to lock and unlock. Modes 3-5 are used to impulse unlock - after entering the code the device is unlocked for the specified time and then it relocks automatically. Modes 3-5 differ from each other only in the pulse lenght (time to auto relock).
     Locking and unlocking:
The numeric code is entered using the numeric keypad (keyboard) with the digits 0 - 9. For confirming the code during unlocking use the # (so called hash key or pound sign - in the lower right corner of the keyboard). To lock the device use the * (so called asterisk or star - in the lower left corner). So when unlocking, enter the code and press #. To lock in mode 2, enter the code and press *. In other modes just * to lock. In modes 3-5 after the timeout the lock automatically locks. The asterisk (*) can be used to relock before the timeout. Pressing a key is indicated by a short beep. Locking is indicated by a beep with higher tone, then lower tone. Unlock is indicated by beep of lower and then higher tone. If you enter wrong code, you will hear 5 short beeps. Exceeding the maximum code length (31 digits) you will hear 3 short beeps and other digits are ignored. LED1 lights when it is locked, and LED2 when it is unlocked.
     Changing the code:
If you have not yet set the code, it is empty (0 digits). In this state, you can lock and unlock just by pressing the * and the # without entering a code. To start the process of changing the code, press and hold the # for 2 seconds (until you hear a long beep). Then enter the old code (or nothing, if the empty code is set) and confirm by #. you will hear 2 long beeps (step 2). Now enter the new code (0-31 digits). Confirm it by . You will hear 3 long beeps, signaling the final (third) step of code change: re-entering the new code (to verify there was no mistake during typing). Then again confirm it by #. You will hear a fanfare (4 tone beep), the new code is stored and the code change process is completed. If you want to lock and unlock without entering the code, can you change your code to an empty code (instead of entering new code, the press # directly).
     Recovering a forgotten code:
If you forget the code and you can not reprogram the processor, there is the possibility of recovering it :). Turn off the circuit, connect the PB1 pin with PA4 (this is the recovery jumper) and turn it on again. Now the lock is in recovery mode. Press the # for 2 seconds to enter the process of code change. In recovery mode, until the new code is succesfully saved, the entering of the old code (step 1) is skipped, so you will hear two long beeps now. Enter the new code twice, and then always confirm by #. Do not forget to remove the recovery jumper.
     The AVR program for download:
source code in Assembly (ASM)
compiled HEX file (1174 Bytes)

I can send you the programmed microcontroller. For more info click here.

Schematic of the Simple code lock with Atmel AVR ATtiny24A / ATtiny24 / ATtiny24V.

Configuration bits setting

The simple code lock during development in the breadboard (the letters on the keyboard are not used).

Very simple code lock circuit with ATtiny24A.

Video - Testing the simple code lock - modes 1 a 2.

Video - Newly added modes 3, 4, 5 (pulse unlocking).

Added: 8. 2. 2014