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!