Tuesday, 17 February 2015

RFID + GSM + PIR MOTION SENSOR FOR DOOR CONTROL SECURITY SYSTEM

Am going to talk about door control system using RFID and GSM for security alert system when wrong tag is detected. In this project i will talk about the little challenges you could encounter when working with RFID projects.
The RFID reader i used is the EM-18 READER MODULE

                                                     Image result for rfid em18

Description:This is a great little RFID Reader Module from Innovations, simillar to the ID models (the difference being no silicone protection on the back). If you need an inexpensive way to get started with RFID, this is a great little module. Just power the module, and it will read any RFID card within range.

It will output the cards ID in a serial string, which can easily be read by any microcontroller. The spacing on the pins is 2.54 mm, which means the module will directly fit on a breadboard.

Here is a great little tutorial we did, to help you get started with this module!

Note: This Module will not work the the Atmega32u2 Developement Board.

Features:
  • 5V supply
  • 125kHz read frequency
  • EM4001 64-bit RFID tag compatible
  • 9600bps TTL and RS232 output
  • Magnetic stripe emulation output
  • 100mm read range

Here is little article on how RFID works

Radio-frequency identification (RFID) is the wireless use of electromagnetic fields to transfer data, for the purposes of automatically identifying and tracking tags attached to objects. The tags contain electronically stored information. Some tags are powered byelectromagnetic induction from magnetic fields produced near the reader. Some types collect energy from the interrogating radio waves and act as a passive transponder. Other types have a local power source such as a battery and may operate at hundreds of meters from the reader. Unlike a barcode, the tag does not necessarily need to be within line of sight of the reader, and may be embedded in the tracked object. Radio frequency identification (RFID) is one method for Automatic Identification and Data Capture (AIDC).
RFID tags are used in many industries. An RFID tag attached to an automobile during production can be used to track its progress through the assembly line. Pharmaceuticals can be tracked through warehouses. Livestock and pets may have tags injected, allowing positive identification of the animal.
Since RFID tags can be attached to cash, clothing, possessions, or even implanted within people, the possibility of reading personally-linked information without consent has raised serious privacy concerns.

A radio-frequency identification system uses tags, or labels attached to the objects to be identified. Two-way radio transmitter-receivers called interrogators or readers send a signal to the tag and read its response.
RFID tags can be either passive, active or battery-assisted passive. An active tag has an on-board battery and periodically transmits its ID signal. A battery-assisted passive (BAP) has a small battery on board and is activated when in the presence of an RFID reader. A passive tag is cheaper and smaller because it has no battery; instead, the tag uses the radio energy transmitted by the reader. However, to operate a passive tag, it must be illuminated with a power level roughly a thousand times stronger than for signal transmission. That makes a difference in interference and in exposure to radiation.
Tags may either be read-only, having a factory-assigned serial number that is used as a key into a database, or may be read/write, where object-specific data can be written into the tag by the system user. Field programmable tags may be write-once, read-multiple; "blank" tags may be written with an electronic product code by the user.

                                 
RFID tags contain at least two parts: an integrated circuit for storing and processing information, modulating and demodulating a radio-frequency (RF) signal, collecting DC power from the incident reader signal, and other specialized functions; and an antenna for receiving and transmitting the signal. The tag information is stored in a non-volatile memory. The RFID tag includes either fixed or programmable logic for processing the transmission and sensor data, respectively.
An RFID reader transmits an encoded radio signal to interrogate the tag. The RFID tag receives the message and then responds with its identification and other information. This may be only a unique tag serial number, or may be product-related information such as a stock number, lot or batch number, production date, or other specific information. Since tags have individual serial numbers, the RFID system design can discriminate among several tags that might be within the range of the RFID reader and read them simultaneously.
 RFID Card 125 kHz                RFID Key Fob 125 kHz (Black Or White)                     RFID/NFC Card 13.45MHz


EM-18 RFID Reader Module is the one the most commonly used module for Radio Frequency Identification Projects. It features Low Cost, Small Size, Low Power Consumption and Easy to use. It can be directly interfaced with microcontrollers using UART communication. Software UART can be used for microcontrollers having no UART modules. In this tutorial we will see How to Interface EM-18 RFID Reader Module with PIC 16F877A Microcontroller. By understanding the basic idea, you will be able to interface it with any microcontrollers.

The EM-18 RFID Reader module generates and radiates RF Carrier Signals of frequency 125KHz through its coils. When a 125KHz Passive RFID Tag (have no battery) is brought in to this field, will get energized from it. These RFID Tags are usually made using a CMOS IC EM4102. It gets enough power and master clock for its operations from the electromagnetic fields produced by RFID Reader.
RFID - System Principle


                                                    MODE OF OPERATION


The microcontroller used in this project is the popular PIC18F2550 made from microchip technology which i interfaced with PIR motion sensor, SIM300 GSM module and EM-18 Reader. The mirocontroller communicates with the gsm module and EM-18 reader using UART mode of communication via a max232 IC logic level converter. 

For more tutorial on this project please call me on +2348188515146


Here is the code for this project written in mikroC compiler




#define _XTAL_FREQ 12000000


sbit LCD_RS at RB6_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;


sbit LCD_RS_Direction at TRISB6_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;
// End LCD module connections

                unsigned char waste,i=0,pp,str[14],cnt,cnt1,fnt,waste1,nn,tt[]="  ",bn;
               const char TAG1[] = {0x67,0x32,0xE6,0xA6,0x26,0x79,0x22,0x2A,0xEE,0x1A,0x3E};
               const char TAG2[] = {0x67,0x32,0xE6,0xA6,0xE6,0xE9,0x26,0xF2,0xFA,0x1A,0x22};
               const char TAG3[] = {0x67,0xCC,0xE6,0x66,0x26,0x79,0xE6,0x2E,0xE6,0xE6,0X2E};
               const char TAG4[] = {0x67,0xCC,0xE6,0x66,0xA6,0xCC,0x66,0xE9,0x1A,0x36,0x22};
               
Asciitohex(unsigned char asc){
                         unsigned  char lb,mb,st1=0,st2=0;
                          lb= asc & 0x0F ;
                           if(lb==10) lb='A';
                          else if(lb==11) lb='B';
                          else if(lb==12) lb='C';
                          else if(lb==13) lb='D';
                          else if(lb==14) lb='E';
                          else if(lb==15) lb='F';
                          else lb+=48;

                          mb=  (asc &0xf0) >> 4;
                           if(mb==10) mb='A';
                          else if(mb==11) mb='B';
                          else if(mb==12) mb='C';
                          else if(mb==13) mb='D';
                          else if(mb==14) mb='E';
                          else if(mb==15) mb='F';
                          else mb+=48;

                           tt[0]= mb; tt[1]=lb;

               }


UART1_WRITE1(unsigned char dat){
                             TXREG= dat;
                             while(!TXIF);
                           delay_ms(10);
                           }

UART1_WRITE1_TEXT1(unsigned char *dat){
                      unsigned int tx =0;
                    fnt=1;
                      while(fnt != '\0'){
                      fnt= dat[tx++];
                        UART1_WRITE(fnt);
                           }
}


UART1_INIT1(unsigned int baud){
                  SPBRG = 77;
                  TXSTA.SYNC =0;
                  TXSTA.BRGH =1;
                  TXSTA.TXEN = 1;
                  PIE1.RCIE=1   ;
                  INTCON.GIE =1 ;
                  INTCON.PEIE=1 ;
                  RCSTA.SPEN =1;
                  RCSTA.CREN =1;


                     }



void interrupt (){
    if(RCIF){
    waste = RCREG;
    if(waste == 0x67) pp=0;
    str[pp++]=waste;
    i=1;
         RCIF_bit =0;
    }
}
main(){
    ADCON1=0X0F;
    CMCON=0X07;
    TRISB=0; PORTB=0x00;
    TRISA=0B00000100; PORTA=0x00;

    LCD_INIT();
    LCD_CMD(_LCD_CURSOR_OFF);
    UART1_INIT1(9600);
    UART1_INIT(9600);
    PORTA.F1=1;
    LCD_OUT(1,1,"Initialising ");
    delay_ms(1000);
    UART1_WRITE1_TEXT1("AT\r\n");
    delay_ms(1000);
    UART1_WRITE1_TEXT1("AT+CMGF=1\r\n");
    delay_ms(1000);
    PORTA.F1=0;
    lcd_cmd(_lcd_clear);
    while(1){
        PORTA=0;
        LCD_OUT(1,3,"RFID BASED");
        LCD_OUT(2,1,"SECURITY SYSTEM");
        delay_ms(100);
        if(PORTA.F2){
               LCD_CMD(_LCD_CLEAR);
               LCD_OUT(1,4,"DOOR");
               LCD_OUT(2,1,"Opening >>>>>");
               PORTA.F1=0;
               PORTA.B0=1;
               DELAY_MS(4000);
               LCD_OUT(2,1,"Closing >>>>>");
               PORTA.B1=1;
               PORTA.B0=0;
               delay_ms(4000);
               LCD_CMD(_LCD_CLEAR);
               PORTA=0;
        }
        if(i==1){
           bn=0;
           cnt=0; cnt1=0;
           waste1=1;
           while(waste1 != '\0'){
               if(str[cnt]==TAG1[cnt]) cnt1++;
               waste1=str[cnt];
               cnt++;
           }
           if(cnt1==11) {
              bn=1;
              PORTA.B0=1;
              PORTA.B1=0;
              LCD_CMD(_LCD_CLEAR);
               LCD_OUT(1,1,"TAG 1 DETECTED");
               LCD_OUT(2,1,"Opening >>>>>");
              delay_ms(3000);
               LCD_OUT(2,1,"Closing >>>>>");
               PORTA.B1=1;
               PORTA.B0=0;
               delay_ms(3000);
              PORTA=0;
               LCD_CMD(_LCD_CLEAR);
           }
            else PORTA.B0=0;

          if(cnt1 !=10){
           cnt=0; cnt1=0;
           waste1=1;
            while(waste1 != '\0'){
               if(str[cnt]==TAG2[cnt]) cnt1++;
               waste1=str[cnt];
               cnt++;
           }
           if(cnt1==11) {
           bn=1;
              PORTA.B0=1;
              PORTA.B1=0;
              LCD_CMD(_LCD_CLEAR);
               LCD_OUT(1,1,"TAG 2 DETECTED");
               LCD_OUT(2,1,"Opening >>>>>");
          delay_ms(3000);
               LCD_OUT(2,1,"Closing >>>>>");
               PORTA.B1=1;
               PORTA.B0=0;
          delay_ms(3000);
               PORTA=0;
               LCD_CMD(_LCD_CLEAR);
           }
            else PORTA.B0=0;
           }
           if(cnt1 !=10){
           cnt=0; cnt1=0;
           waste1=1;
            while(waste1 != '\0'){
               if(str[cnt]==TAG3[cnt]) cnt1++;
               waste1=str[cnt];
               cnt++;
           }
           if(cnt1==11) {
           bn=1;
              PORTA.B0=1;
              PORTA.B1=0;
              LCD_CMD(_LCD_CLEAR);
               LCD_OUT(1,1,"TAG 3 DETECTED");
               LCD_OUT(2,1,"Opening >>>>>");
              delay_ms(3000);
               LCD_OUT(2,1,"Closing >>>>>");
               PORTA.B1=1;
               PORTA.B0=0;
               delay_ms(3000);
               PORTA=0;
               LCD_CMD(_LCD_CLEAR);
           }
            else PORTA.B0=0;
           }

           if(cnt1 !=10){
           cnt=0; cnt1=0;
           waste1=1;
            while(waste1 != '\0'){
               if(str[cnt]==TAG4[cnt]) cnt1++;
               waste1     =str[cnt];
               cnt++;
           }
           if(cnt1==11) {
           bn=1;
                PORTA.B0=1;
                PORTA.B1=0;
              LCD_CMD(_LCD_CLEAR);
               LCD_OUT(1,1,"TAG 4 DETECTED");
               LCD_OUT(2,1,"Opening >>>>>");
               delay_ms(3000);
               LCD_OUT(2,1,"Closing >>>>>");
               PORTA.B1=1;
               PORTA.B0=0;
              delay_ms(3000);
               PORTA=0;
              LCD_CMD(_LCD_CLEAR);
           }
            else PORTA.B0=0;
           }
           if((bn==0)){
               LCD_CMD(_LCD_CLEAR);
               LCD_OUT(1,2,"TAG DETECTED");
               LCD_OUT(2,4,"ERROR");
              DELAY_MS(100);
               UART1_WRITE1_TEXT1("ATD08188515146;\r\n");
               delay_ms(6000);
               LCD_CMD(_LCD_CLEAR);
           }
           i=0;
           }
       }

    }

Here are some pics

tags

tags

design construction

Door mechanism,Sim300,controller board

wires

Power supply ,gsm module and PIR motion sensor



Power supply + PIC18F2550 Controller Board + GSM MODULE


LCD + RFID READER





1 comment: