#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");
}
When I read a message, SIM900A.read() returns something like this.
When I try to send a message, I'm getting this error
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
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.
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 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...
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 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. @J-M-L@red_car@lastchancename