Jump to content
43oh

parallax rfid reader + back door


Recommended Posts

This is a project I have finished recently. Since I am lazy and didn't feel the need to use keys to access my apartment I decided to hook up an rfid reader to my back door, which in turn will open my breaker bar on my patio door.

It is sorta of a kludge till I can find a stepper motor to replace my rube goldberg~esqe like device.

 

How it lifts the breaker bar, it uses a solenoid to pull a large ball bearing that is attached to a string, that goes through a screw eye, then it attaches to the breaker bar.

when the correct card is scanned it pulls on the balanced ball bearing, which it will then pull on the breaker bar to unlock the patio door.

 

I use a overkill atx power supply to power everything, 12v for the solenoid, 5v for the rfid reader, and 3.3v to power the msp430. Since I have about 5 more atx power supplies sitting around, its not really a waste, just getting use out of something that taking up space in a closet.

 

Please ignore all the ScotchLoks that I use. They are one of the best way to connect 2 wires together, and also having 2 bulk containers(2 wire and 3 wire, cnt 500), makes using them a no brainer on projects or other repairs.

 

http://justinstech.org/2012/07/rfid-back-door-easy-access/

 

In the video, I am using the older code before I put the reset code in, so I had to manually reset the device every time the card was scanned.

 

I am sure that the code can be improved but it works quite well at this time. It has been tested for the past few weeks with out issues. I know my delay kludge could be improved by use of the time but this leaves options open for upgrades at a later date (like adding a stepper motor).

 

code http://justinstech.org/wp-content/uploads/2012/07/main.c

 

//******************************************************************************
//  MSP430F20xx Demo - Timer_A, Ultra-Low Pwr UART 2400 Echo, 32kHz ACLK
//  M. Buccini / L. Westlund
//  Texas Instruments Inc.
//  October 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A
//******************************************************************************
//
//  This code has been modified to work with the parallax RFID reader for 2400 baud
//  It works and all but needs improvment.
//  Modifications By Justin Solarski
//  built with MSPGCC and a Text editor...CCE and IAR specific code commented out. 
//   or removed. Delay may not work on CCE or IAR please use built in delay cycles.
//  Changed from running on the aclk/32K crystal to 8Mhz
//  removed all TX code because its not needed	
//
//               MSP430F20xx
//            -----------------
//        /|\|              XIN|-
//         | |                 | 
//         --|RST          XOUT|-
//           |                 |
//           |          p1.7   |------\/\/>100ohm--->tip120 to solonoid
//           |                 | 2400 8N1
//           |   CCI0A/RXD/P1.1|<---------paralax RFID reader 
//
#include  
//#include                          //for string comparison
//string comparison failed do to non charactors in string...........

#define RXD       0x02                      // RXD on P1.1


//   Conditions for 2400 Baud SW UART, ACLK = 32768

#define Bitime_5  1667                      // old = 0x06 ~ 0.5 bit length + small adjustment
#define Bitime    3333                      // 0x0E = old aclk val 427us bit length ~ 2341 baud e=14




//******************************************************************************

unsigned int RXTXData;
unsigned char BitCnt;
unsigned char rfidtag[12];
unsigned int tagcnt = 0;
unsigned char tag1[12] = {0x0a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0d}; 
//tag replaced by 0xff for security reasons, I doubt any one wants to break into my place 
// but just in case they do, they will have to do it the hard way.

//******************************************************************************

void RX_Ready (void);
void __inline__ msp_delay(register unsigned int n);
void Check_rfid(void);




//******************************************************************************

void main (void)
{
 WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
   BCSCTL1 = CALBC1_8MHZ;                    // Set range
 DCOCTL = CALDCO_8MHZ;                     // Set DCO step + modulation */


 TACTL = TASSEL_2 + MC_2;                  // ACLK, continuous mode
                                           // tassel_1 =aclk tassel_2 = smclk
 P1SEL = RXD;                              //
                                           //
 P1DIR |= BIT0 + BIT7;
 P1OUT |= BIT0;
 P1OUT &= ~BIT7;
//******************************************************************************
// Mainloop
 for (;
 {
 RX_Ready();                               // UART ready to RX one Byte
 _BIS_SR(LPM0_bits + GIE);                 // Enter LPM3 w/ interr until char RXed
//******************************************************************************
//when all 12 chars are recieved
 if ( tagcnt == 12)
  { 
     Check_rfid();

  }
 else 
  { 
   rfidtag[tagcnt] = RXTXData;
   tagcnt++;
   }



 }
}
//******************************************************************************
//check if RFID matches known rfid

void Check_rfid(void)
{
unsigned char flag;
unsigned int i;
 while(1) 
  {

   for(i=0; i<12; i++)
    {
      if (rfidtag[i] == tag1[i])  // check tag against one in memory.
       { 
        flag = 0x01; 
       } //end if
     else 
      {
        flag = 0x00;

//                                     moved to flag code 0x00, it was redundant to put reset code here

//         for(i=0; i<12; i++)      //incoming data reset to 0
//          {
//           rfidtag[i] = 0;
//           }
//                                     moved to flag code 0x00, it was redundant to put reset code here
//          tagcnt = 0;
//          WDTCTL = WDT_MRST_32;                      //reset msp430 after read and execute
//          while(1){  msp_delay(50000); } 
      } //end else
    } //end for

  if (flag == 0x01)
       {
         P1OUT |= BIT7; 
         msp_delay(50000);                          //delay kludge 
         msp_delay(50000); 
         msp_delay(50000); 
         msp_delay(50000); 
         msp_delay(50000); 
         msp_delay(50000); 
         msp_delay(50000); 
         msp_delay(50000);                          //end of delay kludge

        for(i=0; i<12; i++)
         {
          rfidtag[i] = 0;
          }


         P1OUT ^= BIT7; 
         tagcnt = 0;
         WDTCTL = WDT_MRST_32;                      //reset msp430 after read and execute
         while(1){  msp_delay(50000); }  
       } //end if

   if (flag == 0x00) 
    {
        for(i=0; i<12; i++)
         {
          rfidtag[i] = 0;
          }
         tagcnt = 0;
         WDTCTL = WDT_MRST_32;                      //reset msp430 after not the correct tag
         while(1){  msp_delay(50000); }  
     }


  } //end while

}


//******************************************************************************
// delay loop used for mspgcc, if using IAR or CCE please replace with delay cycles

void __inline__ msp_delay(register unsigned int n)
{
  __asm__ __volatile__(
" 1: \n"
" dec %[n] \n"
" jne 1b \n"
     : [n] "+r"(n));
}
//******************************************************************************
// Function Readies UART to Receive Character into RXTXData Buffer
void RX_Ready (void)
{
 BitCnt = 0x8;                             // Load Bit counter
 CCTL0 = SCS + OUTMOD0 + CM1 + CAP + CCIE;   // Sync, Neg Edge, Cap
}
//******************************************************************************
// Timer A0 interrupt service routine
//#pragma vector=TIMERA0_VECTOR
//__interrupt void Timer_A (void)

__attribute__((interrupt(TIMERA0_VECTOR)))
void CCR0_ISR(void)
{
 CCR0 += Bitime;                           // Add Offset to CCR0


   if( CCTL0 & CAP )                       // Capture mode = start bit edge
   {
   CCTL0 &= ~ CAP;                         // Switch from capture to compare mode
   CCR0 += Bitime_5;
   }
   else
   {
   RXTXData = RXTXData >> 1;
     if (CCTL0 & SCCI)                     // Get bit waiting in receive latch
     RXTXData |= 0x80;
     BitCnt --;                            // All bits RXed?
     if ( BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
     {
     CCTL0 &= ~ CCIE;                      // All bits RXed, disable interrupt
     _BIC_SR_IRQ(LPM0_bits);               // Clear LPM3 bits from 0(SR)
     }
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
   }

}

 

If you have any suggestions, questions or criticism please let me know

 

**edit**

there are pictures of the each component on my blogpost that is linked above

Link to post
Share on other sites

Useful! As opposed to a stepper motor you could use a dc motor, they make gear drive motors that might even be able to take over as the hinge for the stick.

 

Also, you could drill the door and track to use the solenoid for locking instead of using the stick at all. I did this in my old apartment so I could open the door a bit and put a metal pin in it for air circulation at night.

Link to post
Share on other sites

I considered using DC motors but I have use extra circuitry to tell it to stop when its at its peak or when it closed. If I had a different breaker bar I probably would have used the dc motor.

 

with a stepper motor you can count steps and tell it to stop after so many steps, and then decrement the steps back to the down position.

 

I like the steel pin idea, that just might be the next upgrade.

Link to post
Share on other sites

Do you have some software or some device to "program" the RFID card? Just wondering what you use for that... I assume you can encode some info on it like a credit card mag strip.

 

Also re: your code...I think that __delay_cycles() works on MSPGCC unless I am misunderstanding what you are doing??

Link to post
Share on other sites

the rfid tags are static, they come pre-programed. (145khz em41000 family of cards.)

there is a parallax rfid reader with programable cards. which you can encode your own data through the rfid reader but last time I checked it was a bit pricey.

 

No misunderstanding on the code, it just needs to pulse the solenoid for a moment. Just long enough to overcome the spring and weight of the weight.

as for the delay_cycles(), I have an older version of mspgcc, which does not support it.

once I finish my lfs + blfs (linuxfromscratch) (x-window +other essential sw) box I will have an updated version that will support that call.

I'm curious on the code behind delay_cycles (), my guess its something similar to what I'm using now.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...