1

I want to know if it is possible to send an SMS from a SIM900 using Arduinos to another SIM900.

Problem: When the gsm is connected to the network, it does not send an sms; my airtime balance remains the same.

Here is the code I used:

#include <SoftwareSerial.h>
SoftwareSerial SIM900 (9,10);

void setup()
{
   serial.begin(9600);
   SIM900.begin(9600);
   delay(5000);
}

void loop()
{
   sendSMS();

   while(SIM900.available()!=0)
     {
        Serial.println(SIM900.read());
     }
}

void sendSMS()
{
    SIM900.println("AT+CMGF=1\r");
    delay(100);
    SIM900.println("AT+CMGS=\"+27769384488"\r");
    delay(100);
    SIM900.println("Hello");
    delay(100);
    SIM900.println((char)26);
    delay(100);
    SIM900.println();
    delay(5000);

}
1

Yes, it is possible.

Your code doesn't show any sign of board powering on and initialization.

SIM900 has some LED that show status - make sure you are connected to GSM network.

Please check this tutorial: https://www.youtube.com/watch?v=RUGV_64lQX8

  • Thanks for respond, I have used Hash include SoftwareSerial.h #include <SoftwareSerial.h> but the website refused to display it, i was powering it using the button in it. Is this the only initialization used? – Mike May 29 '16 at 12:58
1

I had worked on GSM long back ago and sometimes it becomes very difficult to debug the problem. However u need to just check whether the AT commands are being sent properly to the GSM module. I had tried using Software Serial but it did not work for me but when I switched to the usual Serial port it worked like a charm. Few things that you need to check are:

  1. Check the baud rate of GSM module. Does it match with the baud rate of Software Serial.
  2. Do a if-else check to see whether the commands are actually being sent to the GSM module. The println() returns the number of bytes written so you can do like this in your sendSMS() function.

int a; //To store the number of bytes written a=SIM900.println("AT command to be sent");
if(a)
{
Serial.println("Command sent");
}
else
{
Serial.println("Command not sent");
}

Now upload the code and open the serial monitor to see whether the command is actually being sent to the GSM module or not.

  1. You also need to check whether the format of your AT command is correct. Because you need to send \n(newline) and\r(carriage return) at the end of every AT command to ensure proper operation. For this you need to read the response sent back by the GSM module after every command. This can be done by reading the Software serial port and the printing the response onto the Serial monitor.
  2. You also need to check whether your GSM module has detected the SIM card. Usually this is indicated by an onboard LED that blinks after every 3 seconds.

I think your code is pretty much correct but try to ensure that everything is setup properly as I said. Here is my code but I used Serial port instead:

void setup() {
Serial.begin(9600);
delay(10000); \\For initialization purpose
}
void sendSMS()
{ Serial.println("AT+CMGF=1");
delay(5000); Serial.println("AT+CMGS=\"Phone number with international code\"");
delay(5000); Serial.print("Hello");
delay(5000); Serial.println((char)26);
delay(5000);
}
void loop()
{
sendSMS();
do {
}while(1);
}

This code will send the SMS once so you need to reset the board for sending another SMS or you can remove the do while loop for continuous operation.You can adjust the delay accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.