Problems with code for RFID read to LCD output

Hey there,
I try to write a program, with wich I'd like to get an LCD output when I hold an RFID card in front of the RFID-reader.

The computer is the Arduino clone elegoo uno r3.

The Problem now is, that Arduino IDE I use for programming gives out:

Compilation error: expected primary-expression before '{' token

Code for this is:

#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>

#define RST_pin  9
#define SS_pin  10
#define UID {0xDE, 0xAD, 0xBE, 0xEF}

MFRC522 mfrc522(SS_pin, RST_pin);
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);

void setup(){
  lcd.begin(16,2);
  lcd.print(F("Test"));
}

void loop(){
  lcd.setCursor(0, 1);
  if (mfrc522.PICC_ReadCardSerial()==UID) {
    lcd.print(F("RFID read"));
  }

Thanks for Help
Luke Gaming911

1 Like

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Sorry this is the hole Error:
C:\Users\folkm\AppData\Local\Temp.arduinoIDE-unsaved202302-11368-pgspe0.64ukf\sketch_jan2a\sketch_jan2a.ino: In function 'void loop()':
C:\Users\folkm\AppData\Local\Temp.arduinoIDE-unsaved202302-11368-pgspe0.64ukf\sketch_jan2a\sketch_jan2a.ino:7:13: error: expected primary-expression before '{' token
#define UID {0xDE, 0xAD, 0xBE, 0xEF}
^
C:\Users\folkm\AppData\Local\Temp.arduinoIDE-unsaved202302-11368-pgspe0.64ukf\sketch_jan2a\sketch_jan2a.ino:19:38: note: in expansion of macro 'UID'
if (mfrc522.PICC_ReadCardSerial()==UID) {
^~~
C:\Users\folkm\AppData\Local\Temp.arduinoIDE-unsaved202302-11368-pgspe0.64ukf\sketch_jan2a\sketch_jan2a.ino:7:13: error: expected ')' before '{' token
#define UID {0xDE, 0xAD, 0xBE, 0xEF}
^
C:\Users\folkm\AppData\Local\Temp.arduinoIDE-unsaved202302-11368-pgspe0.64ukf\sketch_jan2a\sketch_jan2a.ino:19:38: note: in expansion of macro 'UID'
if (mfrc522.PICC_ReadCardSerial()==UID) {
^~~
Mehrere Bibliotheken wurden für "LiquidCrystal.h" gefunden
Benutzt: C:\Users\folkm\OneDrive\Dokumente\Arduino\libraries\LiquidCrystal
Nicht benutzt: C:\Users\folkm\AppData\Local\Arduino15\libraries\LiquidCrystal
exit status 1

Compilation error: expected primary-expression before '{' token

Use memcmp.
(Don't any of the library examples show how to compare serial numbers?)

Hi @lukegaming911 ,
welcome to the Arduino-Forum.
Well done posting code as a code-section.

As you have encountered with your project changing too many things at the same time with knowing too less about programming leads to errors.

The compiler-error-messages point to where the error occured

7:13 means line 7 columm 13 inside file sketch_jan2a.ino
caused the error.

There are things to learn:

Save your sketch with a meaningful and self-explaining name.
read-RFID-LCD-001.ino or something like that

Each time you have reached a party working state of your code save the code again with a new
serial number
read-RFID-LCD-002.ino
read-RFID-LCD-003.ino
...

Start from a code that is well known as working and then do a small modification towards your aims. Test the code again if the code works as expected with the small modification.

If the code works as exepcted do another small modification.

Post the code you took as the base to start.

best regards Stefan

That is an initializer list, not a valid array. Try:
const byte UID[] = {0xDE, 0xAD, 0xBE, 0xEF};

You can't directly compare two arrays like that. If the arrays are null terminated character strings you would use 'strcmp()' but since they aren't, you have to specify the number of bytes of memory to compare:

if (memcmp(mfrc522.PICC_ReadCardSerial(), UID, 4) == 0))

@StefanL38 thanks for your explanation, the name was the original the IDE gave I later replaced it

@johnwasser thanks for your help I'll try this

@anon56112670 I didn't knew this library so I don't know how to use it

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.