How to use the Arduino GSM shield to send the SMS AUTOMATICALLY

// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

void setup()
{
// initialize serial communications
Serial.begin(9600);

Serial.println("SMS Messages Sender");

// connection state
boolean notConnected = true;

// 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);
}
}

Serial.println("GSM initialized");
}

void loop()
{

Serial.print("Enter a mobile number: ");
char remoteNumber[20]; // telephone number to send sms
readSerial(remoteNumber);
Serial.println(remoteNumber);

// sms text
Serial.print("Now, enter SMS content: ");
char txtMsg[200];
readSerial(txtMsg);
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);

// send the message
sms.beginSMS(remoteNumber);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
}

/*
Read input serial
*/
int readSerial(char result[])
{
int i = 0;
while(1)
{
while (Serial.available() > 0)
{
char inChar = Serial.read();
if (inChar == '\n')
{
result = '\0';

  • Serial.flush();*
  • return 0;*
  • }*
  • if(inChar!='\r')*
  • {*
    _ result = inChar;_
    * i++;*
    * }*
    * }*
    * }*
    }
    this is the code for send the SMS
    Is anyone know how to send the SMS AUTOMATICALLY

Is that a trick question ?
Look at the function Readserial() .
Do you need that if you already know the message content ?
Comment that out and replacebit with a string array gor the message.
If you define the message then there is no need to read it is there ?
You just need to declare "TxtMsg".
If you declare it , then isn' t it hardcoded ?

Could u give me that code? because i am not really understand that code.
Thank you very much.

Could u give me that code?

What code?

because i am not really understand that code.

You don't understand the code you posted? You need to learn, then. This is NOT the homework hotline.

Think about it
If you want to send the smstext automatically, why would you want to read serial from the keyboard ?

zsj7887:
Could u give me that code? because i am not really understand that code.
Thank you very much.

Whats your point then? What hardware have you got? What do you want to achieve?

Making questions in a smart way yelds higher changes to get help

Could u give me that code?

you already have the code. This is not a homework hotline. Figure it out.

i got the GPRS Shield V2.0
i dont want to write phone number in the Serial screen. i just want that board can read the number that i put on the code.
So i am not sure about the code can it be " serial print("phone number:04526158") like this

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.

I don't think anyone understands what you are trying to do. You need to try to explain it in more detail. I don't think the word "automatically " explains anything and hard coding the phone number doesn't tell us if you plan to hard code the message too.

From my interpretation of the question this is is a common query and there are lots of solutions out on the internet. You just need to do a little searching.

Could u give me that code?

Points
1- It is still unclear what you want to do . You need to clearly state exactly what you want to hardcode.
2- You already have code that can be modified to suit your needs.
3- Repeated stating that you don't know what to do is not going to change the fact that we are here to help you learn, not to do
your homework. This is not a homework hotline or program writing service. Your repeated reluctance to engage the posters with
specific question regarding your code suggests you believe that sooner or later, someone is going to write your code for you.
Let me be perfectly clear. We are not going to write the code for you. You need to clarify what you want so we can advise you on the changes you need to make to the code you already posted. We are not going to do anything until you respond to the replies you already have, starting with the one asking you to edit your code and use code tags. Please follow instructions in order for us to help you.

Richmond,
you have broken almost every rule of the forum... with only four posts to your name!

hijacking someone else's thread, not using code tags, and not telling us what your problem is...!

Delete your post above, start a new thread AFTER reading the sticky threads at the top of the forum.

and... btw, your SIM900 will become progressively less usable after the end of the year. Different countries are turning off their 2G mobile networks - starting in December.

p.s. I hope the gas you're detecting isn't flammable or explosive, otherwise when the buzzer goes off, you may not need this device anyway.

I am trying to run the SendSMS example with an UNO and SIM900 shield. I have easily done this in the past but can no longer get it to send a text message to my phone. I get the following serial response:

SMS Messages Sender
GSM initialized
Enter a mobile number: +1(my number)
Now, enter SMS content: SENDING

Message:
test

I never receive the message. Can someone suggest where to look for the problem? I tried other basic sketches and none seem to work anymore. Stumped!

ncuck...
hijacking someone else's thread is bad form...

Delete your post above, start a new thread AFTER reading the sticky threads at the top of the forum.

and... btw, your SIM900 will become progressively less usable after the end of the year. Different countries are turning off their 2G mobile networks - starting in December.

try this it work for me when auto replying to sender

/*
GPRS SMS Read

This sketch is used to test seeeduino GPRS_Shield's reading SMS
function.To make it work, you should insert SIM card
to Seeeduino GPRS Shield,enjoy it!

There are two methods to read SMS:

  1. GPRS_LoopHandle.ino -> in order to recieve "+CMTI: "SM""
    may be you need to send this command to your shield: "AT+CNMI=2,2,0,0,0"
  2. GPRS_SMSread.ino -> you have to check if there are any
    UNREAD sms, and you don't need to check serial data continuosly

create on 2015/05/14, version: 1.0
by op2op2op2(op2op2op2@hotmail.com)
*/

#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>

#define PIN_TX 7
#define PIN_RX 8
#define BAUDRATE 9600

#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;

char phone[16];
char datetime[24];

GPRS gprsTest(PIN_TX,PIN_RX,BAUDRATE);//RX,TX,PWR,BaudRate

void setup() {
Serial.begin(9600);
while(!gprsTest.init()) {
Serial.print("init error\r\n");
delay(1000);
}
delay(3000);
Serial.println("Init Success, please send SMS message to me!");
}

void loop() {
messageIndex = gprsTest.isSMSunread();
if (messageIndex > 0) { //At least, there is one UNREAD SMS
gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
//In order not to full SIM Memory, is better to delete it
gprsTest.deleteSMS(messageIndex);
Serial.print("From number: ");
Serial.println(phone);
Serial.print("Datetime: ");
Serial.println(datetime);
Serial.print("Recieved Message: ");
Serial.println(message);
gprsTest.sendSMS(phone,"received your message");
}
}