SIM900 responds AT, no sms

I am trying to get this sketch working. It does everything i want except sending the SMS. I wont get anything. This is what i got through serial:

Waiting for GSM
Waiting for GSM
Simpel
SMS Deleted
Sending SMS
Waiting to send
Sent or timed out
Going to sleep
Wait

I used an example sketch from the IDE with success.
(Arduino Pro Mini 3.3V clone + SIM900A)

#include <GSM.h>
#include <HWSerial.h>
#include <SIM900.h>
#include <sms.h>
#include <WideTextFinder.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <avr/sleep.h>
#include <avr/wdt.h>

#define power_pin 4                 //Pin used to power GSM module on and off.
#define config_switch_pin 6         //Pin to read configuration
#define SMS_waiting_threshold 45000 //How long the module will stay on after notification in order to receive potential configured number
#define SMS_TIMEOUT_THRESHOLD 15000 //The time that the program waits for a send acknowledgement of an SMS
#define batt_pin A0                 //Pin for battery level measurement
#define wake_pin 3                  //Pin used for waking up  

SoftwareSerial mySerial(7, 8); // RX, TX

String number = "+xxxxxxxxx"; //Set default number to call - in case none is programmed in the EEPROM yet
int start;                      //Variable used to start counting time for timeouts
String text;                    //Variable used for serial communication with the GSM module
float battery_level;

void setup()
{
  battery_level = ((analogRead(batt_pin) / 1024.0) * 5.0); //Measure battery level before we start consuming more power and scale it to 5V
  Serial.begin(9600);
  mySerial.begin(9600);

  pinMode(power_pin, OUTPUT);
  pinMode(wake_pin, INPUT_PULLUP);        //We'll use internal pull-up resistors to simplify the breadboard layout
  pinMode(config_switch_pin, INPUT);
  attachInterrupt(0, wakeUpNow, HIGH);    //Use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW   
  
  MCUSR = 0;                              //Pre-configure WDT
  number = get_number();                  //Obtain number from EEPROM

  power_GSM();                           //Power up the GSM module
  
  while (get_net_status()=="NC") {        //Check every 1 second if the GSM module has registered in the network
    Serial.println(F("Waiting for GSM"));
    delay(1000);
  }

What do i miss…

mailbox_deb2.ino (8.9 KB)

I think you cannot have extra spaces in the AT+CMGS command.

This works:

  mySerial.println("AT+CMGDA=\"DEL ALL\"");       //Delete existing text messages
  delay(500);
  Serial.println( "SMS Deleted" );
  Serial.println("Sending SMS");
  mySerial.println("AT+CMGF=1");                //AT command to send SMS message
  delay(150);
  mySerial.print( "AT+CMGS=\"+00000000000\"\r"); //Recipient's number
  delay(100);
  mySerial.print( "You've got mail! Battery: 50");  //Message content
  delay(100);
  mySerial.println( (char)26 );                     //Sending ^Z to finish content
  Serial.println(F("Waiting to send"));

PS: var start needs to be an unsigned long int, not an int. An int cannot contain values for millis() after running a long time.

PPS: You don't need to measure the battery voltage by the way, the SIM900 has an AT command "AT+CBC" that will tell you the battery level and voltage.

I changed it but still no SMS. I am starting to think it takes a kind of demon worshipping to get this code working.

I tried this little sketch to send an sms. Worked flawless.

Uploaded the other sketch again. Serial monitor gave me this:

Waiting for GSM
Simpel
SMS Deleted
Sending SMS
Waiting to send
Sent or timed out
T+CMGDA="DEL ALL"

OK
AT+CMGF=1


OK
"
You've got mail!
Going to sleep
Waiting for serial and going to sleep

It looks like the AT+CMGS isn't send at all??

I have not looked at the code that checks the SMS response, just the send-SMS bit. Your code checking the responses from the SIM900 is not okay, as I told you in the last lines of my reply, but I have not debugged that code.

Somehow it got it to work after i used the a proper connection for the config switch and stored my mobile number in the EEPROM. Works very well but i can’t stand not knowing what the real problem was since i entered my number in case there was no number stored in EEPROM.

mailbox_deb2.ino.ino (8.98 KB)

I'd love to help, but I'm not sure what your question is...

Sorry, my post was one born out frustration :D

After many hours of trying and searching it suddenly started working and received an sms.

I made a mistake with defining the pins the config pin was connected to the same pin as the rx pin to the SIM900. The program kept looping waiting for an sms with 'PROGRAM' in it. Merely by coincidence i sent one. After ungrounding the configswitch pin and resetting the Pro Mini i received my sms.

The sketch itself provides 2 ways of using a mobile nummer. Storing one in the EEPROM and enter one in the sketch. Only storing one in EEPROM seems to make the whole thing work.

I just can't find out why the number stored in the sketch doesn't work and i just can't stand that. I like to know how stuff works of why not.

Also i found out the Pro Mini with original bootloader does not support system restart by the watchdogtimer so i had to burn the Optiboot bootloader. That should rule out any problems with the millis funcion doesn't it?

By the way, the original .ino of this sketch comes from this Instructable

After many hours of trying and searching…

The sketch itself provides 2 ways of using a mobile nummer. Storing one in the EEPROM and enter one in the sketch. Only storing one in EEPROM seems to make the whole thing work.

I just can’t find out why the number stored in the sketch doesn’t work and i just can’t stand that. I like to know how stuff works of why not.

I had a look, but did not see anything obvious at first sight, but I did not keep the whole sketch, nor did I use actual EEPROM. Bytes are usually not very different when they are read from EEPROM :wink:

You can do a few things:

  1. Cut out everything you don’t need. E.g. keep this:
void sendSMS()
{
  text.reserve(100);
  text="";
  Serial.println("AT+CMGDA=\"DEL ALL\"");       //Delete existing text messages
  delay(500);
  Serial.println( "SMS Deleted" );
  Serial.println("Sending SMS");
  Serial.flush();
  Serial.println("AT+CMGF=1\r");                //AT command to send SMS message
  delay(1000);
  Serial.println("AT + CMGS = \""+number+"\""); //Recipient's number

  Serial.print("-> 3 freeMemory()="); Serial.println( freeMemory() );

  delay(1000);
  Serial.println("You've got mail! \r\nBattery: "+String(battery_level)+" V");  //Message content
  delay(1000);
  Serial.println((char)26);                     //Sending ^Z to finish content
  Serial.flush();  
  delay(1000); 
  Serial.println();
  Serial.println(F("Waiting to send"));
}

That just prints to your serial pc monitor, so you can see what may not be correct. If you send it to your SIM900 you lose track.

  1. You use the String type all over this sketch, while you have only 2k bytes memory available. Use this to keep track of free memory:

#include <MemoryFree.h>

Serial.print(“freeMemory()=”); Serial.println( freeMemory() );

  1. I don’t have the libraries called by:
#include <GSM.h>
#include <SIM900.h>
#include <sms.h>
#include <WideTextFinder.h>

Check with freeMemory() if they have eaten up your memory in your complete sketch.

  1. Spend a few of those frustrated hours to learn good old C-strings. They’re not that bad.

Thanks Rick, very much appreciated! Going to try this tonight.

  1. Spend a few of those frustrated hours to learn good old C-strings. They're not that bad.

I know. While solving my problems i am reading a lot and trying to learn. When i got this working i will just start with a blinking led. ;)