Do-it-yourself electronic lock with ibutton keys. Universal electronic lock - immobilizer with iButton keys. Scheme and description. Adding new keys

The lock has a simple design and is intended mainly for individual use. The lock works with any type of iButton keys, so you can use existing keys for other purposes. In total, up to 9 keys can be stored in memory, although this number can be easily increased. To authorize the programming process, a master key is used, the code of which is stored in the ROM and cannot be erased or changed by the normal lock programming procedure.

Recently, locks have become widespread, the key to which is an iButton (or touch memory) electronic tablet from Dallas Semiconductor. Such locks are often used on the doors of entrances, as well as inside many institutions. In addition, iButton keys are often used for payments at gas stations and other places. So many people already have iButton keys for something. Therefore, when designing a homemade lock, it is rational to use the keys that the user already has in it. This is exactly what is done in the proposed lock: any type of keys can work with it, since only the serial number stored in the iButton ROM is used, which is in any of their types. In addition, the command to read this number is the same for all types of keys (33H). The family code, which differs for different types, can be anything. It is perceived as another digit of the serial number. It should be noted that the cheapest type of keys is DS1990A.

The castle was designed for individual use and has an extremely simple design. On the front door from the outside there is only a socket for iButton and a door opening LED. Opening the doors from the inside is carried out using a button. As an actuator, a standard latch with an electromagnet is used, which is designed for a voltage of 12V. Key codes are stored in non-volatile memory and can be deleted and added by the user. A master key is used to protect against unauthorized reprogramming of the lock. In total, 9 keys can be stored in memory. This number is dictated by the capabilities of the 1-digit indicator of the number of the programmable key. If you also use letters, you can increase the total number of keys to 15. This is done by changing the value of the MAXK constant in the program. In the same way, you can reduce the maximum number of keys.


Rice. 1. Schematic diagram of the lock

Schematic diagram of the lock is shown in Figure 1. The design is based on the U1 microcontroller type AT89C2051 from Atmel. A 7-segment indicator is connected to port P1, which is used when programming keys. The SB1 button connected to the P3.7 port is also intended for the same purposes. Key serial numbers are stored in EEPROM U3 type 24C02, connected to ports P3.4 (SDA) and P3.5 (SCL). The external iButton socket is connected to the P3.3 port via the XP2 connector and VD4, R3, VD5 and VD6 protection elements. The pull-up resistor R4 is selected according to the single-wire bus specification. Parallel to the external socket, an internal XS1 socket is also connected, which is used for key programming. The door open button is connected to the P3.2 port via the XP1 connector and the same protection elements as for the iButton. The actuator of the lock is an electromagnet connected via terminal XT1. The electromagnet is controlled by the VT3 key, which is used as a powerful MOS transistor of the IRF540 type. Diode VD7 protects against self-induction emissions. The VT3 key is controlled by the VT2 transistor, which inverts the signal coming from the P3.0 port and provides 0/12V control levels at the VT3 gate. The inversion is needed so that the actuator does not work during the reset of the microcontroller, when there is a logical one level on the port. The 12-volt control levels made it possible to use a conventional MOSFET instead of the more scarce low-threshold (logick level) one. To indicate the opening of the lock, an LED is used, which is controlled by the same port as the electromagnet, but through a transistor key VT1. The LED is connected through the same connector as the iButton. Since the device must operate around the clock without maintenance, a U2 type ADM1232 supervisor is installed to improve reliability. It has a built-in watchdog and power monitor. On port P3.1, the microcontroller generates periodic pulses to reset the watchdog timer.

The device is powered by a built-in power supply unit containing a transformer T1, a rectifier bridge VD9-VD12 and an integral stabilizer U4. As a backup power source, a BT1-BT10 battery of 10 AA size NiMH batteries with a capacity of 800mAh is used. When the device is powered from the mains, the battery is charged through the resistor R10 with a current of approximately 20mA, which is 0.025C. The mode of charging with a small current is called drip (trickle charge). In this mode, the batteries can be indefinitely long, control of the end of the charging process is not required. When the batteries are fully charged, the energy they take from the power source is converted into heat. But since the charging current is very small, the generated heat is dissipated into the surrounding space without any noticeable increase in the temperature of the batteries.

Structurally, the device is made in a housing measuring 150x100x60mm. Most of the elements, including the power transformer, are mounted on a printed circuit board. Batteries are placed in standard plastic holders, which are fixed inside the case next to the board. In principle, other types of batteries can also be used, such as the 12-volt maintenance-free acid battery used in security systems. The board has TB-2 type terminals for connecting an actuating device, all other external circuits are connected via small-sized connectors with a pin pitch of 2.54 mm. The connectors are located on the printed circuit board and are not accessible from the outside of the case. The wires exit the housing through rubber seals. Since the HG1 indicator, the SB1 button and the iButton XS1 socket are used only during programming, they are placed on the board inside the device. This simplifies the design of the housing and makes it more protected from external influences. On the side panel of the housing there is only a VD13 power-on indication LED. The scheme of external connections is shown in fig. 2.


Rice. 2. Diagram of external connections

When the door is opened, a pulse lasting 3 seconds is applied to the electromagnet. The logic of the device is such that if the door opening button is held down, then the electromagnet will be energized all this time and, accordingly, the door will be open.

The lock can have a maximum of 9 keys, plus one master key. The key codes are stored in non-volatile memory under numbers from 1 to 9. The master key code is stored in the ROM of the microcontroller and cannot be changed. Programming new keys or erasing old ones can only be done with a master key. Like other keys, the master key can be used to open the lock.

To program a new key, do the following:

  1. Press the programming button.
  2. The letter “P” will appear on the indicator, which means entering the programming mode.
  3. Touch the panel with the master key.
  4. The indicator will show the number "1", which indicates the number of the programmable key.
  5. Use the button to select the desired number.
  6. Touch the panel with any key.
  7. The number on the indicator will start flashing, indicating that it is ready for programming.
  8. Touch the panel with the key whose code you want to memorize.
  9. In case of successful programming, the figure on the indicator will stop blinking and will start to burn constantly.
  10. To exit the programming mode, you just need to wait 5 seconds, after which the indicator will turn off.

Schematically, the process of programming a new key is shown in fig. 3.


Rice. 3. Programming a new key

If you need to program several keys, you can immediately go from step 9 to step 5 and repeat steps 5-9 as many times as necessary.

If, after step 7, it turns out that the wrong number has been selected, then to avoid losing the key code under this number, you can press the button or simply wait 5 seconds. In the first case, the current number will increase by one, and the contents of the memory will remain unchanged. In the second case, a complete exit from the programming mode will occur without changing the codes. In general, you can exit programming at any time if you pause for more than 5 seconds.

To erase an extra key from the memory, the sequence of actions remains the same as during programming, only all actions are performed by the master key. Those. the erasing process is actually writing the master key code to unused numbers.
Schematically, the process of erasing an extra key is shown in Fig. 4.


Rice. 4. Erase extra key

During programming, you can open the door with the button, but opening with iButton is blocked. Since the inner and outer sockets are connected in parallel, care must be taken that during programming no one touches the outer socket with any keys.

The master key code is written to the ROM of the microcontroller programs, starting from the address 2FDH. The code length is 8 bytes. The sequence of numbers should be the same as on the touch-memory case, you need to read from left to right. Those. at address 2FDH, the checksum value is entered, then at addresses 2FEH - 303H, six bytes of the serial number, starting from the high byte, and, finally, at address 304H, the family code. For example, the code as a whole might look like this: 67 00 00 02 D6 85 26 01.

The electronic lock program has a main loop, the block diagram of which is shown in fig. 5. In the main loop, the socket is polled, and if a key is found there, then its code is read. Then this code is checked, and if it matches the code of the master key or any other key (user key) stored in memory, the lock opens. The state of the door opening button is also checked, and if a press is detected, the lock also opens.


Rice. 5. Block diagram of the main cycle of the program

There are two subroutines for handling events related to programming: PROGT and PROGS, the block diagrams of which are shown in fig. 6. The first one is called when the key code is read in the programming mode, the second one is called when the programming button (NUMBER) is pressed. The programming process is divided into 3 phases. When the NUMBER button is pressed, programming is entered, i.e. transition to phase 1. In this case, the letter “P” is displayed on the indicator. The key codes that are read after that are checked for a match with the master key code, since only it can allow programming to continue. If such a match occurs, then the transition to phase 2 is carried out. The indicator displays the number of the current key, which the NUMBER button can change. If a key touch is registered again, a transition to phase 3 will occur. Another key touch will lead to storing its code and returning to phase 2. By pressing the NUMBER button, you can also return to phase 2, but without changing the contents of the memory. Any action in programming mode causes the reset of the return timer, which has an interval of 5 seconds and is checked in the main loop. If a reset of this timer is detected, the programming mode is exited.


Rice. 6. Block diagrams of subroutines used when programming the key code

Shown in fig. Flowcharts 5 and 6 are greatly simplified, but they allow you to understand the general logic of building a program.

The described castle, of course, does not have a wide range of possibilities. However, it is very simple, which makes it easy to repeat. The open source code of the program allows you to independently improve the design or adapt it to specific requirements.

Download files:
lock.asm - source code for the lock program.
lock.bin - compiled program.

The device is assembled on an ATtiny2313 microcontroller, to which an external non-volatile memory EEPROM - 24C16 is connected. Source codes are available, work "on iron" is checked up. The access controller works with DS1990 type keys, supports up to 500 pcs. Programming the access controller through the master key or through the jumpers on the board.
The access controller, in addition to the button for opening the lock, has a limit switch that tracks the time the door is open. The signal response time is programmed by jumper JP2 (from 10 sec to 127 sec).

The controller on electronic keys DS1990A.

Supports up to 500 keys. The device is made on the AVR microcontroller: ATtiny2313.

Schematic diagram of the i-Button DS1990 key reader (click on the diagram to enlarge):

Programming instructions

Operating mode - when 12V is applied to the controller, the LED flashes at 1Hz.
Programming mode - LED flashes 2 Hz.
When you press the "OPEN" button, a series of short beeps for the duration of the lock opening.
The door limit switch (NC) monitors unauthorized entry without a key.

The controller beeps if:
1 - After opening the door, the door remained open for more than the programmed passage time.
2 - Opening the door without a programmed key or using the "OPEN" button, the controller starts emitting short double beeps until the door is closed.

Attention!!! Programming the waiting time for a closed door CAN ONLY BE USED WITH JP2 JUMPER.

Sound signals

1 short beep - the key is stored in the controller's memory.
2 short beeps - the key is already stored in the controller's memory.
5 short beeps - exit from the programming mode.
1 long beep - the key memory has been erased from the controller.
short beeps 20sec. - the key memory is full.

Record MASTER Key and lock opening time

1 - Power off the controller.
2 - Press the "OPEN" button
3 - While holding the button, connect the power to the controller, after 5 seconds. controller "Squeak",
the LED will flash at a frequency of 2 Hz.
4 - Release the button.
5 - Bring the key to the reader, a single beep will sound,
The master key is WRITTEN, and the lock opening time of 1 sec will be recorded.

6 - Holding the key on the reader - we count the sound signals,
number determines the required time to open the lock, increment 1 sec. But no more than 32 seconds.
7 - Turn off the power to the controller or pause for 20 seconds.

Erase all key memory.

1 - Operating mode.
2 - Press the "OPEN" button and while holding it, bring the MASTER key to the reader and hold it, after 10 seconds. a long beep will sound - the key memory has been erased.
3 - Release the button and remove the key.

Adding new keys

1 - We bring the Master key to the reader and hold it for 5 seconds, 2 short beeps will be heard, the LED will flash at a frequency of 2 Hz.
2 - Bringing additional keys one by one to the reader - a short beep will sound, - the key is RECORDED, if 2 short beeps are heard - ATTEMPT TO RECORD A DUPLICATE KEY.
3 - We write down the required number (up to 500) of keys. The pause between the recorded keys is no more than 20 seconds.
4 - Turn off the power to the controller or pause for 20 seconds.

Access controller programming via JUMPERS JP1,JP2,JP3,JP4

JP1 - RELAY operating time, increment 1 sec.
JP2 - Waiting time for closing the door, increment 1 sec.
JP3 - Adding new keys (maximum - 500).
JP4 - Erase all keys from the controller's memory.

The jumper performs its function with a constant short circuit for the duration of use.

Printed circuit board:

Appearance of the assembled device:

"RELAY work time"- JP1 the red LED flashes with a frequency of 1 Hz throughout the duration of the jumper. and a short beep sounds. With each sound and light signal (green LED) 1 second is added to the variable "RELAY operation time". In total, it can be from 1 second to 32. After counting the required number of seconds, remove the jumper.

"Waiting time closed door"
- JP2 the red LED flashes at a frequency of 1 Hz throughout the duration of the jumper. and a short beep sounds. With each sound and light green signal, the "Closed door waiting time" variable is added by 1 second, in total it can be from 5 seconds to 126. After counting the required number of seconds, remove the jumper.

"Adding New Keys"- JP3 throughout the duration of the jumper closing, the red LED flashes at a frequency of 2 Hz. Bringing the key to the reader, upon successful reading, a short beep will sound and the LED will blink green - the key is written. If the key is already stored in the memory, then when you try to write it again, 2 short beeps are heard. When trying to write more than 500 keys to memory, the red LED flashes constantly at a frequency of 2 Hz. and a short beep sounds periodically. Remove the jumper.

"Erasing all keys from the controller's memory"- JP4 3 seconds after closing, 5 short beeper signals are emitted, a pause, then the beeper sounds continuously for the erasing time (approximately 10 seconds) - the key memory is erased. Remove the jumper.

This electronic lock is an immobilizer; it uses iButton (Dallas Touch Memory) keys of the DS1990 type as keys for authorization. Each such key has its own unique 64-bit serial number, which is an access code that allows the key holder, for example, to open the door.

The main parameters of the electronic lock:

  • memory up to 15 keys;
  • three operating modes: monostable, bistable and with adjustable relay on time;
  • light indication of lock operation (reader indicator);
  • power supply from 9 to 15 V / 100mA;
  • current consumption in standby mode: 6mA;
  • board dimensions: 34×46 mm;
  • the operation of the scheme was tested in Proteus (link at the end of the article)

Schematic diagram of the lock is shown in the figure below. Its main element is the PlC12F675 microcontroller with an internal ADC. In this case, the ADC of the microcontroller is used to configure the lock parameters.

The microcontroller is clocked from an internal RC oscillator with a frequency of 4 MHz. The circuit is powered by a constant voltage of 12 V. It can be any battery or power supply with a load current of at least 100mA.

Diode VD2 protects the system from the wrong polarity of the input voltage connection. The input voltage is supplied to the DAl stabilizer type 78L05, capacitors C1 ... C4 act as a power filter. A miniature relay of the JQC3FF type (coil 12 DC, contacts 10 A/230 V) was used as an actuating element.

The output signal from the microcontroller (pin 2) goes to the base transistor VT1, in the collector of which the relay coil is connected. Resistor R7 limits the current flowing through the base, while diode VD1 protects the transistor from self-induction EMF that occurs when the relay is turned off.

Resistors R2 and R3 together with R1, depending on the position of jumper JP2, determine the mode of operation of the lock:

  1. If jumper JP2 is not installed, then a high level voltage is applied to input G4 through resistor R3. In this case, the microcontroller will switch the lock to monostable mode. In this mode, touching the key to the reader will turn on the relay. This state will be permanent until the power is turned off, regardless of whether the key is reapplied. This mode of operation can be used to work as an immobilizer in a car.
  2. Installing a jumper on the pins will put the lock into bistable mode. In this mode, each touch of the key will switch the relay.
  3. Installing a jumper on the outputs sets the temporary mode of operation. In this mode, touching the registered key to the reader will turn on the relay for a certain time. This time depends on the voltage applied to the G4 input of the microcontroller. To set this value, is used, assembled from the elements R2, R3 and R1. The relay activation time is in the range from l…30 seconds.

As a key reader, you can use a ready-made head containing a two-color diode signaling the working state of the lock. The PROG jumper is used to switch the microcontroller to the key registration mode.

This scheme has been tested in Proteus:

Key Registration

In order for the lock to respond to our key, you must first register it in the microcontroller's memory. Up to 15 keys can be recorded. To switch the lock to registration mode, install the PROG jumper with the power off and turn on the power.

After that, the red LED will flash 10 times and the microcontroller will enter the key registration mode. In this case, all previously saved keys will be deleted from the memory. From now on, the keys to be registered should be attached to the reader in turn.

If an error occurs during registration, this key will not be saved and you must reattach it. An erroneous read from the DS1990 will be indicated by the red LED for one second, while a correct read will be indicated by the green LED.

Errors during transmission can be caused by interference when the key is applied to the reader, so to be sure that the key is read correctly, it should be applied for about two seconds.

After writing the fifteenth key, the microcontroller will exit the key writing procedure and further saving will be impossible. This state is signaled by simultaneous flashing of both LEDs. Now you need to turn off the power and remove the PROG jumper. After the power is turned on again, the lock will be ready for operation.

In a situation where it is not necessary to register all 15 keys, after entering the required number of keys into the microcontroller's memory, turn off the power from the lock and remove the PROG jumper. Only the specified keys will be stored in memory, and only the microcontroller will respond to them.

In normal operation, the microcontroller constantly checks to see if a registered key has been attached to the reader. If an unregistered key is detected, the red diode will light up for one second, and when you touch the registered key reader, it will turn on the lock relay, depending on the position of jumper J2.

The whole circuit fit on a single-sided printed circuit board measuring 34 × 46 mm.

Please note that all changes to the lock configuration, such as changing the relay on time or selecting the operating mode (J2), will only be active after turning the lock supply voltage off and on again.

(30.6 Kb, downloaded: 1 349)