Book issue/renew project using RFID code need help

Hello guys so i've already posted here once about this when i couldn't get the result for my code. Now i'm obtaining the result properly but i need to optimize it in the serial monitor. Can anyone help me with this?
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
  mfrc522.PCD_DumpVersionToSerial();
  Serial.println("Approximate your card to the reader...");
  Serial.println();
  Serial.println("ENTER THE STUDENT IDENTIFICATION CODE");
}
void loop()
{
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  // Dump debug info about the card; PICC_HaltA() is automatically called
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
  if(mfrc522.uid.uidByte[0]==0x0c && mfrc522.uid.uidByte[1]==0x8c && mfrc522.uid.uidByte[2]==0x91 && mfrc522.uid.uidByte[3]==0x79)
  {
    Serial.println("WELCOME /n 1.ISSUE /n 2.RENEWAL /n 3.RETURN");
    delay(3000);
    if(Serial.available()>0)
    {
      //Serial.println("Hello");
    a=Serial.read();
    }
    switch(a)
    {
      case 49:
            Serial.println("Scan the book for issue");
            delay(3000);
            if ( ! mfrc522.PICC_IsNewCardPresent()) {
            return;
            }

            // Select one of the cards
            if ( ! mfrc522.PICC_ReadCardSerial()) {
            return;
            }

            // Dump debug info about the card; PICC_HaltA() is automatically called
            mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
            if(mfrc522.uid.uidByte[0]==0x51 && mfrc522.uid.uidByte[1]==0xc5 && mfrc522.uid.uidByte[2]==0x11 && mfrc522.uid.uidByte[3]==0x2e && c1==0)
            {
              Serial.println("Book 1 has been issued");
              c1=1;
            }
            else
            {
              Serial.println("Book 1 has already been issued. Please renew it");
            }
            break;
      case 50:
            Serial.println("Scan the book for renew");
            delay(3000);
            if ( ! mfrc522.PICC_IsNewCardPresent()) {
            return;
            }

            // Select one of the cards
            if ( ! mfrc522.PICC_ReadCardSerial()) {
            return;
            }

            // Dump debug info about the card; PICC_HaltA() is automatically called
            mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
            if(mfrc522.uid.uidByte[0]==0x51 && mfrc522.uid.uidByte[1]==0xc5 && mfrc522.uid.uidByte[2]==0x11 && mfrc522.uid.uidByte[3]==0x2E && c1==1)
            {
              Serial.println("Book 1 has been renewed");
              
            }
            else
            {
              Serial.println("Book 1 has'nt been issued yet. Please issue it to renew");
            }
            break;
      case 51:
            Serial.println("Scan the book to return");
            delay(3000);
            if ( ! mfrc522.PICC_IsNewCardPresent()) {
            return;
            }

            // Select one of the cards
            if ( ! mfrc522.PICC_ReadCardSerial()) {
            return;
            }

            // Dump debug info about the card; PICC_HaltA() is automatically called
            mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
            if(mfrc522.uid.uidByte[0]==0x51 && mfrc522.uid.uidByte[1]==0xc5 && mfrc522.uid.uidByte[2]==0x11 && mfrc522.uid.uidByte[3]==0x2e && c1==1)
            {
              Serial.println("Book 1 has been returned");
              c1=0;
            }
            else
            {
              Serial.println("Book 1 hasn't been issued yet. please issue the book to return it.");
            }
            break;      
      default:
            Serial.print("Invalid option");
            break;
    }
  }
}

So the output of the code on the serial monitor is something like shown in the picture.
Imgur
i.e whenever i scan a card i get it's sector block too. Is there anyway to remove just the sector block from being printed in the serial monitor? Other than that the code works as intended. Thank you.

Try using the MFRC522::PICC_DumpDetailsToSerial() function instead

So if I can restate your concern, you are looking for a convenient way of formatting the output?

DKWatson:
So if I can restate your concern, you are looking for a convenient way of formatting the output?

Yes, as you can see in the serial monitor picture i've linked the conditions are being printed just fine, i can issue renew and return books as the i've wanted. But every time i swipe a card the serial monitor fills up with the card's sector block. if i could just remove the sector block from being printed in the serial monitor the output would looks less messy. Can you please help me?

(deleted)

blh64:
Try using the MFRC522::PICC_DumpDetailsToSerial() function instead

you mean instead of "mfrc522.PCD_DumpVersionToSerial()" in void setup?

spycatcher2k:

mfrc522.PICC_DumpToSerial(&(mfrc522.uid));

I think this line may have something to do with it?

that is the code i've directly taken from the example code bundled with the rfid library. This is my first time using arduino to make a project and i have no idea how to change that code so it can exclude the sector blocks. Any help?

Try replacing the PICC_DumpToSerial() call with PICC_DumpDetailsToSerial() function instead. If you look at the library code, the PICC_DumpToSerial() calls PICC_DumpDetailsToSerial() and then also prints out the sector information which I'm gathering you don't want.

blh64:
Try replacing the PICC_DumpToSerial() call with PICC_DumpDetailsToSerial() function instead. If you look at the library code, the PICC_DumpToSerial() calls PICC_DumpDetailsToSerial() and then also prints out the sector information which I'm gathering you don't want.

Awesome! it worked! Thank you very much!!! I'd love to know how did you resolve the error though, i can learn something. Did you look into the MFRC522.h library? where the commands are present?

LoneWolf999:
Did you look into the MFRC522.h library? where the commands are present?

Yes. I library is nothing more that C/C++ code that somebody else wrote so you are free to look at it just like your own code :slight_smile: