Hello,
So I am doing a project in Arduino UNO and got some trouble with the code for multiple connect specific users to the RFID. For example in the code below, I am trying to do so the arduino can read my card and know who the user is when I "blip" it. And the same thing should happend again but with another card and recognize that card. So my question is: How can I do so the arduino understands how to save different users card.
Here is my code so far:
int power = 7;
int led = 8;
int serNum[5];
/*
- This integer should be the code of Your Mifare card / tag
*/
int cards[][5] = {{}};
bool access = false;
void setup(){
Serial.begin(9600);
SPI.begin();
rfid.init();
/*
- define VMA100 (UNO) pins 7 & 8 as outputs and put them LOW
*/
pinMode(led, OUTPUT);
pinMode (power,OUTPUT);
digitalWrite(led, LOW);
digitalWrite (power,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 != cards[x]) {
* access = false;*
* break;*
* } else {*
* access = true;*
* }*
* }*
* if(access) break;*
* }*
* }*
* if(access){*
* Serial.println("Välkommen in");*
/*
* Valid card : Switch ON the LED for 1000 ms (1 second)
*/
* digitalWrite(greenled, HIGH);*
* delay(1000);*
/*
* Valid card : Switch ON the POWER PIN for 2000 ms (2 seconds)), the POWER PIN can activate for example a relais, controlling a doorlock)
/ _
_ digitalWrite(power, HIGH);*
* delay(2000);*
* digitalWrite(power, LOW);*
* digitalWrite(led, LOW);*
* access = false;*
* } else {*
/*
* NON-Valid card : switch ON and OFF the LED twice for 0,5 seconds
*/
* Serial.println(" Du har ingen åtkomst hit :C ");*
* digitalWrite(redled, HIGH);*
* delay(500);*
* digitalWrite(redled, LOW);*
* delay(500);*
* digitalWrite(redled, HIGH);*
* delay(500);*
* digitalWrite(redled, LOW); *
* } *
* }*
* rfid.halt();*
}