Electronic safety-lock with telecars as key

21,113

Circuit Image

Most of the source code for this project is based on the Telecard reader project from my website. The components are few and ordinary, which means they are low-cost and easy to find. The "keys" are empty or non-telecards (phone cards, not cell phone SIM cards) that can be found discarded in any telephone booth at no additional charge. To learn more about telecards, read the phonecards_204.zip. This circuit does not write any data to the telecard. The ATtiny26 reads the first 16 bytes of the telecard and stores them in the internal EEPROM of the ATtiny26. When a telecard is inserted into the telecard holder (slot), it presses the switch SW1. The ATtiny detects that a card has been inserted and reads the card. It temporarily saves the first 16 bytes of the card to RAM, and then searches its internal EEPROM to check if the telecard is registered in the system. If it is not registered, the Red LED will turn on. The ATtiny has 8 groups of 16 bytes each, totaling 128 bytes of EEPROM memory. With a telecard in the slot, pressing SW2 registers the card in the system. The ATtiny searches the internal EEPROM for an empty memory group (1 group = 16 bytes with $0F values). If an empty group is found, it reads the 16 bytes from RAM and stores them in the EEPROM. The ATtiny then reboots, resets the telecard, reads it again, and checks if the card is registered (by comparing the 16 bytes of the telecard with each group in the internal EEPROM). If registered, it turns off the Red LED and turns on the Green LED, while also arming the relay connected to the PB6 pin via a BC547 transistor. If there is a need to unregister any of the 8 registered telecards, insert the card into the slot, and the ATtiny will accept it (indicated by the Green LED turning on). Pressing SW3 will prompt the ATtiny to search the internal EEPROM for the 16 bytes stored and delete them by writing the value $0F to that memory group. The ATtiny will reboot, read the telecard again, compare the first 16 bytes with the internal EEPROM, and since the card is unregistered, it will turn on the Red LED. The telecard is now unregistered. It can be registered again by following the initial registration steps. If all 8 telecards are registered and an attempt is made to register a 9th card, pressing SW2 will cause the ATtiny to flash the Red and Green LEDs alternately four times. To register another telecard, one of the existing 8 must be unregistered or the entire EEPROM must be erased (writing $0F to all locations). To erase the entire EEPROM (128 bytes 0-127), press SW3 without any card inserted into the slot for 2 seconds to prevent accidental activation. In this case, the ATtiny will flash the Red LED four times, and the internal EEPROM will be cleared. The default internal EEPROM byte values are $FF. Inserting a telecard with the wrong pin orientation (reverse) will result in the ATtiny reading 16 bytes with $FF values due to the internal pull-up resistor of PB4. If the EEPROM is left at its default value ($FF), inserting any card (of telecard dimensions) and pressing switch SW1 will cause the ATtiny to read 16 bytes with $FF value (due to the internal pull-up resistor of PB4) and will arm the relay. By setting the EEPROM to $0F during the programming phase of the safety_lock.eep file of the ATtiny, the system is protected from this error. The $0F value in the source code can be replaced with a value of choice, such as $AB or $CF. It is important to replace all occurrences of $0F in the source code, not just the 128 bytes of EEPROM. The telecard base and the main circuit are built on separate boards for improved convenience.

The Telecard reader circuit utilizes an ATtiny26 microcontroller, which is programmed to manage the reading and registration of telecards. The circuit includes a telecard holder, a switch (SW1) for detecting card insertion, and two additional switches (SW2 and SW3) for registering and unregistering telecards, respectively.

When a telecard is inserted, SW1 is activated, prompting the ATtiny26 to read the first 16 bytes of data from the telecard. This data is stored temporarily in RAM for processing. The ATtiny26 then checks the internal EEPROM for existing registrations. If the telecard is not registered, it activates a Red LED to indicate that further action is required.

The registration process is initiated by pressing SW2, which triggers the ATtiny26 to search for an empty memory group in the EEPROM. If an empty group is found, the data from RAM is written into the EEPROM, and the system reboots to confirm the registration. Successful registration is indicated by the activation of a Green LED and the arming of a relay through a BC547 transistor connected to pin PB6, allowing for further control functions.

To unregister a telecard, the user must insert the card and press SW3. The ATtiny26 will locate the stored data in the EEPROM and overwrite it with the value $0F, effectively removing the registration. A subsequent reboot will confirm the unregistration by activating the Red LED.

The system is designed to handle a maximum of 8 registered telecards. If an attempt is made to register a 9th card, the ATtiny26 will signal this limitation by flashing both LEDs alternately. To accommodate additional registrations, the user must first unregister an existing card or clear the entire EEPROM.

The EEPROM can be cleared by pressing SW3 for 2 seconds without any card in the slot, ensuring that this action is intentional. Upon successful erasure, the ATtiny26 will flash the Red LED, confirming that the EEPROM has been reset to its default state.

In cases where the telecard is inserted incorrectly, the internal pull-up resistor will cause the ATtiny26 to read $FF values, which can lead to unintended relay activation. This issue is mitigated by programming the EEPROM with a safety value ($0F) to prevent erroneous operations.

Overall, this Telecard reader circuit provides a straightforward and cost-effective solution for managing telecard data, with clear visual indicators for user interaction and robust functionality for card registration and unregistration. The design emphasizes ease of use and reliability, making it suitable for various applications where telecard management is required.Most of the source code of this project its based on my Telecard reader projectof my web site. The components for this project arefew and ordinary, thatmeans low-cost and easy-to-be-found. The "keys" are empty or not telecards (Phone cards. Not cell phone SIM cards), that can befounddiscarded on any telephoneboothwith no additional charge. To learn more about telecards read the phonecards_204. zip. This circuit doesn`t write any data to the telecard. The ATtiny26 reads the 16 first bytes of telecard and then store them in to the internal eeprom of ATtiny26. When you insert any telecard in to the telecard holder (telecard`s slot) will be pressed the switch SW1.

The ATtiny will seethat a card was inserted in to the slot and reads the card. Temporary will save the 16 first bytes of the card to the RAM and after that the ATtiny will search in to its internal eeprom to see if this telecard wasregistered to the system. if not, it will turn-on the Red LED. The ATtiny has 8 groups of 16 bytes each, summary 8*16=128 bytes of eeprom memory. With any telecard in to the slot, press the SW2 forregistering the card in to the system. The ATtiny will search the internal eeprom for empty memory group (1 group=16 bytes with $0F values).

If there is empty group, it will read the 16 bytes from RAM and store them to the eeprom. Then, the ATtiny will reboot, reset the telecard, read it again and check if the card is registered (by compare the 16 bytes of telecard, with 1 group at the time, with internal eeprom). Now it will turn-off the Red LED and turn-on the green LED because we have registered this telecard in to the system.

At the same time it will arm the relay connected to PB6 pin via BC547. If for some reason youdon`t want to use any of the 8 registeredtelecard, youcan un-register it from the system. Youhave to insert this card in to the slot, the ATtiny accept it (by turn-on the green led). If we press the SW3, the ATtiny will search to internal eeprom to find were the 16 bytes werestored and delete them by write the value $0F to this memory group.

Now the ATtiny will reboot, read again the telecard, compare the first 16 bytes of the cardwith the internal eeprom and because we have un-registered this card it will turn-on the red LED. This telecard is unregistered now. We can register the card again if we want to, by follow the step 1. If we have register 8 telecards to the system and will try to register 1 more (9th), when we press SW2 to register the card, the ATtiny it will flash the Red and Green LEDs 4 times alternately.

The only way to register some other telecard, is to un-register one of the 8 already registered cards (step 2. ) or byerasingthe entire eeprom (writing the value $0F to all locations). Forerasingthe entire eeprom (128 bytes 0-127) youhave to press the SW3 button with NOT any card inserted into the slot, for 2 seconds, to ensure that we are not pressed the button SW3accidentally.

At this case the ATtiny it will flash the Red LED 4 times. After that, the internal eeprom of ATtiny will be cleared. The values of default internal eeprom bytes are $FF. If we insert the telecard with wrong pins position (reverse), the ATtiny will read 16 bytes with $FF values because of internal pull-up resistor of PB4. If we let the eeprom to default value ($FF), when we insert any card (anything with a telecard dimensions) just to press theswitch SW1, the ATtiny will read 16 bytes with $FF value (because internal pull-up resistor of PB4) and will arm the relay.

By set the eeprom to$0F value, at the phase of programming the safety_lock. eep file of ATtiny, we protect the system from this mistakes. You can replace the $0F value of the source code withthe value of yourchoice, for example $AB or $CF etc. Remeber to replace all the $0F values of the source code, not only the 128 bytes of eeprom. The telecard base and the main circuit are build them to different boards for morecommodi 🔗 External reference