Help me I cant find UID no. for rfid tag

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

#define RC522_SS_PIN  10 // The Arduino Nano pin connected to RC522's SS pin
#define RC522_RST_PIN 5  // The Arduino Nano pin connected to RC522's RST pin
#define SERVO_PIN A5     // The Arduino Nano pin connected to servo motor

MFRC522 rfid(RC522_SS_PIN, RC522_RST_PIN);
Servo servo;

byte authorizedUID[4] = {0xFF, 0xFF, 0xFF, 0xFF};
int angle = 0; // The current angle of servo motor

void setup() {
  Serial.begin(9600);
  SPI.begin(); // init SPI bus
  rfid.PCD_Init(); // init MFRC522
  servo.attach(SERVO_PIN);
  servo.write(angle); // rotate servo motor to 0°

  Serial.println("Tap RFID/NFC Tag on reader");
}

void loop() {
  if (rfid.PICC_IsNewCardPresent()) { // new tag is available
    if (rfid.PICC_ReadCardSerial()) { // NUID has been readed
      MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);

      if (rfid.uid.uidByte[0] == authorizedUID[0] &&
          rfid.uid.uidByte[1] == authorizedUID[1] &&
          rfid.uid.uidByte[2] == authorizedUID[2] &&
          rfid.uid.uidByte[3] == authorizedUID[3] ) {
        Serial.println("Authorized Tag");

        // change angle of servo motor
        if (angle == 0)
          angle = 90;
        else //if(angle == 90)
          angle = 0;

        // rotate the servo motor to the angle position
        servo.write(angle);
        Serial.print("Rotate Servo Motor to ");
        Serial.print(angle);
        Serial.println("°");
      } else {
        Serial.print("Unauthorized Tag with UID:");
        for (int i = 0; i < rfid.uid.size; i++) {
          Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
          Serial.print(rfid.uid.uidByte[i], HEX);
        }
        Serial.println();
      }

      rfid.PICC_HaltA(); // halt PICC
      rfid.PCD_StopCrypto1(); // stop encryption on PCD
    }
  }
}

Can you tell what is wrong with my project code pls or is it something else

Links to the datasheets of the tag and the reader would tell if they are compatible with eachother.

I have bought a set doesn't that mean they are compatible

From where did You buy it?

A shop near my home dedicated to only these types of things

Okey, not Ebay, Amazon, Ali E then.
What do they say?
Any knowledge about their products?

Check if it works with simple examples included in library... by the way what is the problem?

That is your problem. The UID for an RFID tag is 64 bits long not 8 bits.

You need to use an unsigned long long variable to hold these not bytes.

Having then all the same value is not going to help either. You need to know the UIDs that are authorized and add then to your code.

I see nothing in your code that would allow a new card to be presented and it then would be deemed to be a valid code and then stored in some sort of none volatile storage like an SD card or EEPROM.

How will I test the UID no. of my tag then, is there any code for that too? @Grumpy_Mike

I cant get the UID no. of my rfid tag

My school also gets all these types of products from there that's all I know

Reply #8 likely solves the matter.

You will print it out using the serial print to the serial monitor window. Make sure that the baud rate of the serial monitor is set to the same serial baud rate as the print will use.

You then make a note of the number each tag gives you and include that number in your list of authorized tags.

The mfrc522 library should have an example call dumpinfo

Can you tell me the code as I am a school student I don't know that much about arduino?

Suggest you talk with the instructor.

1 Like

Do you have anything in the Serial monitor when you run the code from first post?

We are here to help you, not to do it for you.

Now have you made the changes I told you about?
Did it make a difference to your code when you ran it?

Post again your changed code, in a new reply so we can see if you understand what you have been told to do already. Or explain what you didn't understand about what you have been told.

no
just 'tap rfid tag on the rfid" that i coded but after i tap it it doesn't show the UID no. that is supposed to be

Do you see the message "Unauthorized Tag with UID:" ?

Try to add additional diagnostic if the card present and read by module