Hello,
i build with my friends a garage with an arduino, my problem is the if query with or
if i change the or to and it works perfectly... now the code
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
int menuIndex = 0;
const int output_pin = 6;
void readRFID()
{
int j = -1;
byte card_ID[4]; // card UID size 4byte
const int numOfCards = 1; // the nuber of cards used. this can change as you want
byte cards[numOfCards][4] = {{0x4D, 0xD5, 0x93, 0xDA}}; // array of UIDs of rfid cards
for (byte i = 0; i < mfrc522.uid.size; i++)
{
card_ID[i] = mfrc522.uid.uidByte[i];
}
for (int i = 0; i < numOfCards; i++)
{
if ((card_ID[0] == cards[i][0]) && (card_ID[1] == cards[i][1]) && (card_ID[2] == cards[i][2]) && (card_ID[3] == cards[i][3]))
{
j = i;
}
}
if(j == -1) // check the card validity
{
Serial.println("Invalid");
menuIndex = 2;
}
else
{
Serial.println("Valid");
menuIndex = 1;
}
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(output_pin, OUTPUT);
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial) // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
{
}
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void dump_byte_array(byte *buffer, byte bufferSize)
{
for (byte i = 0; i < bufferSize; i++)
{
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
void loop()
{
switch (menuIndex)
{
case 0:
if (mfrc522.PICC_IsNewCardPresent())
{
if (mfrc522.PICC_ReadCardSerial())
{
Serial.println(F("UID:"));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
readRFID();
}
}
break;
case 1: // Access granted.
digitalWrite(output_pin, HIGH);
break;
case 2: // Acess denied.
digitalWrite(output_pin, LOW);
menuIndex = 0;
break;
default:
break;
}
}