SIM900A Serial.read() returns messy string and SMS sending error

This is my code.

#include <SoftwareSerial.h>

SoftwareSerial SIM900A(7,8);
void setup()
{
  SIM900A.begin(115200);   // GSM Module Baud rate - communication speed 
  Serial.begin(115200);    // Baud rate of Serial Monitor in the IDE app
  Serial.println ("Text Messege Module Ready & Verified");
  delay(100);
  Serial.println ("Type s to send message or r to receive message");
}


void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
      SendMessage();
      break;
    case 'r':
      RecieveMessage();
      break;
  }

 if (SIM900A.available()>0)
   Serial.write(SIM900A.read());
}

 void SendMessage()
{
  Serial.println ("Sending Message please wait....");
  SIM900A.println("AT+CMGF=1");    //Text Mode initialisation 
  delay(1000);
  Serial.println ("Set SMS Number");
  SIM900A.println("AT+CMGS=\"+XXxxxxxxxxx\"\r"); // Receiver's Mobile Number
  delay(3000);
  Serial.println ("Set SMS Content");
  SIM900A.println("Bhai kya haal hain? (Brother how are you?) this messege has been sent through Arduino Uno not a mobile phone wink wink ");// Messsage content
  delay(3000);
  Serial.println ("Done");
  SIM900A.println((char)26);//   delay(1000);
  Serial.println ("Message sent succesfully");
}


 void RecieveMessage()
{
  Serial.println ("Receiving Messeges");
  delay (1000);
  SIM900A.println("AT+CNMI=2,2,0,0,0"); // Eeceiving Mode Enabled
  delay(1000);
  Serial.write ("Messege Received Sucessfully");
 }
  1. When I read a message, SIM900A.read() returns something like this.

  2. When I try to send a message, I'm getting this error

Could you please help me on this?

Sofwtare Serial is unreliable at 115200 bauds if you have lots happening.

➜ configure your SIM900 for 9600 bauds and modify the code

#include <SoftwareSerial.h>

SoftwareSerial SIM900A(7,8);
void setup()
{
  SIM900A.begin(9600);   // GSM Module Baud rate - communication speed 
  Serial.begin(115200);    // Baud rate of Serial Monitor in the IDE app
...
 SIM900A.begin(9600);   // GSM Module Baud rate - communication speed 
  Serial.begin(115200);    // Baud rate of Serial Monitor in the IDE app
  Serial.println ("Text Messege Module Ready & Verified");
  delay(100);
  Serial.println ("Type s to send message or r to receive message");

I have updated the code like this.
But I'm getting this issue

Then I have updated the baud rate like this

SIM900A.begin(9600);   // GSM Module Baud rate - communication speed 
  Serial.begin(9600);    // Baud rate of Serial Monitor in the IDE app

But the same issue occurred. :sweat:

Did you send the AT command to your module to set the baud rate to 9600? (Or does it auto-baud?)

as @J-M-L said... you likely have to change the baud rate on the modem.

Send it this command...

AT+IPREX=9600

…at what speed ?
The modem has to be listening at the right speed to ‘get’ the command to change speed…

at whatever speed it was at before... presumably 115200.

as per this... Weird characters or wrong letters when working with SIM7600 - #2 by red_car

Please excuse me on this. I'm still learning to do this.

I created a new implementation to check AT commands.
Like below.

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900A
SoftwareSerial mySerial(7, 8); //SIM900A Tx & Rx is connected to Arduino #7 & #8

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(115200);
  
  //Begin serial communication with Arduino and SIM900A
  mySerial.begin(115200);

  Serial.println("Initializing...");
  delay(1000);

  mySerial.println("AT"); //Handshaking with SIM900A
  updateSerial();
}

void loop()
{
  updateSerial();
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

When I try to update the board rate, it gives me an error. Like below.

Initializing.Initializing...
AT

OK
⸮AT+IPRE⸮=9600

ER⸮OR

remove this...

Removed that line and again tried that

Initializi..
Initializing...
AT

OK
AT+IPREX=9f00

ERROR

Sorry.. that might be the wrong AT command for that modem,

Try

AT+IPR=9600

or (for auto baud detection)

AT+IPR=0

try something like this - assuming your SIM module is at 115200 bauds

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900A
SoftwareSerial SIM900A(7, 8); //SIM900A Tx & Rx is connected to Arduino #7 & #8

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(115200);

  //Begin serial communication with Arduino and SIM900A
  SIM900A.begin(115200);
  SIM900A.println("AT");            //Handshaking with SIM900A
  SIM900A.println("AT+IPR=9600");   // whatever is the command to change baud rate
  SIM900A.end();
  delay(100);
  SIM900A.begin(9600);
}

void loop()
{
  while (Serial.available())  SIM900A.write(Serial.read()); //Forward what Serial received to Software Serial Port
  while (SIM900A.available()) Serial.write(SIM900A.read()); //Forward what Software Serial received to Serial Port
}

we open the communication with the SIM module at 115200, we send a command to change the baud rate, so we can't talk to it any more after that. So we close the software serial connection and open it again at the right baud rate.

PS: mySerial is the most stupidest :innocent: name I've seen in demo code... it does not help read the code. so I used SIM900A, you could use simSerial or whatever else will help you/the reader understand you are talking to the SIM module but really don't go for mySerial...

Sorry for that :grinning: Now I updated that to a meaningful name.

Now got the message :innocent:

But why I'm getting this backward question mark like this. This print when SIM900A.read().

while (SIM900A.available()) Serial.write(SIM900A.read());

There might be crap for a bit of time as you switch baud rate in the code and may be the SIM module does spit out something at the old baud rate or new baud rate and you are not in sync.

but is it working afterwards? (look in your module's doc if there is a way to modify the baud rate permanently or to set it to auto-baud permanently). Then you do that once and you are all set, your code can talk at 9600 bauds to the module

I didn't the last code. But now I'm getting something like this

Sorry, that's working now. There was a power issue.

Good news :wink:

I have fixed the backward question mark issue. That was a char to string conversion issue in my implementation. SMS sending also working now. Thank you for the help you all have given. :pray: :pray: :pray: :pray: :pray: @J-M-L @red_car @lastchancename

Have fun now !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.