November 22, 2024, 12:45:55 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Door lock activation program.

Started by pbronson, March 11, 2008, 07:31:01 PM

Previous topic - Next topic

pbronson

Jon,
Could you look at the following program that I got from a friend. It activates a 5V reed relay to complete continuity across two contacts to open a Weiser Powerbolt door lock. All that is requires to open the lock is to connect two contact points within the lock. It is activated by RFID tags. I have built the board with the 5V regulator for the reader and the relay for the lock and have checked the continuity of the sockets and jumpered the sockets to insure that the relay is working properly but it doesn't seem to work. Maybe it is the program which is why I am asking you to look at it for me. I have entered the Tag IDs and have checked that the reader is working.

Thanks - Pete

' =========================================================================
'
'   File....... RFID_DoorDemo.BS2
'   Purpose.... RFID Tag Reader / Simple Security System
'   Author..... Amal Graafstra -- www.rfidtoys.net
'   E-mail..... amal@rfidtoys.net
'
' =========================================================================
'
'   {$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 pull back deadbolt.
'
' -----[ I/O Definitions ]-------------------------------------------------

Latch           PIN     9                       ' Solenoid control
RFTX            PIN     2                       ' Out to PC via RF
RX              PIN     13                      ' Serial from RFID reader

' -----[ Constants ]-------------------------------------------------------

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T1200       CON     813
    T2400       CON     396
  #CASE BS2SX, BS2P
    T1200       CON     2063
    T2400       CON     1021
#ENDSELECT

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

LastTag         CON     2                       ' used in tag ID for loop

' -----[ Variables ]-------------------------------------------------------

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

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


' -----[ EEPROM Data ]-----------------------------------------------------
' valid tags
Tag1            DATA    "0415ED5523"            ' access card 1
Tag2            DATA    "0415E9C4A4"            ' access card 2


' -----[ Initialization ]--------------------------------------------------

Reset:
  LOW Latch                                     ' Deactivate lock

' -----[ Program Code ]----------------------------------------------------

Main:
  #IF __No_SPRAM #THEN
    ' wait 2 seconds for hdr + ID
    SERIN RX, T2400, [WAIT($0A), STR RFIDBuf\10]
  #ELSE
    ' wait 2 seconds for hdr + ID
    SERIN RX, T2400, [WAIT($0A), SPSTR 10]
  #ENDIF

  'output to PC via RF link
  'SEROUT RFTX, T1200, [STR RFIDBuf\10, 13, 10]
  'DEBUG STR RFIDBuf\10, CR

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 <> RFIDBuf(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:                                        ' bad tag passed
  SLEEP 2                                       ' sleep a while
  GOTO Main                                     ' go back to listening

Tag_Found:                                      ' authorized tag found
  HIGH Latch                                    ' activate relay
  PAUSE 250                                     ' keep relay open
  LOW Latch                                     ' close relay
  SLEEP 2                                       ' door open, sleep a while
  GOTO Main                                     ' go back to listening

  END

JonnyMac

The code looks fine -- I know it well as, other than the addition of the RF stuff, I wrote it! (while working for Parallax).

I sincerely hope that you're not trying to connect a 5v relay to one of the I/O pins... very bad idea.  Relays, even small ones, are inductive and kick back a reverse voltage spike when deactivated; this spike can kill an I/O pin.  They also require more current that what a microcontroller can provide from a singe I/O pin.  In a word: don't.  Get a 12v relay and connect it between V+ and the OUTx pin you want to activate the relay.

Also, troubleshoot in small steps.  You can use DEBUG to see if you actually got a tag at the beginning of the program.  Write a separate little tester program that just cycles the relay so you can verify that your connections are goo.
Jon McPhalen
EFX-TEK Hollywood Office

pbronson

Thanks Jon, I will try what you suggest.

Pete