Ever since the introduction of the iButton DS1990A by Dallas Semiconductor (MAXIM) into the market, it has found widespread applications in the realms of security and access control systems. Within the context of this project, we intend to employ the iButton as a means to operate an electronic lock. This particular electronic lock has the versatility to accommodate various types of iButtons and can store up to 9 distinct keys. Among these keys, one holds the status of a master key, permanently residing in the device’s memory. The master key grants us the capability to add or remove subordinate keys.
Notably, this electronic lock is compatible with a range of iButton variants that you might already possess. The sole requirement is the knowledge of the internal serial number, which differs for each iButton. The command utilized to retrieve this serial number remains consistent across all iButtons. Furthermore, it’s worth mentioning that the iButton family code, unique to each iButton, can assume various values and is determined as a part of the complete serial number. It’s important to highlight that the DS1990A series of iButtons is renowned for their cost-effectiveness.
This self-contained electronic lock is straightforward to assemble. From the user’s perspective, typically located outside the door, it features an iButton socket and an LED indicator. Inside the door, access is granted via a simple push button. The actual locking mechanism for the door employs a solenoid and a bolt, with the solenoid requiring a 12Vdc rating. The stored serial numbers of the iButtons in memory can be edited and updated as needed, with a single master key serving as the keyholder for all iButtons. In total, the device can store up to 9 unique keys.
The schematic diagram, depicted in Figure 1, outlines the circuitry. The core of the system is based on an Atmel AT89C2051 (U1) microcontroller. Port 1 (P1) of the microcontroller is utilized to interface with a 7-segment common anode LED display, which facilitates the programming of additional keys. To aid in this programming, a push-button labeled SB1 is connected to P3.7. The iButton serial numbers are stored in a 24C02 EEPROM (U3), connected to P3.4 (SDA) and P3.5 (SCL) of U1. The external iButton socket interfaces with port P3.3 via the XP2 pin array. Additional components, namely VD4, R3, VD5, and VD6, are incorporated to safeguard the microcontroller ports. A pull-up resistor, R4, adheres to the requirements of the 1-wire protocol. Another iButton socket is connected in parallel with predefined pins at XS1, designated for key programming.
The door’s “OPEN” button is linked to P3.2 through the XP1 connector, employing the same protective components mentioned above. The solenoid responsible for locking the door connects to the XT1 connector. Control of the solenoid is managed by a power MOSFET, specifically the IRF540 (VT3). Diode VD7 is included to shield the MOSFET from voltage surges resulting from solenoid inductance. Transistor VT3 is governed by VT2, which inverts the logic state received from P3.0, ensuring that VT3 outputs 0V and 12V. This additional transistor is beneficial as it translates the microcontroller’s logic levels into the necessary 0V and 12V levels capable of driving the solenoid.
An LED serves as an indicator for the electronic lock’s status, and its control is routed through the same pin as the solenoid, utilizing transistor TV1. This LED is linked to the board through the identical pin array, XP2. However, to guarantee the continuous functionality of the circuit without supervision, we’ve incorporated the ADM1232 (U2). This component manages the reset pin of the microcontroller (MCU) and boasts internal circuits for counting and voltage testing. On pin P3.1, the MCU generates pulses during normal operation. If, for any reason, the MCU becomes unresponsive, U2 sends a reset pulse to revive its functionality.
This electronic lock is equipped with its own onboard power supply, comprising transformer T1, bridge rectifier VD9-VD12, and voltage regulator U4. As a backup power source, an array of 10 AA batteries is employed (BT1-BT10), with a total capacity of 800mAH. When the circuit is connected to the main voltage source, the battery pack charges through R10 with a current of 20mA. This current rate, equivalent to 0.025C (with C representing the batteries’ capacity), is relatively low and ensures a gradual charge to compensate for losses over time. Consequently, no charge completion detection is necessary. Any excess energy dissipates as heat, posing no harm to the batteries due to its minimal magnitude.
The overall dimensions of the board measure 150 x 100 x 60mm. Most of the components, including the transformer, are positioned on the board itself. The batteries are secured in battery holders. Instead of AA batteries, a 12V sealed Lead-Acid battery can be utilized. External components are connected to the board through 2 or 3-pin connectors. Notably, part numbers HG1, SB1, and XS1 are solely utilized in programming mode and can be housed within the plastic enclosure. LED VD3 can be affixed to the enclosure’s surface to indicate the proper functioning of the board. A connection diagram is depicted in Figure 2.
Upon the door opening, a 3-second pulse is initiated to activate the solenoid. When we press the door open button, the door remains in the open position as long as we maintain pressure on it.
The electronic lock has the capability to store a total of 9 keys, in addition to one master key. The serial number of the master key is stored within the microcontroller (MCU). The remaining keys are housed in external memory slots, ranging from slot 1 to 9. To add or remove a new key, possession of the master key is essential. Furthermore, the master key can also be used to unlock the door.
To add a new key, the following steps should followed:
1. Press programming button.
2. Led displays letter P that indicated you entered programming mode.
3. Touch the master button in socket.
4. Led displays number 1. That’s the current selected slot in memory.
5. Push the programming button to select a different programming slot for your new key.
6. Touch the new key to the socket.
7. The number on led display blinks, indicating ready to program.
8. Touch again the new key to confirm registration to memory.
9. If successfully registered the display stops blinking.
10. 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 wish to enroll additional keys, you can jump directly from step 9 to step 5. You have the flexibility to revisit these steps as many times as needed.
In the event that, following step 7, you realize you’ve chosen an incorrect slot number and wish to retain that key, you have two options. You can either press the programming button, causing the slot number to increment by one while leaving the memory unchanged, or you can simply wait for 5 seconds. When you press the button, the slot number increases without altering the memory contents. Waiting for 5 seconds will result in exiting the programming mode, with no changes registered in the memory. In essence, during any programming step, you can opt to wait for 5 seconds to exit the programming mode.
To remove a previously registered key, you can employ a similar procedure, but solely with the master key. Essentially, it resembles the process of enrolling the master key into the memory slot you intend to erase. This procedure is visually outlined in Figure 4.
During the programming mode, access to the door is exclusively granted by pressing the OPEN button. Additionally, since both iButton sockets are connected in parallel, it is advisable to avoid simultaneous contact with keys in both sockets.
The serial number of the master key is stored in the program memory of the MCU, commencing at memory address 2FDH. This serial number spans 8 bytes and must precisely match the one imprinted on the top of the iButton case, read from left to right. At memory address 2FDH, the control byte is registered, followed by the next six bytes at addresses 2FEH to 303H, starting with the most significant byte. Lastly, the family code byte is stored at address 304H. For instance, a complete serial code should exhibit the following format: 67 00 00 02 D6 85 26 01.
The software block diagram is illustrated in Figure 5. The program initiation involves an inquiry to ascertain if a key has been inserted. If a key is detected, it proceeds to read the internal serial number. The subsequent step involves verifying whether this is the master key or another key already recorded in the memory. If the key is authenticated, access to the door is granted. Furthermore, the program monitors the OPEN push button, and if it’s pressed, the door opens.
The programming mode encompasses two distinct subprograms: PROGT and PROGS, both of which are visually depicted in Figure 6. The first subprogram, PROGT, is invoked during the programming phase when the serial number is read, while the second subprogram, PROGS, is activated when the programming button is pressed. The process of programming a new key unfolds across three phases.
Initiating the programming mode is initiated by pressing the programming button. In this state, the LED displays “P,” and the system proceeds to verify the entered key’s serial number to determine if it corresponds to the master key, which is a prerequisite for advancing through the programming steps.
If the entered key is indeed the master key, the program advances to phase 2. At this point, the LED displays the number of the currently selected memory slot, which can be changed by pressing the programming button. If we touch the key again, it is registered in memory, and the program transitions to phase 3. Registering another key similarly propels us back to phase 2. By simply pressing the button, we transition to phase 2 without registering any keys.
In the event that no action is taken for a period of 5 seconds, the program exits the programming mode. It’s important to note that while the block diagrams in Figures 5 and 6 are simplified, they offer a comprehensive overview of the program’s functionality.
The extensibility of this program to meet specific requirements is at your discretion, as it is open source and can be tailored to suit your particular needs.