RC522 NFC PC login - error in code ?!?

Hello Community :slight_smile: ,
Iam building on a automated pc login if you touch an RFID tag to the rc522 reader. I am following this tutorial on youtube -> - YouTube <- but when I try to upload the final code the IDE gives me an error:

sketch_aug11b.ino:1:10: error: #include expects "FILENAME" or
sketch_aug11b.ino:2:10: error: #include expects "FILENAME" or
sketch_aug11b:26: error: stray '' in program
sketch_aug11b:36: error: stray '' in program
sketch_aug11b:7: error: 'MFRC522' does not name a type
sketch_aug11b.ino: In function 'void setup()':
sketch_aug11b:13: error: 'SPI' was not declared in this scope
sketch_aug11b:14: error: 'mfrc522' was not declared in this scope
sketch_aug11b.ino: In function 'void loop()':
sketch_aug11b:18: error: 'mfrc522' was not declared in this scope
sketch_aug11b:22: error: 'mfrc522' was not declared in this scope
sketch_aug11b:26: error: 'mfrc522' was not declared in this scope
sketch_aug11b:36: error: expected ;' before 'u2039' sketch_aug11b:36: error: 'u2039' was not declared in this scope sketch_aug11b:36: error: expected )' before numeric constant
sketch_aug11b:36: error: name lookup of 'i' changed for new ISO 'for' scoping
sketch_aug11b:36: error: using obsolete binding at 'i'
sketch_aug11b:36: error: expected `;' before ')' token

I dont know why this error happens and it would be great if you help me.
Here are some details:

-Sainsmart Leonardo
-RC522 NFC module
-Windows 7
-Arduino IDE 1.0.6

Thanks for your help.

Post the code YOU are using, following the #7 in this link.

Have you downloaded and installed the correspondent libraries?

giova014:
Post the code YOU are using, following the #7 in this link.

Have you downloaded and installed the correspondent libraries?

Yes. they are downloades from guithub and pasted in the libaries folder. Arduino IDE was restarted

.ino Code...?

giova014:
.ino Code...?

what do you mean with .ino code?

This thread title :

RC522 NFC PC login - error in code ?!?

error in code

Where is the code?

giova014:
This thread title :

RC522 NFC PC login - error in code ?!?

error in code

Where is the code?

#include ‹SPI.h›
#include ‹MFRC522.h›

#define SS_PIN 10
#define RST_PIN 5

MFRC522 mfrc522(SS_PIN, RST_PIN);
char ctrlKey = KEY_RETURN;

void setup() {
Serial.begin(9600);
Keyboard.begin();
SPI.begin();
mfrc522.PCD_Init();
}

void loop() {
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}

if (!mfrc522.PICC_ReadCardSerial()) {
return;
}

mfrc522.PICC_DumpToSerial(&(mfrc522.­uid)); //serial monitor

Keyboard.press(ctrlKey);
Keyboard.release(ctrlKey);
delay(300);

//You can add another character like '@' here.
//Keyboard.print('@');
//Keyboard.print('#');

for (byte i = 0; i ‹ 4; i++) {
Keyboard.print(mfrc522.uid.uidByte*, HEX); //e.g. C4AD6FB2*
}
//You can add another character like '@' here.
//Keyboard.print('3');
//Keyboard.print('4');
Keyboard.releaseAll();
delay(200);
Keyboard.press(ctrlKey);
Keyboard.releaseAll();
}
Sorry

#include ‹SPI.h›
#include <SPI.h>

See the difference?

Your code is strange.

1 * Replace every ‹ with < and replace every › with >.
2 * This:

mfrc522.PICC_DumpToSerial(&(mfrc522.­uid)); //serial monitor

Try to copy the "point" in the mfrc522.uid and paste in arduino IDE. It is being see as '.-' (Different Char encoding?)
3 * This:

for (byte i = 0; i < 4; i++) {
Keyboard.print(mfrc522.uid.uidByte, HEX); //e.g. C4AD6FB2
}

mfrc522.uid.uidByte is an byte Array with 10 elements, so replace it with:

for (byte i = 0; i < 4; i++) {
Keyboard.print(mfrc522.uid.uidByte[i], HEX); //e.g. C4AD6FB2
}

Below is the corrected code:

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

#define SS_PIN 10
#define RST_PIN 5

MFRC522 mfrc522(SS_PIN, RST_PIN);
char ctrlKey = KEY_RETURN;

void setup() {
Serial.begin(9600);
Keyboard.begin();
SPI.begin();
mfrc522.PCD_Init();
}

void loop() {
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}

if (!mfrc522.PICC_ReadCardSerial()) {
return;
}

mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); //serial monitor

Keyboard.press(ctrlKey);
Keyboard.release(ctrlKey);
delay(300);

//You can add another character like '@' here.
//Keyboard.print('@');
//Keyboard.print('#');

for (byte i = 0; i < 4; i++) {
Keyboard.print(mfrc522.uid.uidByte[i], HEX); //e.g. C4AD6FB2
}

//You can add another character like '@' here.
//Keyboard.print('3');
//Keyboard.print('4');

Keyboard.releaseAll();
delay(200);

Keyboard.press(ctrlKey);
Keyboard.releaseAll();
}

giova014:
Your code is strange.

1 * Replace every ‹ with < and replace every › with >.
2 * This:

mfrc522.PICC_DumpToSerial(&(mfrc522.­uid)); //serial monitor

Try to copy the "point" in the mfrc522.uid and paste in arduino IDE. It is being see as .-. (Differen Char encoding?)
3 * This:

for (byte i = 0; i < 4; i++) {

Keyboard.print(mfrc522.uid.uidByte, HEX); //e.g. C4AD6FB2
}



mfrc522.uid.uidByte is an byte Array with 10 elements, so replace it with:


for (byte i = 0; i < 4; i++) {
Keyboard.print(mfrc522.uid.uidByte[i], HEX); //e.g. C4AD6FB2
}




Below is the corrected code:



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

#define SS_PIN 10
#define RST_PIN 5

MFRC522 mfrc522(SS_PIN, RST_PIN);
char ctrlKey = KEY_RETURN;

void setup() {
Serial.begin(9600);
Keyboard.begin();
SPI.begin();
mfrc522.PCD_Init();
}

void loop() {
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}

if (!mfrc522.PICC_ReadCardSerial()) {
return;
}

mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); //serial monitor

Keyboard.press(ctrlKey);
Keyboard.release(ctrlKey);
delay(300);

//You can add another character like '@' here.
//Keyboard.print('@');
//Keyboard.print('#');

for (byte i = 0; i < 4; i++) {
Keyboard.print(mfrc522.uid.uidByte[i], HEX); //e.g. C4AD6FB2
}

//You can add another character like '@' here.
//Keyboard.print('3');
//Keyboard.print('4');

Keyboard.releaseAll();
delay(200);

Keyboard.press(ctrlKey);
Keyboard.releaseAll();
}

Thanks Very very much :slight_smile:

It works!

Maybe it is because it was written with a Macintosh?

Thanks Thanks Thanks!!!

greetings

James Bond

Now what is if I want to use my own password? I mean if the arduino detects the card with uid 'abc123' it should give out 'mypassword123' and not 'abc123' this would also make it easier to add multiple users.

Can anyone help me? :o

Thanks

Can anyone help me?

No. You don't seem to have caught on to the fact that you need to post YOUR code when asking questions about it.