Write to serial port by detecting a RFID card

when I connect it, the serial monitor shows squares (like undefined symbols) that appear in a row.

What baud rate have you got the Serial monitor set to ?

It must match the baud rate specified in Serial.begin() in the program.