Problem: Reading RFID into UNO

I’m working on a project that tracks a person via RFID. But the code for reading the card serial number that I’ve been trying didn’t give any result on the serial monitor.
I tried then checking the source of the error. So I tried a simple example that reads from serial port and that also didn’t work either.
Both codes are included below.

Components:

Connection:
RFID Module ------------> Arduino Uno
VCC 5V
GND GND
UART receiver Pin 1: TX
UART transmitter Pin 0: RX

Below is the simple code example that reads from serial port and blinks pin 13 on the Uno board.

void setup() 
{
  
  Serial.begin(19200);
  pinMode(13, OUTPUT);
}

void loop() 
{
  
      if (Serial.available())
      { 
      
        digitalWrite(13,HIGH);
        delay(1000);
        digitalWrite(13,LOW);
        Serial.println("AVAILABLE"); 
      }
}

Below is the second code that reads the card serial number:

 byte data[5];  //For holding the ID we receive
 int val = 0;

 void setup()
 {
  
   // Start serial port 19200 bps
   Serial.begin(19200);
   
   // Setting 
   // command: AA BB 02 19 1B
   Serial.print(0xAA);  //Header
  Serial.print(0xBB);  //Header
   Serial.print(0x02);  //Length  of command
    Serial.print(0x19);  // command card serial number   
   Serial.print(0x1B);  //Checksum
   
   delay(500);
   Serial.flush();
   Serial.println();
   Serial.println("RFID module started in Auto Read Mode, Waiting for Card...");
 }

 void loop()
 {
  //
 Serial.println(val);
   val= Serial.read();   
    while (val != 0xAA)
   {  //On Successful read, first byte will always be 0xAA
     Serial.println(val);
      val = Serial.read();
      Serial.println(val);
      delay(1000);
   }
   
   
   Serial.read();              // reserved
  Serial.read();              // reserved
   Serial.read();              // length
   Serial.read();              // command (indicates tag data)
   data[0] = Serial.read();    // we read data 1
   data[1] = Serial.read();    // we read data 2
   data[2] = Serial.read();    // we read data 3
   data[3] = Serial.read();    // we read data 4
   data[4] = Serial.read();    // we read data 5
   Serial.read();              // checksum

 Serial.print("Card found");
    for (int i=0; i<5; i++)
   {
     if (data[i] < 16) Serial.print("0");
     Serial.print(data[i], HEX);
   }
  
   
 }

Any help appreciated. Thanks.

serial1.ino (262 Bytes)

cardserialnumber.ino (1.4 KB)

Serial monitor uses pins D0 & D1 for communication. It looks as though you are also trying to use them to talk to the card reader?

Try creating an instance of SoftwareSerial to talk to your device, using another pair of pins.

dannable:
... Try creating an instance of SoftwareSerial to talk to your device, using another pair of pins.

I tried SoftwareSerial and used another pair of pins but I still have the same problem.

Feel free to post your revised code.