Shop OBEX P1 Docs P2 Docs Learn Events
Using multiple tags with 28140 RFID reader?? — Parallax Forums

Using multiple tags with 28140 RFID reader??

DavidNymanDavidNyman Posts: 52
edited 2013-10-10 15:58 in BASIC Stamp
I've purchased the 28140 RFID reader and 25 of the blue FOB keychain cards. I'm far from an expert at programming so I've been trying to modify the RFID1.bs2 program I found on the main site. I managed to answer my own question by deleting the "show_name" subroutine. I've posted the code here for anyone needing to use multiple tags. The green led will tie to a 2n3904 and switch a reed relay. I'll run a bigger relay through the reed's contacts. The bigger relay will run the 24vdc magnetic lock.



' =========================================================================
'
' File....... RFID.BS2
' Purpose.... RFID Tag Reader / Simple Security System
' Author..... (c) Parallax, Inc. -- All Rights Reserved
' E-mail..... support@parallax.com
' Started....
' Updated.... 09 SEPT. 2005
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================


'
[ Program Description ]
'
' Reads tags from a Parallax RFID reader and compares to known tags (stored
' in EEPROM table). If tag is found, the program will disable a lock.


'
[ Revision History ]


'
[ I/O Definitions ]

Enable PIN 0 ' low = reader on
RX PIN 1 ' serial from reader
LED_Red PIN 15 ' Green LED
LED_Green PIN 14 ' Red LED


'
[ Constants ]

#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T4800 CON 188
T9600 CON 84
T19K2 CON 32
TMidi CON 12
T38K4 CON 6
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T4800 CON 500
T9600 CON 240
T19K2 CON 110
TMidi CON 60
T38K4 CON 45
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T4800 CON 813
T9600 CON 396
T19K2 CON 188
TMidi CON 108
T38K4 CON 84
#ENDSELECT

SevenBit CON $2000
Inverted CON $4000
Open CON $8000
Baud CON T2400


#SELECT $STAMP
#CASE BS2, BS2E
TmAdj CON $100 ' x 1.0 (time adjust)
FrAdj CON $100 ' x 1.0 (freq adjust)
#CASE BS2SX
TmAdj CON $280 ' x 2.5
FrAdj CON $066 ' x 0.4
#CASE BS2P
TmAdj CON $3C5 ' x 3.77
FrAdj CON $044 ' x 0.265
#CASE BS2PE
TmAdj CON $100 ' x 1.0
FrAdj CON $0AA ' x 0.665
#CASE BS2PX
TmAdj CON $607 ' x 6.03
FrAdj CON $2A ' x 0.166
#ENDSELECT


LastTag CON 25


#DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM?


'
[ Variables ]

#IF __No_SPRAM #THEN
buf VAR Byte(10) ' RFID bytes buffer
#ELSE
chkChar VAR Byte ' character to test
#ENDIF

tagNum VAR Byte ' from EEPROM table
idx VAR Byte ' tag byte index
char VAR Byte ' character from table


'
[ EEPROM Data ]

Tag1 DATA "36008D36B3" ' valid tags
Tag2 DATA "36005C90D8"
Tag3 DATA "3502107AF2"
Tag4 DATA "35021DE8C7"
Tag5 DATA "840033979C"
Tag6 DATA "35021E04F4"
Tag7 DATA "35021DD15F"
Tag8 DATA "3501D5AB7D"
Tag9 DATA "36009C0C31"
Tag10 DATA "3501D5AB4E"
Tag11 DATA "35021DD2E2"
Tag12 DATA "3501D5C068"
Tag13 DATA "35021DEC07"
Tag14 DATA "84003395AF"
Tag15 DATA "35021DC6C7"
Tag16 DATA "3A00157006"
Tag17 DATA "35021E05A2"
Tag18 DATA "35021DE148"
Tag19 DATA "3501D5B644"
Tag20 DATA "35021EB856"




'
[ Initialization ]

Reset:
HIGH Enable ' turn of RFID reader
LOW Led_Green ' lock the door!


'
[ Program Code ]

Main:
LOW Enable ' activate the reader
#IF __No_SPRAM #THEN
SERIN RX, T2400, [WAIT($0A), STR buf\10] ' wait for hdr + ID
#ELSE
SERIN RX, T2400, [WAIT($0A), SPSTR 10]
#ENDIF
HIGH Enable ' deactivate reader

Check_List:
FOR tagNum = 1 TO LastTag ' scan through known tags
FOR idx = 0 TO 9 ' scan bytes in tag
READ (tagNum - 1 * 10 + idx), char ' get tag data from table
#IF __No_SPRAM #THEN
IF (char <> buf(idx)) THEN Bad_Char ' compare tag to table
#ELSE
GET idx, chkChar ' read char from SPRAM
IF (char <> chkChar) THEN Bad_Char ' compare to table
#ENDIF
NEXT
GOTO Tag_Found ' all bytes match!

Bad_Char: ' try next tag
NEXT

Bad_Tag:
tagNum = 0
HIGH Led_Red
PAUSE 1000
LOW Led_Red
GOTO Main

Tag_Found:
HIGH Led_Green ' Light green LED
PAUSE 1000
LOW Led_Green ' turn off green LED
GOTO Main

END

Comments

  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-10-09 18:08
    Might I ask what type of lock are you using? I have the same RFID kit and have been thinking of using RFID for my home entry and need a good lock that will work with it. Your code looks good as far as I can see. Might as well use up my Basic Stamps that I have and save my Propellers for other projects.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-10 15:58
    If I may make a suggestion...I would simply use a driver (MOSFET) in place of the 2N3904 that is capable of driving the magnetic lock if possible. The reason is that the bigger relay will most likely cause the reed relay contacts to fuse at some point unless you implement some protection for switching an inductive load like that. If you can post a link to the datasheet for the lock I (or someone else) may be able to make a suggestion.
Sign In or Register to comment.