top of page

Arduino-RFID

#include <deprecated.h>
#include <MFRC522.h>
#include <MFRC522Extended.h>
#include <require_cpp11.h>

#include <SPI.h>
#include <MFRC522.h>
 
#define SS_PIN  53
#define RST_PIN 5
#define lightled 4
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
//int LEDpins=1;


void setup() 
     {
     Serial.begin(9600);   // Initiate a serial communication
     SPI.begin();      // Initiate  SPI bus
     mfrc522.PCD_Init();   // Initiate MFRC522
     Serial.println("Approximate your card to the reader...");
     Serial.println();
     pinMode(lightled,OUTPUT);

     }


void loop() 
  { 
      // Look for new cards
      if ( ! mfrc522.PICC_IsNewCardPresent()) 

      {
     return;
      }


      // Select one of the cards
      if ( ! mfrc522.PICC_ReadCardSerial()) 
      {
      return;
      }


      //Show UID on serial monitor
      Serial.print("UID tag :");
      String content= "";
      byte letter;
      for (byte i = 0; i < mfrc522.uid.size; i++) 


      {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
      Serial.print(mfrc522.uid.uidByte[i], HEX);
      content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
      content.concat(String(mfrc522.uid.uidByte[i], HEX));
      }


      Serial.println();
      Serial.print("Message : ");
      content.toUpperCase();
      if (content.substring(1) == "99 CF 22 A4") //change here the UID of the  card/cards that you want to give access

 

      {
      digitalWrite(lightled,HIGH);
      Serial.println(" AMBULANCE");
      Serial.println();
      delay(3000);
      }
 
      else   {
     digitalWrite(lightled,LOW);
     Serial.println(" CARS");
     delay(3000);
      }
  }

CCS Compiler

#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_ENABLE_PIN PIN_D2
#define LCD_DATA4 PIN_D3
#define LCD_DATA5 PIN_D4
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D6
//===============================================
#include <18f4520.h>                /Header file PIC18f4550 definitions/
#device ICD=TRUE
#fuses XT,NOLVP,NOWDT
#fuses NOMCLR INTRC_IO
#use delay(clock=4000000)
#include <lcd.c>
#FUSES XT,NOWDT,NOPUT,NODEBUG,NOLVP,NOPROTECT
#use delay (clock=4000000)
#use rs232 (baud=9600,xmit=PIN_C6,rcv=PIN_C7, bits=8,parity=N,stream=TST)


char input[4]={0x00,0x00,0x00,0x00};

#INT_RDA

void main()
   {    int i;
        SET_TRIS_B(0x00); 
        SET_TRIS_A(0x00); 
        SET_TRIS_C(0XFF);
      
    lcd_init(); /* Set direction of PORTB as OUTPUT to which LED is connected */
      
    while(1){
        int sound = INPUT(PIN_C4);  //receiving input from sound sensor
        int rfid = INPUT(PIN_C5); //receiving input from rfid sensor
        if((rfid==1) && (sound==0))
      

         {    

            for(i=60;i>0;i--){
                  printf(lcd_putc,"\f EMERGENCY!! \n");   
                  printf(lcd_putc,"   TIME: %2d",i);
                  OUTPUT_HIGH(PIN_B4);
                  OUTPUT_HIGH(PIN_B0);
                  OUTPUT_HIGH(PIN_A0);
                  delay_ms (1000);

                } 
         }


        else 
        {        
            OUTPUT_HIGH(PIN_B4);
            OUTPUT_LOW(PIN_B0);
            OUTPUT_LOW(PIN_A0);
            printf(lcd_putc,"\fHave a Nice Day! \n");
            delay_ms(1000);  
        };
    
   

     
        
     } 
        while(1);
    
  }

- Arduino's output controls the sound sensor by detecting the cards tag number.

- So, if the output is HIGH then the sound sensor will be functioning.

 

© 2019 by Vulcans. Proudly created with Braininess

  • Facebook Social Icon
  • Twitter Social Icon
  • Instagram Social Icon
bottom of page