GSM Code not working

Hello there !
I uploaded the following code from http://tronixstuff.com/2014/01/08/tutorial-arduino-and-sim900-gsm-modules/
and it is not working. There is no reading in Serial Monitor.

#include <SoftwareSerial.h>SoftwareSerial SIM900(7, 8); char incoming_char=0; void setup(){  Serial.begin(19200); // for serial monitor  SIM900.begin(19200); // for GSM shield  SIM900power();  // turn on shield  delay(20000);  // give time to log on to network.   SIM900.print("AT+CMGF=1\r");  // set SMS mode to text  delay(100);  SIM900.print("AT+CNMI=2,2,0,0,0\r");   // blurt out contents of new SMS upon receipt to the GSM shield's serial out  delay(100);} void SIM900power()// software equivalent of pressing the GSM shield "power" button{  digitalWrite(9, HIGH);  delay(1000);  digitalWrite(9, LOW);  delay(7000);} void loop(){  // Now we simply display any text that the GSM shield sends out on the serial monitor  if(SIM900.available() >0)  {    incoming_char=SIM900.read(); //Get the character from the cellular serial port.    Serial.print(incoming_char); //Print the incoming character to the terminal.  } }

AND THIS CODE IS WORKING.

#include <SoftwareSerial.h>SoftwareSerial SIM900(7, 8);int x,y;String textForSMS; void setup(){  SIM900.begin(19200);  SIM900power();    delay(20000);  // give time to log on to network.   randomSeed(analogRead(0));} void SIM900power()// software equivalent of pressing the GSM shield "power" button{  digitalWrite(9, HIGH);  delay(1000);  digitalWrite(9, LOW);  delay(7000);} void sendSMS(String message){  SIM900.print("AT+CMGF=1\r");                     // AT command to send SMS message  delay(100);  SIM900.println("AT + CMGS = \"+12128675309\"");  // recipient's mobile number, in international format  delay(100);  SIM900.println(message);                         // message to send  delay(100);  SIM900.println((char)26);                        // End AT command with a ^Z, ASCII code 26  delay(100);   SIM900.println();  delay(5000);                                     // give module time to send SMS  SIM900power();                                   // turn off module} void loop(){  x = random(0,255);  y = random(0,255);  textForSMS = "Your random numbers are ";  textForSMS.concat(x);  textForSMS = textForSMS + " and ";  textForSMS.concat(y);  textForSMS = textForSMS + ". Enjoy!";    sendSMS(textForSMS);  do {} while (1)}

What could be the problem ?

Please format your code according to forum conventions.

Formatted code which is not working

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
 
char incoming_char=0;
 
void setup()
{
  Serial.begin(19200); // for serial monitor
  SIM900.begin(19200); // for GSM shield
  SIM900power();  // turn on shield
  delay(20000);  // give time to log on to network.
 
  SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r");
  // blurt out contents of new SMS upon receipt to the GSM shield's serial out
  delay(100);
}
 
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}
 
void loop()
{
  // Now we simply display any text that the GSM shield sends out on the serial monitor
  if(SIM900.available() >0)
  {
    incoming_char=SIM900.read(); //Get the character from the cellular serial port.
    Serial.print(incoming_char); //Print the incoming character to the terminal.
  }
}

CODE WHICH IS WORKING

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
int x,y;
String textForSMS;
 
void setup()
{
  SIM900.begin(19200);
  SIM900power();  
  delay(20000);  // give time to log on to network.
  randomSeed(analogRead(0));
}
 
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}
 
void sendSMS(String message)
{
  SIM900.print("AT+CMGF=1\r");                     // AT command to send SMS message
  delay(100);
  SIM900.println("AT + CMGS = \"+12128675309\"");  // recipient's mobile number, in international format
  delay(100);
  SIM900.println(message);                         // message to send
  delay(100);
  SIM900.println((char)26);                        // End AT command with a ^Z, ASCII code 26
  delay(100);
  SIM900.println();
  delay(5000);                                     // give module time to send SMS
  SIM900power();                                   // turn off module
}
 
void loop()
{
  x = random(0,255);
  y = random(0,255);
  textForSMS = "Your random numbers are ";
  textForSMS.concat(x);
  textForSMS = textForSMS + " and ";
  textForSMS.concat(y);
  textForSMS = textForSMS + ". Enjoy!";  
  sendSMS(textForSMS);
  do {} while (1);
}

Any help will be highly appreciated

Ok, it’s not working. In what way isn’t it working?

And try:

char incoming_char='0';

Hello Sir

No readings are displayed in serial port. Although the baud rate is set to 19200

NO 'OK' is received from the Modem, the serial interface is blank. I have tried the
char incoming_char='0';

The only other thing I can suggest to try before I get home (I'm at work without an Arduino!) is:

 Serial.write(incoming_char);

Hello Sir

I tried this also but it does not work

I don't know how to put this, apart from I just uploaded it and it works.

Hello Sir,

Can you send the code which you uploaded and is working ?

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
 
char incoming_char=0;
 
void setup()
{
  Serial.begin(19200); // for serial monitor
  SIM900.begin(19200); // for GSM shield
  SIM900power();  // turn on shield
  delay(20000);  // give time to log on to network.
 
  SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r");
  // blurt out contents of new SMS upon receipt to the GSM shield's serial out
  delay(100);
}
 
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}
 
void loop()
{
  // Now we simply display any text that the GSM shield sends out on the serial monitor
  if(SIM900.available() >0)
  {
    incoming_char=SIM900.read(); //Get the character from the cellular serial port.
    Serial.print(incoming_char); //Print the incoming character to the terminal.
  }
}

And the result was (redacted):

AT+CMGF=1

OK
AT+CNMI=2,2,0,0,0

OK

+CMT: "+447751123456","","14/11/05,18:56:32+00",145,32,0,0,"+447802000223",145,6
Hello!

Hello Sir,

I uploaded this code, still the serial monitor screen remains blank.
Only changes i am making is “SoftwareSerial SIM900(0, 1)” because I am using a
GPS modem. But other code is working, so the modem can not be defective, very strange.

Serial monitor uses pins 0 & 1. You cannot also use them to talk to the modem.

Sir

Thanks, I changed the SoftwareSerial from 0,1 to SoftwareSerial SIM900(7, 8);
Now, in serial monitor it displays "00" not the result which you got in your serial
monitor

dannable:

#include <SoftwareSerial.h>

SoftwareSerial SIM900(7, 8);

char incoming_char=0;

void setup()
{
  Serial.begin(19200); // for serial monitor
  SIM900.begin(19200); // for GSM shield
  SIM900power();  // turn on shield
  delay(20000);  // give time to log on to network.

SIM900.print(“AT+CMGF=1\r”);  // set SMS mode to text
  delay(100);
  SIM900.print(“AT+CNMI=2,2,0,0,0\r”);
  // blurt out contents of new SMS upon receipt to the GSM shield’s serial out
  delay(100);
}

void SIM900power()
// software equivalent of pressing the GSM shield “power” button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}

void loop()
{
  // Now we simply display any text that the GSM shield sends out on the serial monitor
  if(SIM900.available() >0)
  {
    incoming_char=SIM900.read(); //Get the character from the cellular serial port.
    Serial.print(incoming_char); //Print the incoming character to the terminal.
  }
}




And the result was (redacted):



AT+CMGF=1

OK
AT+CNMI=2,2,0,0,0

OK

+CMT: “+447751123456”,"",“14/11/05,18:56:32+00”,145,32,0,0,"+447802000223",145,6
Hello!

Hi, this code has been VERY USEFUL to me, thank you
but i have problem is their a way to get the number and message and save it to a variable, int for number and string for text,

Or is their another link that has the same problem, hoping for your reply’s