I have an Arduino Uno setup with a MFRC522 RFID Receiver module. I am attempting to create a verification system in which I use the UID of the card to turn on an LED Here is my current code:
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Scan PICC to see UID and type...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
byte readCard[7] ;
byte cardCode[7] = E05E987;
Serial.println("Scanned PICC's UID:");
for (int i = 0; i < mfrc522.uid.size; i++) {
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
}
Serial.println("");
if (readCard == cardCode){
Serial.println("Correct Code");
return;
}
}
However, When I compile this code I am met with this error:
/root/Arduino/RFID_Check_/RFID_Check_.ino: In function 'void loop()':
RFID_Check_:28: error: 'E05E987' was not declared in this scope
byte cardCode[7] = E05E987;
^
exit status 1
'E05E987' was not declared in this scope
How can resolve this error? I have tried changing the values inbetween he square brackets to no avail.
You decare an array of 7 bytes. It seems you want to assign it a value; however, the value isn't appropriate for a byte.
To assign a hexadecimal value, you must precede it with 0x
so 0xE05E987
would be a proper hexadecimal value.
But that value is too large for a byte. You can assign the values to the array as follows:
byte cardCode[7] = {0xE0, 0x5E, 0x98, 0x07};
Any value not provided will be zero. The above has initialized cardCode[0]
through cardCode[3]
and has set the remainder to zero.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.