Hello everyone! I'm fairly new to Arduino and just know the bare minimum to write a code in Arduino. So i am tring to do a book issue/renew system using RFID on arduino and need a bit of help here. The base of the program was taken from the RFID library dump and i've written the code in void loop. This is my code.
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
int a,c1=0;
void setup()
{
Serial.begin(9600);
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Approximate your card to the reader...");
Serial.println();
}
void loop()
{
Serial.println("ENTER THE STUDENT IDENTIFICATION CODE");
if(mrfc522.uid.uidByte[0]==0x0c && mrfc522.uid.uidByte[1]==0x8c &&
mrfc522.uid.uidByte[2]==0x91 && mrfc522.uid.uidByte[3]==0x79)
{
Serial.println("WELCOME /n 1.ISSUE /n 2.RENEWAL");
if(Serial.available()>0)
{
a=Serial.read();
}
switch(a)
{
case 1:
Serial.print("Scan the book for issue");
if(!mrfc522.PICC_IsNewCardPresent())
{
Serial.print("Invalid Book");
}
if(!mrfc522.PICC_ReadCardSerial())
{
return;
}
if(mrfc522.uid.uidByte[0]==0x51 && mrfc522.uid.uidByte[1]==0xc5 && mrfc522.uid.uidByte[2]==0x11 && mrfc522.uid.uidByte[3]==0x2E && c1==0)
{
Serial.print("Book 1 has been issued");
c1==1;
}
else
{
Serial.print("Book 1 has already been issued. Please renew it");
}
break;
case 2:
Serial.print("Scan the book for renew");
if(!mrfc522.PICC_IsNewCardPresent())
{
Serial.print("Invalid Book");
}
if(!mrfc522.PICC_ReadCardSerial())
{
return;
}
if(mrfc522.uid.uidByte[0]==0x51 && mrfc522.uid.uidByte[1]==0xc5 && mrfc522.uid.uidByte[2]==0x11 && mrfc522.uid.uidByte[3]==0x2E && c1==1)
{
Serial.print("Book 1 has been renewed");
}
else
{
Serial.print("Book 1 has'nt been issued yet. Please issue it to renew");
}
break;
default:
Serial.print("Invalid option");
break;
}
}
}
So basically i'm scanning a students ID and then he makes a choice between issue and renew and the book is scanned accordingly. when compiling this code i get this error.
Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\tarun.9720\Desktop\liB_auto\liB_auto.ino: In function 'void
loop()':
liB_auto:18: error: 'mrfc522' was not declared in this scope
if(mrfc522.uid.uidByte[0]==0x0c && mrfc522.uid.uidByte[1]==0x8c &&
mrfc522.uid.uidByte[2]==0x91 && mrfc522.uid.uidByte[3]==0x79)
^
exit status 1
'mrfc522' was not declared in this scope
Can anyone help me with this error. I'm a newbie so i might have done something wrong in the code.
EDIT1: So i've wrote 'mrfc' instead of 'mfrc' which was causing the compilation error. Now the code complies successfully but the output is on a infinte loop.
This statement is on loop. Can anyone help me in what wrong i've done in the code?