Components Used: -------------------------------------- 
● Arduino UNO 
● RDM6300 RFID Module with Antenna
 ● LCD 16x2 + 10k Pot 
● Micro Servo Motor + 470uF capacitor (optional) 
● LEDs & Buzzer
 ● Batteries & jumper wires

code

#include <Servo.h>
Servo servo;
int led=10;
#include <LiquidCrystal.h>
LiquidCrystal lcd (12,11,7,6,5,4);

#include <SoftwareSerial.h>
                
// Create a new serial port called RFID
SoftwareSerial RFID (2 , 3) ;     // RX and TX
 
// Here will store the data from the included chip
String idTest = "";

// Here will be stored enabled chips
// You can freely expand

String IDOK [ 5 ] = { "21005311395A" ,
                  "2100525CB39C" ,
                  "21005326DC88" ,
                  "21005310C7A5" ,
                  "0000664966" } ;
 
// In this field, we will store the received data
int data [ 14 ] ;
 
// We store the time of the last inspection chip
long lastTagReading = 0 ;
 
void setup ( )
{
  servo.attach (9);
  servo.write (90);
  
  lcd.begin (16,2);
  lcd.setCursor (0,0);
  lcd.print ("Arduino RFID");
  lcd.setCursor (0,1);
  lcd.print ("Security System");
  delay (1500);
  lcd.clear ();
pinMode(10,OUTPUT);
  lcd.setCursor (0,0);
  lcd.print ("Welcome");
  lcd.setCursor (0,1);
  lcd.print ("Sir");
  delay (1500);
  lcd.clear ();

  lcd.setCursor (0,0);
  lcd.print ("Scan the Tag");
  

  // Starts a serial port at 9600 RDIF
  RFID. begin ( 9600 ) ;    
}
 
void loop ( )
{
  delay ( 200 ) ;
  // If any sum received on data from RDIF
  if ( RFID. available ( ) > 0 )
  {
    // For every 14 pieces of data
    for ( int i = 0 ; i < 14 ; i ++ )
    {
    // Read and store data in the data field
    data [ i ] = RFID. read ( ) ;
    }
   
    // Choose from field only 2-11 Part
    // Data, where TAG
    
    for ( int i = 1 ; i < 11 ; i ++ )
    {
      // Because the data is sent in ASCI
      // Convert them to numbers
      char d = data [ i ] ;
      // And connect to each character variable idTest
      idTest = idTest + d ;
    }
   
   
   // Using the Scan () - declared mine
   // Compare whether the chip between authorized
   // But only when the last scan was
   // Maximum of 4 seconds ago
   
  if ( ( ( lastTagReading + 4000 ) < millis ( ) ) )
   {
     // Save the time of the last scanning chip
     lastTagReading = millis ( ) ;
     if ( check ( ) == 1 )
       // If so rightID execute the function ()
       RightID ( ) ;
       
       
    // If not as a function wrongID
    else WrongID ( ) ;  
   }
   
  }
 
  // Id and finally erase the chip under test
    idTest = "" ;
}
 
//////////////////////////////////////////////
// Function compares the test chip with stored
// If he finds it returns 1, if not so 0

int check ( ) {
  int i ;
 
  for ( i = 0 ; i < sizeof ( IDOK ) ; ++ i ) {
        if ( IDOK [ i ] == idTest )
    {
      return 1 ;
    }
  }
  return 0 ;
}


void RightID ( )
{
  
  lcd.setCursor (0,1);
  lcd.print ("Tag Accepted");
  delay (1000);
  lcd.clear ();
 
  
  // Relay switches for electric lock
  servo.write (180);
   digitalWrite (10, HIGH);
  // Play tone
  tone ( 8 , 2200 , 600 ) ;
  // Wait 2.5 seconds and turns off the relay
  delay ( 4000 ) ;


   digitalWrite (10, LOW);
  servo.write (90);


  lcd.setCursor (0,0);
  lcd.print ("Scan the Tag");
}
 
void WrongID ( )
{
  digitalWrite (13, HIGH);
  delay (1000);
  digitalWrite (13, LOW);
  delay (1000);

  lcd.clear ();

  lcd.setCursor (0,1);
  lcd.print ("Tag Rejected");
  delay (1000);
  lcd.clear ();
  
// Plays three tones for not allowing access
tone ( 8 , 1200 , 150 ) ;
delay ( 300 ) ;
tone ( 8 , 1200 , 150 ) ;
delay ( 300 ) ;
tone ( 8 , 1200 , 150 ) ;
}

No comments

Theme images by Dizzo. Powered by Blogger.