Column #120: You Can’t Touch That: Non-contact Access Control Column #120 April 2005 by Jon Williams: You Can’t Touch That: Non-contact Access Control Today I had a bit of a headache and was feeling cramped in my office so I decided to escape to the treadmill for a half-hour or so in the complex's private gym. To keep it private, members gain access by waving a security card in front of a small plate adjacent to the front door – if the card is a match, cha-ching, the door unlocks and you're in.
Column #120: You Can’t Touch That: Non-contact Access Control There are two essential components in an RFID system: a transceiver (reader) and a transponder (tag). If it were only that simple.... Tags can be active (contain their own power source) or be passive (create parasitic power from the reader's RF field). Further, tags can be read-only or read-write. Zoiks.
Column #120: You Can’t Touch That: Non-contact Access Control Is It Magic? Okay, how does it work? It's not magic; in fact it's not terribly complicated. When power (5 VDC) is applied to the reader a green LED will indicate that it's ready to function. By pulling the ENABLE pin low, the reader becomes active (LED changes to red) and the antenna broadcasts a modulated signal.
Column #120: You Can’t Touch That: Non-contact Access Control Figure 120.
Column #120: You Can’t Touch That: Non-contact Access Control In this program, SERIN does all the work. We construct the SERIN line to wait for the linefeed character, then the specific characters in the valid RFID tag string. Once that shows up the program drops to the point called Access_Granted where we activate an output that will do what we need it to do. We could, for example, disable an electric door lock that gives us – and just us – access to something special.
Column #120: You Can’t Touch That: Non-contact Access Control Figure 120.4: RFID Debug Output By the way, if you happen to have the new Parallax Serial LCD module, you can use it as a terminal – and you don't need a level-shifter. Simply set the LCD Mode switches for 2400 baud (1 = Up, 2 = Down) and connect the RFID reader's SOUT pin to the LCD's RX pin.
Column #120: You Can’t Touch That: Non-contact Access Control Open Sesame Most security systems will have more than one legal user, so let's update the program to work with multiple tags. To be honest with you, I had to go back to the BS1 manual on several occasions for this program because the BS1 – while very cool – is not quite as convenient as its big brother the BS2. It's very inexpensive though (especially with OEM parts), and is worth considering for a low-cost access control system.
Column #120: You Can’t Touch That: Non-contact Access Control Note that the SERIN line is really long, but needs to be on one line to make sure that all 11 bytes (header plus 10) received are in fact received properly. For publication, I've split the line, but you'll find it all together in the downloadable version of the code. With the tag ID stored in the BS1's RAM, we can compare it to our table entries to determine whether the tag presented is a match or not.
Column #120: You Can’t Touch That: Non-contact Access Control The latch is activated (to allow entry) and then a beep is played through piezo speaker of amplifier circuit to alert the user. The beep stops after about two seconds and the door relocks. With that we go back to the top of the program. When the tag presented does not match any of our table entries a one-second groan is played through the speaker: Bad_Tag: DEBUG "Unknown Tag", CR SOUND Spkr, (25, 80) PAUSE 1000 GOTO Main And that's that.
Column #120: You Can’t Touch That: Non-contact Access Control Scratchpad as a serial buffer. The first thing we have to do, though, is setup the program so that the compiler can detect a BS2p or BS2pe and create a symbol to that effect. #DEFINE __No_SPRAM = ($STAMP < BS2P) With this definition the symbol called __No_SPRAM will be set to True if we're not using a BS2p or BS2pe – hence are forced to define a buffer in our variable RAM space.
Column #120: You Can’t Touch That: Non-contact Access Control Check_List: FOR tagNum = 1 TO LastTag FOR idx = 0 TO 9 READ (tagNum - 1 * 10 + idx), char #IF __No_SPRAM #THEN IF (char <> buf(idx)) THEN Bad_Char #ELSE GET idx, chkChar IF (char <> chkChar) THEN Bad_Char #ENDIF NEXT GOTO Tag_Found Bad_Char: NEXT As with the BS1, a loop is used to work through the known tag strings. What we're able to do here, however, is use a second loop to test each byte of the received string.
Column #120: You Can’t Touch That: Non-contact Access Control Show_Name: DEBUG DEC tagNum, ": " LOOKUP tagNum, [Name0, Name1, Name2, Name3], idx DO READ idx, char IF (char = 0) THEN EXIT DEBUG char idx = idx + 1 LOOP RETURN The result of the tag search (in the variable tagNum) will be from one to the number of known tags if the tag string is valid – if not, the search will result in zero. The Show_Name routine uses the result of the tag search to LOOKUP the first character of the corresponding name.
Column #120: You Can’t Touch That: Non-contact Access Control ' ========================================================================= ' ' File....... RFID_Reader.BS1 ' Purpose.... RFID Tag Reader ' Author..... Jon Williams, Parallax ' E-mail..... jwilliams@parallax.com ' Started.... ' Updated.... 07 FEB 2005 ' ' {$STAMP BS1} ' {$PBASIC 1.
Column #120: You Can’t Touch That: Non-contact Access Control Show_Tag: DEBUG "Tag ID: ", #@B0,#@B1,#@B2,#@B3,#@B4,#@B5,#@B6,#@B7,#@B8,#@B9 DEBUG CR PAUSE 1000 ' time to remove tag GOTO Main ' -----[ Subroutines ]----------------------------------------------------- Page 74 • The Nuts and Volts of BASIC Stamps (Volume 6)
Column #120: You Can’t Touch That: Non-contact Access Control ' ========================================================================= ' ' File....... RFID_Single.BS1 ' Purpose.... Single-tag RFID Tag Reader ' Author..... Jon Williams, Parallax ' E-mail..... jwilliams@parallax.com ' Started.... ' Updated.... 07 FEB 2005 ' ' {$STAMP BS1} ' {$PBASIC 1.
Column #120: You Can’t Touch That: Non-contact Access Control HIGH Enable Access_Granted: HIGH Latch PAUSE 2000 LOW Latch GOTO Main ' deactivate reader ' open the lock ' -- for two seconds ' relock ' -----[ Subroutines ]----------------------------------------------------- Page 76 • The Nuts and Volts of BASIC Stamps (Volume 6)
Column #120: You Can’t Touch That: Non-contact Access Control ' ========================================================================= ' ' File....... RFID.BS1 ' Purpose.... RFID Tag Reader / Simple Security System ' Author..... Jon Williams, Parallax ' E-mail..... jwilliams@parallax.com ' Started.... ' Updated.... 07 FEB 2005 ' ' {$STAMP BS1} ' {$PBASIC 1.
Column #120: You Can’t Touch That: Non-contact Access Control SYMBOL SYMBOL pntr char = B11 = B12 ' pointer to char in table ' character from table ' -----[ EEPROM Data ]----------------------------------------------------Tags: EEPROM EEPROM EEPROM EEPROM EEPROM EEPROM ("0F0184F20B") ("0F01D9D263") ("04129C1B43") ("0000000000") ("0000000000") ("0000000000") ' valid tags ' space for other tags ' -----[ Initialization ]-------------------------------------------------Reset: HIGH Enable LOW Latch ' t
Column #120: You Can’t Touch That: Non-contact Access Control IF char <> tag8 THEN Bad_Char pntr = tagNum * 10 + 9 : READ pntr, char IF char <> tag9 THEN Bad_Char GOTO Tag_Found Bad_Char: NEXT Bad_Tag: DEBUG "Unknown Tag", CR SOUND Spkr, (25, 80) PAUSE 1000 GOTO Main Tag_Found: DEBUG "Entry ", #tagNum, CR HIGH Latch SOUND Spkr, (114, 165) LOW Latch GOTO Main ' all match -- good tag ' groan ' remove latch ' beep ' restore latch END ' -----[ Subroutines ]-------------------------------------------------
Column #120: You Can’t Touch That: Non-contact Access Control ' ========================================================================= ' ' File....... RFID.BS2 ' Purpose.... RFID Tag Reader / Simple Security System ' Author..... Jon Williams, Parallax ' E-mail..... jwilliams@parallax.com ' Started.... ' Updated.... 07 FEB 2005 ' ' {$STAMP BS2e} ' {$PBASIC 2.
Column #120: You Can’t Touch That: Non-contact Access Control Main: LOW Enable SERIN RX, T2400, [WAIT($0A), STR buf\10] HIGH Enable Show_Tag: DEBUG "Tag ID: ", STR buf\10, CR PAUSE 1000 GOTO Main ' activate the reader ' wait for hdr + ID ' deactivate reader ' display ID ' time to remove tag ' -----[ Subroutines ]----------------------------------------------------- The Nuts and Volts of BASIC Stamps (Volume 6) • Page 81
Column #120: You Can’t Touch That: Non-contact Access Control ' ========================================================================= ' ' File....... RFID.BS2 ' Purpose.... RFID Tag Reader / Simple Security System ' Author..... Jon Williams, Parallax ' E-mail..... jwilliams@parallax.com ' Started.... ' Updated.... 07 FEB 2005 ' ' {$STAMP BS2} ' {$PBASIC 2.
Column #120: You Can’t Touch That: Non-contact Access Control #ENDSELECT LastTag CON 3 ' three known tags #DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM? ' -----[ Variables ]------------------------------------------------------#IF __No_SPRAM #THEN buf VAR #ELSE chkChar VAR #ENDIF tagNum idx char VAR VAR VAR Byte(10) ' RFID bytes buffer Byte ' character to test Nib Byte Byte ' from EEPROM table ' tag byte index ' character from table ' -----[ EEPROM Data ]----------------------
Column #120: You Can’t Touch That: Non-contact Access Control Check_List: FOR tagNum = 1 TO LastTag FOR idx = 0 TO 9 READ (tagNum - 1 * 10 + idx), char #IF __No_SPRAM #THEN IF (char <> buf(idx)) THEN Bad_Char #ELSE GET idx, chkChar IF (char <> chkChar) THEN Bad_Char #ENDIF NEXT GOTO Tag_Found Bad_Char: NEXT ' scan through known tags ' scan bytes in tag ' get tag data from table ' compare tag to table ' read char from SPRAM ' compare to table ' all bytes match! ' try next tag Bad_Tag: tagNum = 0 GOSUB Sh