iButton Electronic Lock
Since iButton DS1990A introduced in market from Dallas Semiconductor (MAXIM), it has been used in many applications concerning security, access control systems etc. In this project we will use iButton as a key to an electronic lock. This electronic lock can use many different kinds of iButtons and can store up to 9 different keys. One of the keys is the master key and is permanent stored in memory. With the use of master key we can add or remove slave keys.
This electronic lock can be used with any type of iButtons you may already have, since the only thing needed is the internal serial number, that’s different for every iButton. The command used to read the serial number is the same for all iButtons. The iButton family code that goes with every iButton, can be anything and is calculated as part of the whole serial number. We must also notice that DS1990A series iButtons are the cheapest.
Schematic diagram is shown at figure 1. The circuit is build around an Atmel AT89C2051(U1) microcontroller. The port 1 (P1) of mcu is used to connect a 7-segment common anode led display. This led display will be used on the programming of additional keys. For the same reason a push-button labelled SB1 is connected on P.3.7. Storage of iButtons serial numbers is done on a 24C02 EEPROM (U3). It is connected on P3.4 (SDA) and P3.5 (SCL) of U1. The external iButton socked is connected on port P3.3 via XP2 pin array. The rest of components VD4, R3, VD5 and VD6 are used for protection of mcu ports. One pull-up resistor R4 is used as required from 1-wire protocol. An additional iButton socket is connected parallel with the predefined at pins XS1. This one is used for programming the keys. The door OPEN button is connected on P3.2 through XP1 connector, using the same protection components as above. The solenoid that does the lock is connected on XT1 connector. Solenoid is controlled from a power MOSFET IRF540 (VT3). Diode VD7 is added to protect MOSFET from voltage strikes due to solenoid inductance. Transistor VT3 is controlled from VT2, which reverses the logic state that’s appears on P3.0, so on VT3 we have output 0V and 12V. This additional transistor is useful as it translates the mcu logic levels to 0V and 12V, capable to drive the solenoid.
|Fig1: Schematic Diagram|
Overall board dimensions are 150х100х60mm. The most components are placed on the board, including the transformer. Batteries are placed on battery holders. In the place of AA batteries we could use a 12V sealed Lead – Acid battery. External components are connected on board with 2 or 3 pin connectors. Part numbers HG1, SB1 and XS1 are used only in programming mode so can be placed inside the plastic enclosure. Led VD3 can be placed on the face of enclosure, to indicate proper powering of board. A connection diagram is show on figure 2.
|Fig 2:Connection Diagram|
The electronic lock can register 9 keys, plus one master key. Master’s serial number is stored inside mcu. The rest of keys are stored on the external memory under slot 1 to 9. To add or remove a new key you should have the master key. Also master key can be used to open the door.
|Fig 3: Programming Steps for adding a new key|
To add a new key, the following steps should followed:Press programming button.
Led displays letter «P» that indicated you entered programming mode.
Touch the master button in socket.
Led displays number «1». That’s the current selected slot in memory.
Push the programming button to select a different programming slot for your new key.
Touch the new key to the socket.
The number on led display blinks, indicating ready to program.
Touch again the new key to confirm registration to memory.
If successfully registered the display stops blinking.
After 5 seconds, the program exits from programming mode.
The programming procedure to register a new key is displayed schematically on figure 3.
If you want to register more keys, then from step 9 you can go directly to step 5. These steps can be revised as many times as you like.
If after step 7, you find out that you selected wrong slot number and you don’t want to loose that key, press programming button or just wait 5 seconds. When you press the button the slot number increases by one and memory hasn’t changed yet. If you wait 5 seconds, programming mode will exit and nothing is going to register in memory. Generally in any programming step, you can wait 5 second to exit programming mode.
To remove an already registered key, you follow an almost same procedure, using only the master key. Basically, it’s like registering the master key on the memory slot you would like to erase. This procedure is shown on figure 4.
|Fig 4:Programming Steps for Removing a Key|
Master’s key serial number is stored on mcu’s program memory, beginning from address 2FDH. The length of serial number is 8 bytes. The serial must be equal that is printed on top the iButton case, reading from left to right. On memory address 2FDH the control byte is registered, then on address 2FEH - 303H the next six bytes are registered, beginning with most significant byte. Finally the family code byte is stored on address 304H. For example a complete serial code should look like: 67 00 00 02 D6 85 26 01
The software block diagram shows on figure 5. The program starts, asking if a key has entered. If a key is entered, then it goes on reading the internal serial number. The next step is to check if this is the master key or another key already registered in memory. If the key is verified then the door is opened. Also the OPEN push button is checked, and if it’s pressed the door opens.
|Fig 5:Software Block Diagram|
If we don’t touch anything in a period of 5 seconds, the program exits from programming mode. Block diagrams of figure 5 and 6 are simplified, but they give as an overall sense of program functionality.
It’s upon your desire to extend the capabilities of this program, as it’s open source, to fit your special needs.
|Fig 6:Programming Mode Subprograms Block Diagram|