SMS message from GSM shield when a float activates

Hi

I am trying to get a SIM5320A GSM shield to send an SMS to a mobile phone when a switch float activates. I can get it to send an SMS manually but not automatically when the switch float activates. I also can see that the switch floats work but I just can't seem to get them to work together. Any ideas anyone? Does anyone know the correct coding to allow this to happen?

I have been trying to use:
#include <GSM.h>
#include "Adafruit_FONA.h"

#define FONA_TX 2
#define FONA_RX 3
#define FONA_RST 9

boolean state, lastState;

GSM gsmAccess;
GSM_SMS sms;

void setup()
{
pinMode(2, INPUT_PULLUP);
state = digitalRead(2);
lastState = state;

Serial.begin(115200);

delay(1000);
}

void loop()
{

lastState = state;
state = digitalRead(2);

if ( state != lastState ) {
sendSMS();
}

delay(500);
}

void sendSMS() {
Serial.print("Switch was turned ");
Serial.println(state ? "off" : "on");
char txtMsg[200];
Serial.println(txtMsg);

delay (500);

sendSMS("AT+CMGS="+6405701420"");

delay (500);

sendSMS ("Switch was turned ");
sendSMS ? "on" : "off");

delay(500);
}

Cheers

Hi

I am trying to get a SIM5320A GSM shield to send an SMS to a mobile phone when a switch float activates. I can get it to send an SMS manually but not automatically when the switch float activates. I also can see that the switch floats work but I just can't seem to get them to work together. Any ideas anyone? Does anyone know the correct coding to allow this to happen?

I have been trying to use:
#include <GSM.h>
#include "Adafruit_FONA.h"

#define FONA_TX 2
#define FONA_RX 3
#define FONA_RST 9

boolean state, lastState;

GSM gsmAccess;
GSM_SMS sms;

void setup()
{
pinMode(2, INPUT_PULLUP);
state = digitalRead(2);
lastState = state;

Serial.begin(115200);

delay(1000);
}

void loop()
{

lastState = state;
state = digitalRead(2);

if ( state != lastState ) {
sendSMS();
}

delay(500);
}

void sendSMS() {
Serial.print("Switch was turned ");
Serial.println(state ? "off" : "on");
char txtMsg[200];
Serial.println(txtMsg);

delay (500);

sendSMS("AT+CMGS="+6405701420"");

delay (500);

sendSMS ("Switch was turned ");
sendSMS ? "on" : "off");

delay(500);
}

Cheers

Hi

I am trying to get a SIM5320A GSM shield to send an SMS to a mobile phone when a switch float activates. I can get it to send an SMS manually but not automatically when the switch float activates. I also can see that the switch floats work but I just can't seem to get them to work together. Any ideas anyone? Does anyone know the correct coding to allow this to happen?

I have been trying to use:
#include <GSM.h>
#include "Adafruit_FONA.h"

#define FONA_TX 2
#define FONA_RX 3
#define FONA_RST 9

boolean state, lastState;

GSM gsmAccess;
GSM_SMS sms;

void setup()
{
pinMode(2, INPUT_PULLUP);
state = digitalRead(2);
lastState = state;

Serial.begin(115200);

delay(1000);
}

void loop()
{

lastState = state;
state = digitalRead(2);

if ( state != lastState ) {
sendSMS();
}

delay(500);
}

void sendSMS() {
Serial.print("Switch was turned ");
Serial.println(state ? "off" : "on");
char txtMsg[200];
Serial.println(txtMsg);

delay (500);

sendSMS("AT+CMGS="+6405701420"");

delay (500);

sendSMS ("Switch was turned ");
sendSMS ? "on" : "off");

delay(500);
}

Cheers

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]`` [color=blue]// your code is here[/color] ``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason just make for more scrolling when we're trying to read your code.

When your code requires a library that's not included with the Arduino IDE please always post a link (using the chain link icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

Sorry. My first time using a forum and I didn't realise.

Threads merged.

Am I right to say assuming there is no reply this is impossible?

Please read reply #5. Invest a little of your time if you want us to invest ours.

/*  NOT COMPILED or checked for detail */

#include <GSM.h>
#include "Adafruit_FONA.h"

#define FONA_TX 2
#define FONA_RX 3
#define FONA_RST 9
#define SWITCH_PIN x  // you're gonna need this

boolean switch_state, prev_state;

GSM gsmAccess;
GSM_SMS sms;

// -----------------------------
void setup()
{
  // not needed, FONA / serial looks after this
  // and it's an OUTPUT anyway !
  // pinMode(2, INPUT_PULLUP); 
  // why are you reading the TX pin state ?
  // state = digitalRead(2);
  // prev_state = state;

  Serial.begin(115200);
  delay(1000);  // ???
}

// -----------------------------
void loop()
{
  // prev_state = state;
  // state = digitalRead(2);
 
  switch_state = digitalRead(SWITCH_PIN);
  if ( switch_state != prev_state ) {
    sendSMS();
    prev_state = switch_state;  // to avoid multiple trigger events
  }
 // this may be better served by a minimum trigger interval to avoid message storms!
  delay(500);  // ???  
}
// -----------------------------
void sendSMS() {
  // makes more sense to put this message up when the state is detected...
  // it has nothing to do with sendSMS()
  Serial.print("Switch was turned ");
  Serial.println(switch_state ? "on" : "off");
 
  // what is this?
  // You're creating a  new *empty* buffer - then printing it (nothing)
  char txtMsg[200];
  Serial.println(txtMsg);
  delay (500);

 sendSMS("AT+CMGS=\"+64xxxxxxxx\"");  // thanks for the number!
 delay (500);

 // just wrong.
 // two separate messages, the second one won't even compile
 sendSMS ("Switch was turned ");
 sendSMS ? "on" : "off");
  delay(500);  // ???
}