Robert Korn
Published © MIT

Swipe Card Lock

I found this Magtek card reader in a surplus shop and thought it would look great on my shop door.

IntermediateFull instructions provided8 hours794
Swipe Card Lock

Things used in this project

Hardware components

Futaba 20x2 VFD
×1
Magtek Serial Card Reader
×1
Relay (generic)
×1
KSP-13 Darlington
×1
White LED's
×2

Story

Read more

Schematics

Schematic

Code

Arduino Sketch

Arduino
//****************************************************************
//*  Name    : Mag Swipe Door Lock Demo                          *
//*  Author  : Robert Joseph Korn                                *
//*  Notice  : Copyright (c) 2015 Open Valley Consulting Corp    *
//*  Date    : 12/18/15                                          *
//*  Version : 1.1                                               *
//*          :                                                   *
//*  Notes   :  Control Codes                                    *
//*          :  07 - Initialize Display                          *
//*          :  12 - Clear Display(must be followed by cr lf)    *
//*          :  22 - Signal Off                                  *
//*          :  23 - Signal Red                                  *
//*          :  25 - Signal Green                                *
//*          :                                                   *
//*          :  States                                           *
//*          :  0 - Waiting for Swipe                            *
//*          :  1 - Parsing Track 1                              *
//*          :  2 - Parsing Track 2                              *
//*          :  3 - Processing Swipe                             *
//*          :                                                   *
//*          :                                                   *
//****************************************************************

int SER = 0;
int state = 0;
int numlen=0;
int namlen=0;
int o=0;
char nam[255];
char num[55];
int strike = 6;
String str = "";

void setup() {

  pinMode(strike, OUTPUT);     
  digitalWrite(strike, LOW);   

  Serial1.begin(9600);
  Serial1.write(22); 
  Serial1.write(4);
  Serial1.write(12); 
  Serial1.println();
  Serial1.write(12);
  Serial1.println(" MediaTek Linkit One");
  Serial1.write(14);
  Serial1.println(" Mag Swipe Lock Demo");

}

void loop() {
   
          if( state == 3 ) 
          {  
           str = "";
           for(int o=0;o<numlen-1;o++)
             {
                  str += char(num[o]);             
             }
    
            if( str == "0123456789" ) 
            {     
              Serial1.write(12);
              Serial1.println("      Welcome       ");
              Serial1.write(14);
              
            for(int o=0;o<namlen-1;o++)
             {
               Serial1.print(char(nam[o]));             
             }
             
             Serial1.println("");
             
             delay(2500);   
             Serial1.write(25);
             digitalWrite(strike, HIGH);   
             Serial1.write(12);
             Serial1.println("   Door is Unlocked");
             Serial1.write(14);
             Serial1.println("     Please Enter");

             delay(4500);   
             Serial1.write(22);
             digitalWrite(strike, LOW);   
             Serial1.write(12);
             Serial1.println(" MediaTek Linkit One");
             Serial1.write(14);
             Serial1.println(" Mag Swipe Lock Demo");
          }else{
             Serial1.write(23);
             Serial1.write(12);
             Serial1.println("  Access is Denied");
             Serial1.write(14);
             Serial1.println("   Please Go Away");

             delay(4500);   
             Serial1.write(22);
             digitalWrite(strike, LOW);   
             Serial1.write(12);
             Serial1.println(" MediaTek Linkit One");
             Serial1.write(14);
             Serial1.println(" Mag Swipe Lock Demo");
          }
            numlen=0;
            namlen=0;
            state=0;     
          }
  
  if (Serial1.available() > 0) {
      SER = Serial1.read(); 

  switch(state)
  {
    case 0:if (SER==0x3B)  
               {
                 state=1;
               }
           if (SER==0x25)  
               {
                 state=2;
               }break;
               
    case 1:num[numlen]=SER;  
            numlen++;             
              if (SER==0x3F)  
               {
                 state=3;
               }break;
               
    case 2:nam[namlen]=SER;  
            namlen++;              
              if (SER==0x3F)  
               {
                 state=0;
               }break;
          
     default:break;
  }
 
  }

}

SwipeLockControl.pbp

Plain text
You could just use the Linkit or Arduino GPIO pins but I have many other devices that use this protocol
'****************************************************************
'*  Name    : Swipe_Door_Lock.BAS                                 *
'*  Author  : Robert Joseph Korn                                *
'*  Notice  : Copyright (c) 2015 Open Valley Consulting Corp    *
'*  Date    : 12/15/2015                                         *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
  
DEFINE  OSC     10
 
DEFINE HSER_RCSTA 90h 
DEFINE HSER_TXSTA 20h            
DEFINE HSER_BAUD 9600 
DEFINE HSER_CLROERR 1

x       var     word

        ADCON1 = $7f 

char    var     BYTE

red     VAR     PORTB.7
yellow  VAR     PORTB.6
green   VAR     PORTB.5
        
        PORTB = 0
        TRISB = $7e

        low red
        low yellow
        low green
        
        on interrupt goto serial
 
        INTCON = %11000000
        PIE1 = %00100000
 
         goto    main


' interrupt service routine        
        disable
serial:
       
        hserin 0, endisr, [char]
          
        if  char = $16 then 
            low red
            low yellow
            low green
        endif
        
        if  char = $17 then 
            high red
            low yellow
            low green
        endif
        
        if  char = $18 then 
            low red
            high yellow
            low green
        endif
        
        if  char = $19 then 
            low red
            low yellow
            high green
        endif

endisr:
        resume
        enable
        ' end of ISR
       
main:     
       pause 500
       goto main
        

Credits

Robert Korn

Robert Korn

15 projects • 27 followers
I Made the Internet of Things before people had a name for it.

Comments