Skip to content

Instantly share code, notes, and snippets.

@winhtut
Created June 10, 2018 07:12
Show Gist options
  • Save winhtut/fb59fde8218b37b245ca07521d2694b2 to your computer and use it in GitHub Desktop.
Save winhtut/fb59fde8218b37b245ca07521d2694b2 to your computer and use it in GitHub Desktop.
rfid
#include <RFID.h>
/*
* Read a card using a mfrc522 reader on your SPI interface
* Pin layout should be as follows (on Arduino Uno):
* MOSI: Pin 11 / ICSP-4
* MISO: Pin 12 / ICSP-1
* SCK: Pin 13 / ISCP-3
* SS/SDA: Pin 10
* RST: Pin 9
*/
#include <SPI.h>
#include <RFID.h>
#define SS_PIN 10
#define RST_PIN 9
RFID rfid(SS_PIN,RST_PIN);
int led = 7;
int power = 8;
int serNum[5];
int cards[][5] = {
{5,117,21,219,190}
};
bool access = false;
void setup(){
Serial.begin(9600);
SPI.begin();
rfid.init();
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}
void loop(){
if(rfid.isCard()){
if(rfid.readCardSerial()){
Serial.print(rfid.serNum[0]);
Serial.print(" ");
Serial.print(rfid.serNum[1]);
Serial.print(" ");
Serial.print(rfid.serNum[2]);
Serial.print(" ");
Serial.print(rfid.serNum[3]);
Serial.print(" ");
Serial.print(rfid.serNum[4]);
Serial.println("");
for(int x = 0; x < sizeof(cards); x++){
for(int i = 0; i < sizeof(rfid.serNum); i++ ){
if(rfid.serNum[i] != cards[x][i]) {
access = false;
break;
} else {
access = true;
}
}
if(access) break;
}
}
if(access){
Serial.println("Welcome!");
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
digitalWrite(power, HIGH);
delay(1000);
digitalWrite(power, LOW);
} else {
Serial.println("Not allowed!");
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
}
}
rfid.halt();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment