SMS is sended without stopping ?

Hello,

I'm using GSM-shield V2 with Arduino Uno, GSM.h Library and IDE 1.8.10.

The SMS function seems to repeat endlessly to send SMS's.

I use a Motion detector to trigger the SMS function.
I tested it without SMS sending and the Motion trigger runs and stops as expected, but not with the SMS sending activated.

What could be the cause ?

void loop() {
 if(digitalRead(PIR) == HIGH) {
  Serial.println("PIR run");
  delay(3000);
  sendSMS();
  digitalWrite(PIR, LOW);
 }
 if(digitalRead(PIR) == LOW) {
  Serial.println("PIR stop");
 }
}

void sendSMS() {
  Serial.println("sending SMS");
  /*char remoteNum[20] = {"someNumber"};  // telephone number to send sms
  // sms text
  char txtMsg[200] = {"Hi, someone seems into your Object !?"};

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();*/
  digitalWrite(PIR, LOW);
}

Please post your entire script so we can see how everything is being initialized.

Is PIR configured as an input or an output? If it is configured as an input then a digital write with a LOW will disable the internal pullup. Is this what you want?

From the Arduino reference:

"If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor."

Don't know if I should use INPUT_PULLUP.

The Code :

#include <GSM.h>

#define PINNUMBER ""
#define PIR 8

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
GSMVoiceCall vcs;
char numtel[20];

void setup() {
  Serial.begin(9600);
  //Serial.println("setup-okay");
  // connection state
  bool 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) {
      //Serial.println("connected");
      notConnected = false;
      theGSM3ShieldV1ModemCore.println("AT+QAUDCH=1"); // trying to get Audio/Speaker/Microphone) through Audiojack
      theGSM3ShieldV1ModemCore.println("AT+QMIC");     // ""
    } else {
      //Serial.println("Not connected");
      delay(1000);
    }
  }
  vcs.hangCall();
  //Serial.println("Waiting!");
}

void loop() {
 if(digitalRead(PIR) == HIGH) {
  Serial.println("PIR run");
  delay(3000);
  sendSMS();
  digitalWrite(PIR, LOW);
 }
 if(digitalRead(PIR) == LOW) {
  Serial.println("PIR stop");
 }
 switch (vcs.getvoiceCallStatus()) {
    case IDLE_CALL: // Nothing is happening

      break;

    case RECEIVINGCALL: // Yes! Someone is calling us
      // Retrieve the calling number
      vcs.retrieveCallingNumber(numtel, 20);

      // Answer the call, establish the call
      vcs.answerCall();
      break;

    case TALKING:  // In this case the call would be established
      
      break;
  }
  delay(1000);
}

void sendSMS() {
  Serial.println("sending SMS");
  /*char remoteNum[20] = {"someNumber"};  // telephone number to send sms
  // sms text
  char txtMsg[200] = {"Hi, someone seems into your Object !?"};

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();*/
  digitalWrite(PIR, LOW);
}

By default the pin will be an input with no pullup since you did not use the pinmode() call. In that case I am not sure why you are using a digitalWrite for an input pin. Why are you?

I can't tell you whether you need INPUT_PULLUP because I am not familiar with how your motion detector works. If the input is free-floating when there is no motion then you need INPUT_PULLUP otherwise the input could bounce around. If the input is grounded when there is no motion and 5V when there is then you do not need a pullup.

Also, does SMS by itself just send one message?

Hello,

Normal I used pinMode(PIR, INPUT);, just forgot it to write it in again.
As the Pin 8 did not get low by SMS, I used digitalWrite(PIR, LOW); to get sure it is low.

The Motion detector, is not free-floating, i measured the behavior, it is 3.3 Volt high and 0 Volt low. It have 5 Volt and Ground Connectors.

What do you mean, that SMS ist just sending one message by itself ?
The SMS Code is in th loop(). Should I try to write it in the setup(), to let it execute one time ?

Thanks

Hi,
You are checking to see if PIR IS HIGH.
You should be checking for when PIR GOES FROM LOW TO HIGH.

You cannot set the PIR LOW, the PIR will pull it HIGH as it has detected someone in the room.

Tom... :slight_smile:

Hello,

I tried to checking if the PIR is LOW and then trigger SMS, it sends less SMS but still endless.

And I measured also the Voltage on PIN 8 of the GSM-Shield, with SMS enabled and not.
With the Wire of the PIR connected to the Arduino's PIN 8, it shows constanly HIGH 3.3 Volt.
When I pull out the Wire from the Arduino's PIN 8, it shows only HIGH 3.3 Volt , when triggered.

When SMS is disabled, it's as the PIR work, with Wire connected or disconnected.

Why it's ever HIGH and do not get LOW, as the PIR works, when SMS is enabled ?
Maybe I need a parallel Capacitor and Resistor, to filter some remaining current ?

Without sending SMS, the output seems :

PIR stop
PIR stop
PIR stop
PIR stop
PIR stop
PIR stop
PIR run // Motion detected
sending SMS
PIR stop
PIR stop
PIR stop
PIR stop
PIR stop
//... until the PIR triggers again

With sending SMS activated it seems :

**PIR run **
sending SMS
**PIR run **
sending SMS
**PIR run **
sending SMS
**PIR run **
sending SMS
**PIR run **
sending SMS
**PIR run **
sending SMS
**PIR run **
sending SMS
//... endless

Thank you

Hello,

When the SMS send function is enabled it sends repeatedly.

SMS sends just one time when I pasted the Code to the setup() Function and enabled it only there, doesn't seems SMS would be defect.

I changed something in the Code.

Instead of reading from a digital Pin, now I try to read from an analog Pin, through the Voltage-value.

But the Problem that SMS sending is holding the Voltage of the PIR Pin HIGH, and sending ever, persists.

? :

void loop() {
 float value = analogRead(PIR);
 float voltage = value * 0.00322265625;
 Serial.println(voltage);
 if(voltage == 2.24 || voltage == 2.25 || voltage == 2.26) { // around 2.26 volt is the value when the PIR pin is HIGH.
  Serial.println("PIR run");
  delay(3000);
  sendSMS();                
  //digitalWrite(PIR, LOW);
 }
 if(voltage == 0) {
  Serial.println("PIR stop");
 }
}

TomGeorge:
Hi,
You are checking to see if PIR IS HIGH.
You should be checking for when PIR GOES FROM LOW TO HIGH.

You cannot set the PIR LOW, the PIR will pull it HIGH as it has detected someone in the room.

Tom... :slight_smile:

Hello Tom,

How may I check, when it goes from LOW to HIGH, how to code ?

Thanks

Solved,

For the Moment it seems to work, probably because of the PIR's(hc-sr501) Jumper-function.

Well, I tried almost all possibilitys as I knew.

But now it works, I will explain the case in which it sends SMS only when triggered by the PIR motion detector.

I used instead of SMS sending a LED to light on when the motion was detected.
Because the PIR have an Jumper, I switched it to trigger everytime something is moved and not only after the time past.
I re-enabled SMS to see if it works.
The LED have as addition, a Resistor and Capacitor in parallel, to filter some returning current.

#include <GSM.h>

#define PINNUMBER ""
#define PIR 8

// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
GSMVoiceCall vcs;
char numtel[20];

void setup() {
  Serial.begin(9600);
  pinMode(PIR, INPUT);
  pinMode(12, OUTPUT);
  // connection state
  bool 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) {
      //Serial.println("connected");
      notConnected = false;
      theGSM3ShieldV1ModemCore.println("AT+QAUDCH=1"); // trying to get Audio/Speaker/Microphone) through Audiojack
      theGSM3ShieldV1ModemCore.println("AT+QMIC");     // ""
    } else {
      //Serial.println("Not connected");
      delay(1000);
    }
  }
  vcs.hangCall();
  //Serial.println("Waiting for a call!");
}

void loop() {
 if(digitalRead(PIR) != LOW) {
  Serial.println("PIR run");
  sendSMS();
 }
 if(digitalRead != HIGH) {
  Serial.println("PIR stop");
  digitalWrite(12, LOW);
  delay(2000);
 }
 switch (vcs.getvoiceCallStatus()) {
    case IDLE_CALL: // Nothing is happening

      break;

    case RECEIVINGCALL: // Yes! Someone is calling us
      // Retrieve the calling number
      vcs.retrieveCallingNumber(numtel, 20);

      // Answer the call, establish the call
      vcs.answerCall();
      break;

    case TALKING:  // In this case the call would be established
      
      break;
  }
  delay(1000);
}

void sendSMS() {
  Serial.println("sending SMS");
  char remoteNum[20] = {"someNumber"};  // telephone number to send sms
  // sms text
  char txtMsg[200] = {"Hi, someone seems into your Object !?"};

  // send the message
  sms.beginSMS(remoteNum);
  sms.print(txtMsg);
  sms.endSMS();
  digitalWrite(12, HIGH);
  delay(2000);
}