Secure Digital Acess System Using Ibutton

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Construction

Secure Digital Access Sunil Ku


mar

System using iButton


 Chirutkar Harshadkumar
Govindrao and Dr H.N. Pandya

A
ccess control forms a vital link
in a security chain. Here we
describe a secure digital ac-
cess 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 au-
thorised iButton, the system allows ac-
cess. Thereafter, an automated lock key
locks the system again. The system is
permanently halted after five repeated Fig. 1: Block diagram of iButton
false attempts. A service control unit
built around an AVR microcontroller only a single Parts List
is interfaced to the iButton with 1-wire data lead and a Semiconductors:
protocol for authentication of user vali- ground return. IC1 - ATMega16 microcontroller
dation of data. The iButton IC2 - PC817 optocoupler
DS1990A pro- IC3 - MAX232 RS-232 driver
iButton DS1990A vides the ad-
IC4 - 7806, 6V regulator
IC5 - DS1990A iButton
Here we have used the iButton ditional 1-wire T1 - BC548 npn transistor
DS1990A from Dallas Semiconductor protocol capa- D1-D7 - 1N4007 rectifier diode
(MAXIM). Its block diagram is shown Fig. 2: A typical iButton chip bility that al- LED1 - 5mm LED

in Fig. 1. lows the search Resistors (all ¼-watt, ±5% carbon):


R1 - 5-kilo-ohm
An iButton is a chip housed in a ROM command to be interpreted by R2 - 1-kilo-ohm
stainless-steel enclosure (refer Fig. 2). the DS1990A. R3 - 220-ohm
The electrical interface is reduced to R4 - 10-kilo-ohm
the absolute minimum, i.e., a single Circuit description R5 - 330-ohm
data line plus a ground reference. The Fig. 4 shows the circuit of the secure Capacitors:
C1 - 1000µF, 25V electrolytic
energy needed for operation is taken digital access system using iButton.
C2 - 0.1µF ceramic disk
from the data line. The DS1990A serial The circuit is built around an ATme- C3 - 3.3µF, 16V electrolytic
number iButton is a rugged data car- ga16 microcontroller. C4-C8 - 1µF, 16V electrolytic
rier that acts as an electronic registra- The ATmega16 is an 8-bit micro- Miscellaneous:
tion number for automatic identifica- controller based on the AVR enhanced X1 - 230V AC primary to 9V,
300mA secondary
tion. It contains a unique ROM code RISC architecture that executes power-
transformer
that is 64-bit long as shown in Fig. 3. ful instructions in a single clock cycle. RL1 - 6V, 1C/O relay
The first eight bits are a 1-wire family It has 16kB in-system programmable PZ1 - Piezobuzzer
code. The next 48 bits are a unique flash program memory with read- S1 - Push-to-on tactile switch
9-pin D-type female
serial number. The last eight bits are a while-write capabilities, 512 bytes
connector
cyclic redundancy check (CRC) of the of EEPROM, 1kB SRAM, 32 general-
first 56 bits. purpose input/output (I/O) lines, 32
Data is transferred serially via general-purpose working registers, compare modes, internal and external
the 1-wire protocol, which requires three flexible timers/counters with interrupts, a serial programmable

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

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 as-
sembly errors. Carefully
assemble the components
and double-check for any
overlooked error. Con-
nect 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
Fig. 4: Circuit of the secure digital access system using iButton using the Hyper Terminal

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 w w w. e f y m ag . co m
Construction
program. For interfacing of the Hyper generated clock. To activate, program nected to hardware interrupt pin INT0
Terminal, refer EFY Oct. 2010 issue. fuse bytes as follows: so that any change on the pin can be
Fuse low byte = D4 detected and further processing for
Software Fuse high byte = 99 1-wire done.
The software for this project is given The source program is developed The program execution starts by
at the end of this article. It is written in quickly with the help of the BASCOM- initialising the input/output ports, the
‘Basic’ language and compiled using AVR library function. The 1wrest, interrupt pin and its level of detection.
Bascom-AVR compiler. The source 1wread and 1wwrite functions are Global interrupts are enabled and
program is well commented and easy used for checking the presence of the interrupt service routine is ready
to understand. 1-wire device, reading of the unique to be executed when any interrupt
Burn the finally obtained Intel hex ID of iButton and writing to the 1-wire is received. As soon as the normal
code file into the AVR’s flash memory device, respectively. Sound function program execution is interrupted, an
using a suitable programmer. The mi- is used for generating the beep sound interrupt is issued and the control of
crocontroller uses an 8MHz internally from the buzzer. The iButton is con- 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 pro-
grammed in the firmware. If there
is a mismatch between the two IDs,
a fake parameter counter is incre-
mented and the relay connected to
port PD4 de-energises. If the two
IDs match, the relay connected to
port PD4 energises and simultane-
ously the buzzer connected to port
Fig. 5: An actual-size, single-side PCB for the secure digital access system using iButton PD6 sounds. If the unique ID is
wrong sequentially five times, the
system enters the major warning
state where the buzzer sounds con-
tinuously and it can only be stopped
by resetting the system.
EFY note. The source code of
this project has been included in this
month’s EFY-CD and is also avail-
able 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 co-
author. Chirutkar Harshadkumar Govindrao is a
research scholar in Department of Electronics,
Fig. 6: Component layout for the PCB Saurashtra University

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


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

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