send text without using serial comms

I have a project that I am working on, that I need to send a text (read variable) using a GSM module (SIM800L) when a condition(sensor input) is met. I have been researching for a week or so now, and can't find how to get the GSM to send a text to a cell number without having it connected to the computer. This will be a mobile device with a sensor input, GPS input, and GSM output on an arduino Pro Mini.

One problem I have found, is how to store a phone number variable in order to call when sending the text. The other, is how exactly to send the message without using a computer connected through serial coms.

Anyone have ideas???

Thanks,
Nate

Just to clarify your situation.

You have a GSM module connected to an arduino pro mini and the pro mini is connected to a sensor. You also have the arduino pro mini connected to a 'computer' and use the serial console to send commands etc.

You now want to remove the 'computer' and have the pro mini, sensor and GSM module so configured that if the sensor is triggers, the GSM Module should send a predefined text message to a predefined number .

Is that it ?

Dead on! that's exactly what I want to do.

NateOdem:
Dead on! that’s exactly what I want to do.

I’m glad it is so simple. Just post the code that you are using at the moment. Say what the sensor is and what trigger value it has for the message and what message you want to send. If all that is clear, someone here will surely help.

I don't have enough of the code together yet. I have it in pieces right now, as I am trying to get them to work individually before I combine them. The sensor is a accelerometer/gyro. When it is tipped more than 70 degrees in X or Y, it writes a digital pin high, which will trigger the GSM to send a text to a number.

The text that will be sent will be the reading of LAT & LONG from a gps module.

The only part I am having trouble with right now, is getting the GSM to send a text without using the serial monitor to trigger it to do so, and also finding a way to store the phone number as a variable so when the command is made to send the text, I can call it up.

I don't need the whole sketch, or want someone doing it for me, I am just trying to figure out how to do those 2 things, and I should then be able to put it all together.

Thanks!

I would think something like this would work…

#include <GSM.h>              // Include library
#define PINNUMBER ""          // Create Pin Number instance (if needed)

GSM gsmAccess;
GSM_SMS sms;
int button(9,INPUT);          // Create input intance of button on pin 9

void setup() 
{
  Serial.begin(9600);         // Start Serial Comms (for debugging only)
  while (!Serial)             // If not connected to Serial...
  {                           //Do nothing
  }
  Serial.println("Text Message Sender");  // if connected, print project name
  boolean notConnected = true;// Create connection state of GSM

  while (notConnected)        // If not connected to GSM
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) // Connect to GSM
    {
      notConnected = false;   // Change connection status
    } else 
    {
      Serial.println("Not connected"); // Print connection status to Serial
      delay(1000);
    }
  }

  Serial.println("GSM initialized");   // // Print connection status to Serial
}

void loop() 
{
  if (button = (HIGH));        // If button is pressed..
  {
  sms.beginSMS(480XXXXXXX);     // Number to send message to
  sms.print("Test Message");   // Message to send
  sms.endSMS();                // end send command
  }
}

Hi,
Welcome to the Forum

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html
then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks... Tom.. :slight_smile:

Ok, next time I will post sketches correctly.

Anyone have some input?

NateOdem:
Ok, next time I will post sketches correctly.

There's nothing stopping you from editing your earlier post and doing it this time. :wink:
Edit: Thanks for doing that. :slight_smile:

There are a number of things wrong with this:-if (button = (HIGH));        // If button is pressed..
First, you don't actually read the button.
Second, the semicolon on the end stops the conditional code from executing.
Third, = is an assignment operator, not a comparison. You want == .
So it should be:-

if(digitalRead(button) == HIGH)        // If button is pressed..
{
    // do stuff here
}

Edit: You might need to debounce the button press, or at the very least add a delay, to avoid the message being sent multiple times for a single button press.

I have already changed that. I am more focused on getting this part to work - and finding out how to do so, and why what I have isn't working (obviously I filled in the whole phone number)

  {
  sms.beginSMS(480XXXXXXX);         // Number to send message to
  sms.print("Test Message");        // Message to send
  sms.endSMS();                     // end send command
  }

I've never used a GSM module, but the first thing I notice is that you don't have quotation marks around the number. It should be "480XXXXXXX".

And if you'd already fixed the problem I mentioned earlier, you should have posted the corrected code, not the earlier flawed version.

You mentioned 'storing' a number, to send to. The example on the "Getting Started" page shows how that's done:-char remoteNumber[20]= "12125551212";or you could have multiple numbers in a two-dimensional array:-char remoteNumber[3][20]= {"12125551212","13254551212","12125563142"};then use them as 'remoteNumber[0]', 'remoteNumber[1]' etc.

In case you haven't seen it, here's the "Getting Started" page:- Getting Started with the Arduino GSM Shield

The example I saw didn’t have the number in quotes, but I put it in quotes and it now compiles. That’s progress! Thanks!!

If I can directly define the number without needing to use a variable, I’ll do that, as it will not change, and I will probably need to cut down the sketch size any way I can to get it all to fit. I am still waiting for the SIM cards to come in, so once they do, I’ll try it out. Here is the whole code, do you see anything else that prevent it from working?

Thanks again.

#include <GSM.h>              // Include library
#define PINNUMBER ""         // Create Pin Number instance (if needed)
GSM gsmAccess;
GSM_SMS sms;
const int button = 9;            // Create input instance of button on pin 9
int buttonState = 0;             // variable for button input
void setup() 
{
  pinMode (button, INPUT);   // Defines button pin as input
  Serial.begin(9600);           // Start Serial Comms (for debugging only)
  while (!Serial)                  // If not connected to Serial...
  {                                   //Do nothing
  }    
  Serial.println("Text Message Sender");  // if connected, print project name
  boolean notConnected = true;// Create connection state of GSM
  while (notConnected)        // If not connected to GSM
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) // Connect to GSM
    {
      notConnected = false;   // Change connection status
    } else 
    {
      Serial.println("Not connected"); // Print connection status to Serial
      delay(1000);
    }
  }
  Serial.println("GSM initialized");   // Print connection status to Serial
}
void loop() 
{
  buttonState = digitalRead(button);
  if (buttonState == (HIGH))        // If button is pressed..
  {
  sms.beginSMS("480XXXXXXX"); // Number to send message to
  sms.print("Test Message");       // Message to send
  sms.endSMS();                       // end send command
  }
}

A

NateOdem:
Here is the whole code, do you see anything else that prevent it from working?

Not immediately. It looks OK, although you might need that delay or some button debouncing/state change detection. (In this code, as it stands, a short 'delay()' would do the trick.)

Otherwise, (keeping in mind the fact that I've never used a GSM module), it looks OK.

A couple of technical points, (but they won't stop your code working).
You don't need the parenthesis around "HIGH" in this:-if (buttonState == (HIGH))        // If button is pressed..This is fine:-if (buttonState == HIGH)        // If button is pressed..

And to save precious SRAM storage space, when you have a constant string to be printed to the serial monitor, you can use the "F" macro like this:-Serial.println(F("Text Message Sender"));  // if connected, print project namewhich stores the string in program memory, instead of in SRAM.
It will probably work for 'sms.print()', too. (Test that, though, because I'm not positive. You'll soon get a compiler message if it's not OK. :wink: )

Edit: One other thing. I see that you have the button connected as active-high, which means that you must have an external pulldown resistor from the pin to ground.
You can simplify by removing the resistor and connecting the button from the pin to ground, then enabling the chip's internal pullup resistor for that pin. That's done with the 'pinMode()' statement, passing "INTERNAL_PULLUP":-pinMode(button, INTERNAL_PULLUP);Then, in your code, the button state will go LOW when the button is pressed. A simple change:-if (buttonState == LOW)        // If button is pressed..

I tried the "F" macro in both instances, and it actually increased the size a bit. The sms.print compiles ok, but again increases size.

as far as the active high button, a pull-down resistor is not a big deal, I am making a PCB to hold the modules, so a SMD resistor is not a big deal.

Thanks for all the help. I am now anxious to get the SIM cards and see how it works. And the best part is that I am learning.
I'll post when I get the cards.

NateOdem:
I tried the "F" macro in both instances, and it actually increased the size a bit. The sms.print compiles ok, but again increases size.

Yes, it increases code size, but should decrease RAM usage.

I just realised that I do have the GSM library installed. (I forgot that it's provided with the IDE.)

So first I compiled your code. The flash and SRAM usage:-
14330 bytes of flash program memory used.
932 bytes of SRAM used.

Then I added the "F" macro to all prints:-
14400 bytes of flash program memory used.
870 bytes of SRAM used.

Note that flash program memory usage has increased by 70 bytes. (Not important, since there's heaps of that - 32KB on an UNO)

SRAM usage has decreased by 62 bytes. (This is important, especially when you have a lot of serial prints. There isn't anywhere near as much SRAM - 2KB on an UNO.)

So you looked at the wrong figure, the "program storage space", instead of the "dynamic variables".

ok, gotcha. I am using a pro mini 5V/16Mhz MC.

NateOdem:
ok, gotcha. I am using a pro mini 5V/16Mhz MC.

To all intents and purposes, that is an UNO. I have a few of them too.

The only real difference is the bootloader. A standard Pro Mini uses the larger 2KB bootloader.
If you want to save some flash memory space, select "UNO" in the IDE, burn the bootloader, then in future select "UNO" again when you compile/upload code. The UNO uses the Optiboot bootloader, which is 1.5KB smaller.