Sending SMS using GSM SIM900

Hi!

We used the Arduino Uno microcontroller and GSM SIM900 to send an SMS. Tx pin of the SIM900 is connected to Rx of Uno, Rx of SIM900 is connected to Tx of Uno and te Gnd SIM900 to the Gnd of Uno.

Mentioned below is the code we have used, and it works. We wish to implement the same using the SoftwareSerial library. We would like to know what changes we would have to make if it has to be implemented using SoftwareSerial.

int timesTosend=1;
int count=0;
char phone_no[]="9xxxxxxxxx"; 

void setup()
{
Serial.begin(9600);  //Open Serial connection at baud 9600
delay(2000);
Serial.println("AT+CMGF=1"); //set GSM to text mode
delay(200);
}
void loop()
{
while(count<timesTosend){
delay(1500);
Serial.print("AT+CMGS=\"");
Serial.print(phone_no);
Serial.println("\"");
while (Serial.read()!='>');
{
Serial.print("It works!");  //SMS body
delay(500);
Serial.write(0x1A);  // sends ctrl+z end of message
    Serial.write(0x0D);  // Carriage Return in Hex
Serial.write(0x0A);  // Line feed in Hex
//The 0D0A pair of characters is the signal for the end of a line and beginning of another.
delay(5000);
}
count++;
}
}

These are the changes we have made, but it isn’t working:

#include<SoftwareSerial.h>
SoftwareSerial mySerial(2,3);

int timesTosend=1;
int count=0;
char phone_no[]="9036768091"; 

void setup()
{
Serial.begin(9600);
mySerial.begin(9600);//Open Serial connection at baud 9600
delay(2000);
mySerial.println("AT+CMGF=1"); //set GSM to text mode
delay(200);
}
void loop()
{
  if(mySerial.available()>0)
  {
while(count<timesTosend){
delay(1500);
mySerial.print("AT+CMGS=\"");
mySerial.print(phone_no);
mySerial.println("\"");
while (Serial.read()!='>');
{
mySerial.print("It works!");  //SMS body
delay(500);
mySerial.write(0x1A);  // sends ctrl+z end of message
    mySerial.write(0x0D);  // Carriage Return in Hex
mySerial.write(0x0A);  // Line feed in Hex
//The 0D0A pair of characters is the signal for the end of a line and beginning of another.
delay(5000);
}
count++;
}
}
}

Please help us figure out what we have done wrong and what can be done to make it work.

Thanks!

In Arduino 2&3 are default tx,rx pin redeclaring same pin using softserial wont work

int timesTosend=1;
int count=0;
String phone_no="+9036768091";

void setup()
{
Serial.begin(9600);
mySerial.begin(9600);//Open Serial connection at baud 9600
delay(2000);
Serial.println(“AT+CMGF=1”); //set GSM to text mode
delay(200);
}
void loop()
{
while(count<=timesTosend)
{
delay(1500);
Serial.print(“AT+CMGS=” + phone_no);
Serial.print(char(13)); //Enter command
delay(100);
Serial.print(“It works!”); //SMS body
Serial.write(0x1A); // sends ctrl+z end of message
delay(500);
Serial.write(0x0D); // Carriage Return in Hex
Serial.write(0x0A); // Line feed in Hex
//The 0D0A pair of characters is the signal for the end of a line and beginning of another.
delay(5000);
count++;
}
}

use this code if u r connecting gsm to 2&3…
if u r going to use any other pin then use softserial method

example:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4,5);

Ignore what vsathish said, there is only one hardware serial port on the Uno, and that uses (digital) pins 0 & 1. You do need SoftwareSerial to use pins 2 & 3.

To start with I would check the basic functionality by using SerialRelay ( from here amongst other places), set SoftwareSerial to use pins 2 & 3 and start with the standard convention of connecting Tx -> Tx, Rx -> Rx and ground -> ground. I assume you are using an external power supply to the SIM900?

Then use Serial Monitor to get it to respond to the AT command. Once you have it working you can integrate the relevant parts into your own scripts.

If you have any further problems please ask, and unlike vsathish, continue to use code tags.