Raspberry Pi Door Lock 02

 

 

I'll show you how with RFID card checker you can open the door.

 

Needed

1 RaspberryPI
1 Strike (body) mod.18-19
1 KMTronic RFID card reader 
1 KMTronic USB One Relay
recommend install Raspbian

 

 

 

Electromechanical Strike
http://www.amig.es/en/strike-body-mod-18-19/g/372

 

 

Set permissions on /dev/ttyUSB0 and ttyUSB1

sudo chmod -R 777 /dev/ttyUSB0

sudo chmod -R 777 /dev/ttyUSB1

 

 

Code RFIDCardReader.c

 

open/create file  RFIDcardReader.c and post code

 

 

 

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

int main(void) {

    struct termios serial;
    char rON[3] = {0xFF,0x01,0x01}; // USB Relay ON command
    char rOFF[3] = {0xFF,0x01,0x00}; // USB Relay OFF command    
    char inBuff[16];
    char *buffer;
 
    int rfid = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
    int relay = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NDELAY);
    
    if (rfid == -1) {
        return -1;
    }
    
    if (relay == -1) {
        return -1;
    }

    //////////////////// Set up Serial Configuration ////////////
    serial.c_iflag = 0;
    serial.c_oflag = 0;
    serial.c_lflag = 0;
    serial.c_cflag = 0;

    serial.c_cc[VMIN] = 0;
    serial.c_cc[VTIME] = 10;

    serial.c_cflag = B9600 | CS8 | CREAD;
    fcntl(rfid,F_SETFL,0);
    fcntl(relay,F_SETFL,0);
    tcsetattr(rfid, TCSANOW, &serial); // Apply configuration
    tcsetattr(relay, TCSANOW, &serial); // Apply configuration
    //////////////////////////////////////////////////////////////
 
   int rcount;  
   buffer = &inBuff[0];
    
   while(1)
  {
   buffer = &inBuff[0];    
        while( (rcount = read(rfid,buffer,1)) > 0)
        { 
            if (rcount < 0) {
                perror("Read");
                return -1;
             }
            buffer++;
           

            // Valid Card number is 0x79 0x52 0x33
            if (inBuff[0] == 0x79 && inBuff[1] == 0x52 && inBuff[2] == 0x33)
            {
               printf("%02x %02x %02x \r\n",inBuff[0],inBuff[1],inBuff[2]);
               printf("Card is recognized! \r\n");
               memset(&inBuff[0],0,3);
               write(relay, rON, sizeof(rON));
               sleep(5);
               write(relay, rOFF, sizeof(rON));
            }
            else
            {
              
            }
        }
   }

}

 

 

 

How to Compiling C Files? - View here

 

 

chmod +x RFIDCardReader 

and start file

 

 

 

 

 

 

 

 

All files here - DOWNLOAD

 

 

 

 

Read 14595 times