-1

enter image description hereThere is a mistake in the design implementation of the code probably in if statment - when using the serial monitor it repeatedly shows printf() statements from the code instead of "Sending SMS message".

 // Include the GSM library
#include <MKRGSM.h>
#include<math.h>
#include<stdio.h>
int xp = A5;
int yp = A4;
int x,y;
#include "arduino_secrets.h" 
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[] = SECRET_PINNUMBER;

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;

void setup() {
    x=analogRead(xp);delay(2);
    y=analogRead(yp);delay(2);

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("SMS Messages Sender");
  pinMode(xp,INPUT);
  pinMode(yp,INPUT);

  // connection state
  boolean connected = false;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (!connected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      connected = true;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
}

void loop() {
    if ((x>=0.60) & (y>=40))

 Serial.print("AT+CMGF=1\r"); 
    delay(1000);  
    Serial.print("AT+CMGS=\"+491781234567\"\r"); 
    char remoteNum[20]; 


  // sms text
  Serial.print("your bike is in danger!");
  char txtMsg[200];

  Serial.println("SENDING");
  Serial.println();
  Serial.println("Message:");
  Serial.println(txtMsg);

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");
   delay(5000);
   if ((x<=0.30) & (y<=25))

 Serial.print("AT+CMGF=1\r"); 
    delay(1000);  
    Serial.print("AT+CMGS=\"+491781234567\"\r"); 


  // sms text
  Serial.print("your bike is in danger");
  Serial.println("SENDING");
  Serial.println();
  Serial.println("Message:");
  Serial.println(txtMsg);

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");
   delay(5000);
}
3
  • If that is a real phone number you should redact it, also you should have edited your other post instead of posting a new question.
    – esoterik
    Jun 29, 2018 at 0:39
  • 6
    you already asked this question .... please update your previous question and delete this one .... Problem with code for arduino GSM 1400 to send a SMS when tilt movment is detected
    – jsotola
    Jun 29, 2018 at 1:26
  • Nowhere in your code will it print "Sending SMS message". It should print "SENDING Message: <message text>". Please paste in the serial output that you are actually seeing, rather than describing it - in your original post rather than this duplicate.. Jun 29, 2018 at 6:10

1 Answer 1

-1

Your if statement is broken!

if(cond)
   statement; // this is conditional
statment2; // this will always be executed!

You need to use a code block:

if(cond)
{
    statement; // both statments are now 
    statement2; // conditional!
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.