Unable to receive and print SMS on the serial monitor with Arduino Uno and SIM900A I'm trying to receive an SMS and show it on the serial monitor.

My code is as following:

void setup() 
{

  Serial.begin(2400);
  Serial.write("AT+CMGF=1\r");           //set GSM to text mode
  delay(1500);

  Serial.write("AT+CPMS=\"SM\"\r");         //Preferred SMS Message Storage
  delay(1000);

  Serial.write("AT+CMGL=\"ALL\"\r");       //List SMS Messages from Preferred Storage
  while(1)
  {
    if(Serial.available())
    {
      Serial.write(Serial.read());  
    }   
  }
}

void loop() 
{
}


The circuit diagram is as shown below.



The output that I am getting is as following:

AT+CMGR=1
AT+CMGF=1

OK
AT+CPMS="SM"

ERROR
AT+CMGR=1
AT+CMGF=1

OK
AT+CPMS="SM"

ERROR

ERROR
AT+CMGR=1
AT+CMGF=1


I am not able to use AT+CPMS or AT+CMGL commands.
The Arduino UNO that you are using only supports one Serial connection (over the TX and RX pins). Since you are using these pins to talk to the device, you cannot also send data over Serial.

Read this article to see more about Serial and how it works on different boards.