You are on page 1of 4

ConstruCtion

seCure diGital aCCess system usinG iButton


Chirutkar harshadkumar Govindrao and dr h.n. Pandya

Sunil Ku

mar

ccess control forms a vital link in a security chain. Here we describe a secure digital access system using iButton that allows only authorised persons to access a restricted area. The iButton is used here as a key to the access control system. Its unique identification (ID) number is used for authorisation. On detection of an authorised iButton, the system allows access. Thereafter, an automated lock key locks the system again. The system is permanently halted after five repeated false attempts. A service control unit built around an AVR microcontroller is interfaced to the iButton with 1-wire protocol for authentication of user validation of data.

Fig. 1: Block diagram of iButton

iButton ds1990a
Here we have used the iButton DS1990A from Dallas Semiconductor (MAXIM). Its block diagram is shown in Fig. 1. An iButton is a chip housed in a stainless-steel enclosure (refer Fig. 2). The electrical interface is reduced to the absolute minimum, i.e., a single data line plus a ground reference. The energy needed for operation is taken from the data line. The DS1990A serial number iButton is a rugged data carrier that acts as an electronic registration number for automatic identification. It contains a unique ROM code that is 64-bit long as shown in Fig. 3. The first eight bits are a 1-wire family code. The next 48 bits are a unique serial number. The last eight bits are a cyclic redundancy check (CRC) of the first 56 bits. Data is transferred serially via the 1-wire protocol, which requires
w w w. e f y m ag . co m

only a single data lead and a ground return. The iButton DS1990A provides the additional 1-wire protocol capaFig. 2: A typical iButton chip bility that allows the search ROM command to be interpreted by the DS1990A.

PArts List
Semiconductors: IC1 IC2 IC3 IC4 IC5 T1 D1-D7 LED1 ATMega16 microcontroller PC817 optocoupler MAX232 RS-232 driver 7806, 6V regulator DS1990A iButton BC548 npn transistor 1N4007 rectifier diode 5mm LED

Circuit description
Fig. 4 shows the circuit of the secure digital access system using iButton. The circuit is built around an ATmega16 microcontroller. The ATmega16 is an 8-bit microcontroller based on the AVR enhanced RISC architecture that executes powerful instructions in a single clock cycle. It has 16kB in-system programmable flash program memory with readwhile-write capabilities, 512 bytes of EEPROM, 1kB SRAM, 32 generalpurpose input/output (I/O) lines, 32 general-purpose working registers, three flexible timers/counters with

Resistors (all -watt, 5% carbon): R1 - 5-kilo-ohm R2 - 1-kilo-ohm R3 - 220-ohm R4 - 10-kilo-ohm R5 - 330-ohm Capacitors: C1 C2 C3 C4-C8 1000F, 25V electrolytic 0.1F ceramic disk 3.3F, 16V electrolytic 1F, 16V electrolytic

Miscellaneous: X1 - 230V AC primary to 9V, 300mA secondary transformer RL1 - 6V, 1C/O relay PZ1 - Piezobuzzer S1 - Push-to-on tactile switch 9-pin D-type female connector

compare modes, internal and external interrupts, a serial programmable

e l e c t ro n i c s f o r yo u N o v e m b e r 2 0 1 0 1 0 7

ConstruCtion
USART, a byte-oriented two-wire serial interface, a programmable watchdog timer with internal oscillator, an SPI serial port and six software-selectable power-saving modes. Piezobuzzer PZ1 is used as an audible indicator for true, fake, random touches and system halt. It is controlled from port pin PD6 of the microcontroller with the help of transistor T1. The iButton socket is connected to port pin PD2. Pull-up resistor R1 is used as required from the 1-wire protocol. Port pin PD4 controls the relay operation through optocoupler PC817 (IC2). The door locking mechanism, say, for a slide door, is connected to the contacts of relay RL1, which closes after some time automatically. Whenever someone attempts to gain access by touching the iButton (IC5) using his own iButton, the firmware inside the AVR reads its unique ID and matches with the ID in the firmware. If the ID matches, port pin PD4 goes high, the internal LED of the optocoupler (IC2) glows and relay RL1 energises for the predefined time. Simultaneously, the buzzer sounds to indicate grant of access. Thereafter, relay RL1 de-energises. The buzzer gets the PWM signal to produce sound from port pin PD6 of the microcontroller. The 1-wire communication is done through interrupt port pin PD2 (INT0), so the AVR does not have to poll the pin but respond when any change in signal is detected on the interrupt pin. Switch S1 is used for manual reset. Port pin PD1 of the microcontroller is used to interface with the hyper terminal of the PC through RS232 interface MAX232 IC (IC3) for iButton verification and checking. The microcontroller provides a transmit channel for serial data transfer. Transmit data pin (TXD) is specified at port pin PD1. The microcontroller is connected to T1 IN (pin 11) of MAX232. T1 OUT (pin 14) of IC3 is connected to pin 2 of the COM port connector. The signals provided on these pins are TTL-level and must be boosted and inverted through a MAX232 converter to comply with the RS-232 standard. The MAX232 has two internal charge pumps that convert +5V into 10V (unloaded) for RS-232 driver operation. The first converter uses capacitor C6 to double the +5V input to +10V on capacitor C8 at pin 2. The second converter uses capacitor C5 to invert +10V to -10V on capacitor C4 at pin 6. The power supply for this circuit is derived from 230V, 50Hz AC mains. Transformer X1 steps down 230V, 50Hz AC mains to deliver a secondary output of 9V, 300 mA. The transformer output is rectified by a full-wave rectifier comprising diodes D1 through D4, filtered by capacitor C1 and regulated by IC 7806 (IC4). Capacitor C2 bypasses the ripples present in the regulated supply. LED1 acts as the power indicator and R5 limits the current through LED1.

Fig. 3: 64-bit lasered Rom

Construction and testing


An actual-size, single-side PCB for the secure digital access system is shown in Fig. 5 and its component layout in Fig. 6. Assemble the circuit on a PCB as it minimises time and assembly errors. Carefully assemble the components and double-check for any overlooked error. Connect the assembled circuit to the COM port of the computer. The iButton access code and message is transferred is to the PC through the COM port using the Hyper Terminal
w w w. e f y m ag . co m

Fig. 4: Circuit of the secure digital access system using iButton 1 0 8 N o v e m b e r 2 0 1 0 e l e c t ro n i c s f o r yo u

ConstruCtion
program. For interfacing of the Hyper Terminal, refer EFY Oct. 2010 issue. generated clock. To activate, program fuse bytes as follows: Fuse low byte = D4 Fuse high byte = 99 The source program is developed quickly with the help of the BASCOMAVR library function. The 1wrest, 1wread and 1wwrite functions are used for checking the presence of 1-wire device, reading of the unique ID of iButton and writing to the 1-wire device, respectively. Sound function is used for generating the beep sound from the buzzer. The iButton is connected to hardware interrupt pin INT0 so that any change on the pin can be detected and further processing for 1-wire done. The program execution starts by initialising the input/output ports, the interrupt pin and its level of detection. Global interrupts are enabled and the interrupt service routine is ready to be executed when any interrupt is received. As soon as the normal program execution is interrupted, an interrupt is issued and the control of execution enters the interrupt service routine, where iButton is given reset command first and then the ROM command to fetch the unique ID of the iButton. This fetched ID is compared with the unique ID programmed in the firmware. If there is a mismatch between the two IDs, a fake parameter counter is incremented and the relay connected to port PD4 de-energises. If the two IDs match, the relay connected to port PD4 energises and simultaneously the buzzer connected to port PD6 sounds. If the unique ID is wrong sequentially five times, the system enters the major warning state where the buzzer sounds continuously and it can only be stopped by resetting the system. EFY note. The source code of this project has been included in this months EFY-CD and is also available on www.efymag.com website.
Dr H.N. Pandya is a reader and head of Department of Electronics at Saurashtra University, Rajkot, and Ph.D guide of the coauthor. Chirutkar Harshadkumar Govindrao is a research scholar in Department of Electronics, Saurashtra University

software
The software for this project is given at the end of this article. It is written in Basic language and compiled using BASCOM-AVR compiler. The source program is well commented and easy to understand. Burn the finally obtained Intel hex code file into the AVRs flash memory using a suitable programmer. The microcontroller uses an 8MHz internally

Fig. 5: An actual-size, single-side PCB for the secure digital access system using iButton

Fig. 6: Component layout for the PCB

1wirereset.bas
$regfile = m16def.dat $baud = 9600 $crystal = 8000000 $hwstack = 32 default use 32 for the hardware stack $swstack = 64 default use 10 for the SW stack $framesize = 20 default use 40 for the frame space Config Portd = Output $lib mcsbyte.lbx Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Config 1wire = Portd.2 use this pin Config Int0 = Low Level Dim Ar(8) As Byte , A As Word , I As Byte , E As Byte , W As Word Dim Code1(8)as Byte Dim Flag As Bit flag for correctness Code(8 Byte) = {&H01 ,&HDD , &H83 , &H07 , &H13 , &H00 , &H00 , &H1E} Code1(1) = &H01 Code1(2) = &HDD Code1(3) = &H83 Code1(4) = &H07 Code1(5) = &H13 Code1(6) = &H00

w w w. e f y m ag . co m

e l e c t ro n i c s f o r yo u N o v e m b e r 2 0 1 0 1 0 9

ConstruCtion
Code1(7) = &H00 Code1(8) = &H1E On Int0 Int0_int Enable Interrupts Enable Int0 enable the interrupt E = 0 flag for number of attempts W = 65000 Do Set Portd.4 initially the relay is off Loop Int0_int: Disable Interrupts Disable Int0 Flag = 0 Wait 1 1wreset reset the device Print iButton Access Code:; If Err = 0 And E <= 6 Then check DS1990A is present 1wwrite &H33 present, read code read ROM command Ar(1) = 1wread(8) For I = 1 To 8 Print Hex(ar(i)); print output Next Print For I = 1 To 8 If Ar(i) <> Code1(i) Then Set Portd.4 Flag = 0 access not allowed For A = 10 To 1000 Sound Portd.6 , 4 , A Next Print Access Code Not Match:Access Denied; Print E = E + 1 Print E; Print :; Exit For Else Flag = 1 End If Next If Flag = 1 Then E = 0 Print Err; Reset Portd.4 access allowed Sound Portd.6 , 10 , 50000 siren on port PD6 Print --Access Allowed; Print Wait 2 End If Else Set Portd.4 access not allowed For A = 50 To 500 1 , A

Sound Portd.6 ,

Next Print Rejected; Print If E = 5 Then 5 attempts of correctness Do Sound Portd.6 , 4 , W SOUND pin, duration, pulses W = W + 1 If W > 1000 Then W = 10 End If Loop End If End If End If Enable Int0 Enable Interrupts Return

www.electronicsforu.com

www.eb.efyindia.com

www.linuxforu.com

www.benefitmag.com

www.ffymag.com

www.efyindia.com

1 1 0 N o v e m b e r 2 0 1 0 e l e c t ro n i c s f o r yo u

w w w. e f y m ag . co m

You might also like