RFiD Scanner

Announcement Date: January 1, 2016

So i needed a RFiD scanner, well for about $5 you get RC522 breakoutboard.
The data i on the card/brick i needed was the SerialNumber.

The security system i need to use is kinda backwards so i needed to get key “0” from the card it returns 228 50 26 220 16 = E4 32 1A DC A1 in HEX
i only needed 4bit and in reverse DC 1A 32 E4 = 3692704484 in DEC
the first data can be used in the code to grant access if you mount a door magnet/servo.
The HEX just data
The 10DEC code you can use i pro systems.

as i said i needed a RFiD scanner just to get the 10DEC code.

RFiD-Scanner

In this build i use :

Arduino UNO, The finished build i used an Arduino Nano
RC522 (RFID scanner/writer)
Nokia 2110 LCD

Connections:
RC522 -> Arduino

MOSI : Pin 11 ICSP-4
MISO : Pin 12 ICSP-1
SCK : Pin 13 ISCP-3
SS : Pin 10
RST : Pin 9

Nokia LCD -> Arduino

Standard Im Using
SCLK : Pin 8 Pin 2
DN : Pin 9 Pin 3
DC : Pin 10 Pin 4
SCE : Pin 11 Pin 5
RST : Pin 12 Pin 7
BL : Pin 6 Pin 6

RFID Librairy

#include <SPI.h>
#include <RFID.h>
#include <LCD5110_Basic.h>

#define SS_PIN 10
#define RST_PIN 9

RFID rfid(SS_PIN,RST_PIN);
LCD5110 myGLCD(2,3,4,7,5);
extern uint8_t SmallFont[];

int startAlarm = false;
int serNum[5];
//char cAll2[10];
int cards[][11] = 
{
  {1234567890},
  {2345678901},
  {3456789012}
};

bool access = false;

void setup(){

    Serial.begin(9600);
    SPI.begin();
    rfid.init();
    myGLCD.InitLCD();
    myGLCD.setFont(SmallFont);
    myGLCD.setContrast(70);
    analogWrite(6, 1);
}

void loop(){
    myGLCD.print("Arduino", CENTER, 0);
    myGLCD.print("RFiD Scanner", CENTER, 15);
    myGLCD.print("ID:", LEFT, 25);
    myGLCD.print(" Ready To scan ", CENTER, 40);
    analogWrite(6, 180);
    
    if(rfid.isCard()){
        if(rfid.readCardSerial()){
            Serial.print("3 Door Code     : ");
             char cAll[8];
             char *cAllP = cAll;
                cAllP += sprintf(cAllP,"%X",rfid.serNum[3]);
                cAllP += sprintf(cAllP,"%X",rfid.serNum[2]);
                cAllP += sprintf(cAllP,"%X",rfid.serNum[1]);
                cAllP += sprintf(cAllP,"%X",rfid.serNum[0]);
             unsigned long cAll1 = strtoul(cAll, NULL, 16);
             Serial.println(cAll1);
             char cAll3[11];
             String str;
             str=String(cAll1);
             str.toCharArray(cAll3,11);
             myGLCD.print(cAll3, RIGHT, 25);
            
            for(int x = 0; x < sizeof(cards); x++){
              for(int i = 0; i < sizeof(cAll3); i++ ){
                  if(cAll3[i] != cards[x][i]) {
                      access = false;
                      break;
                  } else {
                      access = true;                 }
              }
              if(access) break;
            }
           
        }
        
       if(access){
          myGLCD.print("  Scanned ok  ", CENTER, 45);
          //digitalWrite(greenPin, HIGH);
          //digitalWrite(redPin, LOW);          
       } else {
          myGLCD.print("  Not in use  ", CENTER, 45);
          //digitalWrite(redPin, HIGH);
          //digitalWrite(greenPin, LOW);         
       }        
    }
    
    if(startAlarm) {
       //digitalWrite(alarm, HIGH); 
    } else {
      //digitalWrite(alarm, LOW); 
    }
    
    rfid.halt();

}

void reset_alarm(){
    //startAlarm = false;
}