rfid was not declared on this scope

I’m try to use the follow code to detect a rfid but testing the code I follow the error " rfid was not declared on this scope"
Hereby you’ll found the code, please give me some assistance

#include <MFRC522.h>
MFRC522 rif(10, 9);
void setup() {
void loop() {
if(rfid.PICC_IsNewCardPresent()&& rfid.PICC_ReadCardSerial()){
String uid=getUID();
Serial.println("RFID ID: " +uid);
delay (10);
String getUID(){
String uid="";
for(int i=0; i<rfid.uid.size; i++){
uid += rfid.uid.uidByte[i] < 0x10 ? "0":"";
uid += String (rfid.uid.uidByte[i],HEX);
return uid;

Something called "rif" is declared but never used. Something called "rfid" is used but never declared. Perhaps there's a connection there somewhere?



Enclosed you'll found a picture of the connexion

Sorry the picture wasn't enclosed
The file dimention was to big to forward it trought the forum
May I send it enclosed to your mail address ?

I guess you just found that code somewhere but you don't understand it at all.

The reason you have an error saying "rfid was not declared on this scope" is because you have not declared anything called "rfid" in the code. You have declared an MFRC522 object for the RFID reader but it is named "rif" not "rfid". Try changing "rif" to "rfid".


ok now I have understood, I correct the mistake and now the file running without error but the rfid reader can't detect the rfid sensor


I solved the problem with the code, the test on the IDE given a positive feedback and the loading operation on arduino too

The problem is that the reader can detect the rfid and on the serial monitor nothing happen

Please help me to solve also this problem

Where is the "fixed" code?