you do not need the serial interface at all - thats only for debugging purposes. your issue is that you need to wait for the device to be ready; you cannot send an SMS before the network has been established. you can check out the sample to see how this works http://arduino.cc/en/Guide/ArduinoGSMShield#toc9
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
it may not be connected immediately, the above code keeps trying until the connection is established - hence the delay(1000) and try again - you can strip the Serial.println commands and the sketch will wait until the device is ready before moving to the next step.
Thank you ardiri for pointing out that point, I added that part of the code to wait for the connection to establish.
PaulS thank you for your clarification, I am still new to programming, I did change the way I define my input into a string as you showed. However, why is it defined in: http://arduino.cc/en/Reference/GSMSMSPrint, that it accepts a char array, or is that the same thing as a string?
I updated my code but I still couldn't receive an sms, here is the code:
Yea, I just edited out my phone number to post the code here. I think my main problem is not able to pass the data into "sms.beingSMS()" and "sms.print()" . On the send sms example provided with the GSM library the code for receiving this data is given by this function:
/*
Read input serial
*/
int readSerial(char result[])
{
int i = 0;
while(1)
{
while (Serial.available() > 0)
{
char inChar = Serial.read();
if (inChar == '\n')
{
result[i] = '\0';
Serial.flush();
return 0;
}
if(inChar!='\r')
{
result[i] = inChar;
i++;
}
}
}
}
while the "new line" is set in the serial monitor.
How do I pass on the data the same way without manually inputting the data through the serial monitor.
Thank you very much everyone for your help, I really do appreciate it. However, I'm still not able to receive an SMS on my phone. I reviewed my code and tried to emulate the serial input from the example but still I'm not getting any luck.
So, now the next step is to determine how short those delays can be. Waiting for the hardware to be ready (before the call to beginSMS() makes sense. Once the hardware is ready, the other delays should not be needed.