SIM 900 GSM Module issues with Arduino Uno: it's not sending this SMS message.
the code which I used from a different forum discusion of the same topic
#include <SoftwareSerial.h>
SoftwareSerial ATCommandStream(7, 8);
unsigned long ATComandBaudRate = 9600;
const char * DestinationNumber = "+353894877478";
const char * SMSMessage = "Bonjour";
void setup()
{
// start th serial communication with the host computer
Serial.begin(115200);
while (!Serial);
delay(200);
Serial.println("Sketch started.");
// Power up the SIM900
pinMode(9, OUTPUT);
digitalWrite(9, LOW);
delay(1000);
digitalWrite(9, HIGH);
delay(2000);
digitalWrite(9, LOW);
delay(3000);
ATCommandStream.begin(ATComandBaudRate);
Serial.print("ATCommandStream started at baud rate ");
Serial.println(ATComandBaudRate);
SendShortCommand("AT"); // Just checking that it responds with OK
SendShortCommand("AT+CMEE"); // Turn on verbose messages
SendShortCommand("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
SendShortCommand("AT+CCID"); //Read SIM information to confirm whether the SIM is plugge
SendShortCommand("AT+CREG?"); //Check whether it has registered in the network
SendShortCommand("AT+CSCS="GSM""); // Set character set to GSM
SendShortCommand("AT+CSTA?"); // Check the phone number type
Serial.println("Note: 129=Unknown, 161=National, 145=International, 177=Network Specific");
SendSMSMessage(DestinationNumber, SMSMessage);
SendShortCommand("AT"); // Just checking that it still responds with OK
}
void loop() {}
bool WaitForResponse()
{
unsigned long startTime = millis();
while (millis() - startTime < 5000)
{
String reply = ATCommandStream.readStringUntil('\n');
if (reply.length() > 0)
{
Serial.print("Received: "");
Serial.print(reply);
Serial.println(""");
if (reply.startsWith("OK"))
return true;
if (reply.startsWith("ERROR"))
return false;
}
}
return false;
}
bool SendShortCommand(String command)
{
Serial.print("Sending command: "");
Serial.print(command);
Serial.println(""");
ATCommandStream.print(command);
ATCommandStream.print("\r\n");
if (WaitForResponse())
{
return true;
}
else
{
Serial.print("ERROR or timeout waiting for response to "");
Serial.print(command);
Serial.println(""");
}
return false;
}
void SendSMSMessage(const char *number, const char *message)
{
Serial.println("Sending SMS text");
if (!SendShortCommand("AT + CMGF = 1")) // Set the SMS output to text mode
{
Serial.println("Error in CMGF = 1 (setting to text mode)");
return;
}
if (!SendShortCommand("AT + CMGS = ? ")) // Test for CMGS command support:
{
Serial.println("Error in CMGS = ? (testing for CMGS support)");
return;
}
Serial.print("Sending : ");
Serial.print("AT + CMGS = "");
Serial.print(number);
Serial.println(""(CR)");
Serial.print(message); // The SMS text you want to send
Serial.println("(EM)");
ATCommandStream.print("AT+CMGS=""); // Send SMS
ATCommandStream.print(number);
ATCommandStream.print(""\r"); // NOTE: Command ends with CR, not CRLF
ATCommandStream.print(message); // The SMS text you want to send
ATCommandStream.write(26); // ASCII EndMessage (EM) CTRL+Z character
if (!WaitForResponse())
Serial.println("ERROR or timeout waiting for response to CMGS command");
}