Alarm project: Sim900 shield switching on the wrong output.

Hello everyone,

I’m very happy I found out this forum that contains great Arduino tutorials and trouble shooting information. Since it’s my first post and after looking tutorial on how to place new topics hoping this new topic finds you well and is setup correctly and at the right location.
Since I’m new in the Arduino world, google and this forum has learned me a lot already and helped me out few times already when trying the basic stuff.
To start a first ‘bigger’ alarm system project, I recently purchased the sim900 module and found out that it works really well. Unfortunately and since I wanted to modify the sketch a little (that I found on ‘open-electronics’) it does not seems to work anymore and was wondering if someone could have a quick look into it since I’m sure it must be something I overlooked and can’t understand from the code. Even do I spend already few evenings in finding what’s causing the issue I can’t find and writing this post now as my last resort in having the code working.

From ‘open-electronics - example 2’ I added 2 lines that trigger PIR sensor and a normal switch button. These 2 lines work, when the PIR detects movement the LED 10 goes on and when I press the switch button, the LED 11 turns on. Unfortunately when I send ON-SMS, LED13 should go on but it doesn’t, instead LED 10 goes on again, sending off-SMS, LED10 goes off. If I load back the original code, LED13 functions normal when sending SMS. So I’m lost on why adding those 2 output’s make the code not to function anymore. I really hope someone has a minute to look into the below code since it would help me big time in having my alarm system ready.

Lines added:

digitalWrite(R_PIR,digitalRead(PIR_Sensor));
digitalWrite(R_Door,digitalRead(Door_Sensor));

Full Sketch code:

// Example 2: http://www.open-electronics.org/how-to-send-and-receive-sms-with-gsmgprs-gps-shield/

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
#define PIR_Sensor 2     // the pin that the PIR is attached to
#define Door_Sensor 3    // the pin that the doorsensor is attached to

int ledPin = 13;  // EN: Pin of the LED to turn ON and OFF depending on the received message
int R_PIR = 10;     // the pin that the PIR is attached to
int R_Door = 11;    // the pin that the doorsensor is attached to

char number[]="+32xxxxxxxxx";
char message[180];
char pos;
char *p;


void setup()
{
 Serial.begin(9600);
  if (gsm.begin(2400))
    Serial.println("\nstatus=READY");
  else Serial.println("\nstatus=IDLE");
 pinMode(ledPin, OUTPUT ); 
 digitalWrite( ledPin, LOW );    // set ledpin status low
 pinMode(PIR_Sensor, INPUT);     // initialize the PIR-Sensor pin as input
 pinMode(Door_Sensor, INPUT);    // initialize the Door-Sensor pin as input
 pinMode(R_PIR, OUTPUT);
 pinMode(R_Door, OUTPUT);
};
 
void loop()
{
 pos=sms.IsSMSPresent(SMS_UNREAD);
 Serial.println((int)pos);
 if((int)pos>0&&(int)pos<=20){
   Serial.print("NUOVO MESSAGGIO, POS=");
   Serial.println((int)pos);
   message[0]='\0';
   sms.GetSMS((int)pos,number,message,180);
   p=strstr(message,"testpwd");
   if(p){
     Serial.println("PSWD OK");
     p=strstr(message,"LEDON");
     if(p){
       Serial.println("LED ON");
       digitalWrite(ledPin,HIGH);
     }
     else{
       p=strstr(message,"LEDOFF");
       if(p){
         Serial.println("LED OFF");
         digitalWrite(ledPin,LOW);
       }
     }
   }
   sms.DeleteSMS((int)pos);
 }
digitalWrite(R_PIR,digitalRead(PIR_Sensor));
digitalWrite(R_Door,digitalRead(Door_Sensor));
delay(500);
}

Many thanks in advance,
GS

Hello everyone,

Since my post yesterday noticed that I didn’t received responses, since it’s my first post was wondering if I may be misplaced the topic. If so please let me know so I can correct and have my issue resolved.

Many thanks in advance,
GS

#define PIR_Sensor 2     // the pin that the PIR is attached to
#define Door_Sensor 3    // the pin that the doorsensor is attached to
int R_PIR = 10;     // the pin that the PIR is attached to
int R_Door = 11;    // the pin that the doorsensor is attached to

What pins are being used by the GSM shield?

Hello PaulS,

many thanks for your response. Pins currently used by the GSM Shield:

pin 7 => Tx (software serial selected, not HW)
pin 8 => Rx (software serial selected, not HW)

Later on will be using ping 9 being the software power pin to switch on the Shield.
The shield and pin information can be found @ GPRS Shield V2.0 - Seeed Wiki

many thanks in advance,
GS

Hey everyone,

week ago now and some more testing and trying out different options but unfortunately without any positive result. Therefore wanted to ask if someone who may previously missed the post would have any ideas on what could be wrong?

Many thanks in advance,
GS

Hey you all,

after another two weeks of searching solution for hours and long nights, changing code the result is still that my sketch does not seems to work entirely!
In short problem is that every 3 hours I get message that motion is detected while the PIR is in a box, no movement, no light changes, sun, … nothing else in room that does anything. But still notice that every 3 hours for a unknown reason the PIR goes high, led on and SMS get send! when I measure, voltage is 0V all the time, if PIR detects motion it goes high and is showing 3.299V for few seconds (PIR onboard timer setting)
Now I also noticed that sometimes sending ‘smson’ or ‘smsoff’ it does what it should do = switch on/off led but also enables disables further SMS message sending (if Off) but before it switches the LED it makes PIR go high and triggers to send SMS motion! In addition, when I just call the device, the PIR sensor also get’s activated, motion sms gets send!!
So after looking for weeks into the code, re-writing, testing other PIR I’m douting that it’s not related to code but maybe something to do with GSM shield interference??

Anybody any idea or experienced similar behaviour?

Below the code + some result from serial monitor (many THANKS in advance for sharing ideas, code tips, …) Let’s hope we can have it nailed down and resolved soon :slight_smile: getting more or less frustrated about but learned already a lot what keeps me going in finding solution.
Thx GS

Sketch Code:

#include "SIM900.h"
#include <SoftwareSerial.h>

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;
boolean started = false;
boolean smsonoff = true;

//this code is based on the example of Arduino Labs simple sketch to send and receive SMS.
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 60;  
int numdata;
char smsbuffer[160];
char n[20];

unsigned long previousMillisPir1 = 0;
const unsigned long intervalPir1 = 120000;  // intervalPir1 at which to blink (milliseconds)
int valPir1 = 0;		            // value PIR1
int inputPir1Pin = 5;                       // PIR sensor pin 2
int pir1State = LOW;                        // we start, assuming no motion detected
int pir1Led = 11;                           // output led pin for Pir1

int smsLedonoff = 10;		            // switch on/off sms sending

void setup() 
{
  Serial.begin(9600);                      //Serial connection.
  Serial.println("GSM Shield testing.");

  if (gsm.begin(2400)){                    //Start configuration of shield with baudrate.
    Serial.println("\nstatus=READY");
    started=true;  
  }
  else Serial.println("\nstatus=IDLE");

  if(started){                            //Enable this two lines if you want to send an SMS.
    //if (sms.SendSMS("+32xxxxxxxxx", "Arduino SMS"))
    //Serial.println("\nSMS sent OK");
  }
  pinMode( 10, OUTPUT );                  // sms LED
  digitalWrite( 10, HIGH );               // set sms LED to High during start 
  pinMode( 11, OUTPUT );                  // PIR 1 Output LED
  pinMode( 5, INPUT);                     // PIR 1 Pin (5) defined input

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor 60sec. :");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(".");
    delay(1000);
  }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);
}

void loop() 
{
  int pos = 0;
  if(started){
    pos = sms.IsSMSPresent(SMS_ALL);
    if (pos) {
      delay(4000);                               //For testing
      Serial.println("Receiving SMS");           //Read if there are messages on SIM card and print them.
      Serial.println(pos);
      sms.GetSMS(pos, n, smsbuffer, 10);
      delay(1000);                               //For testing
      Serial.println(n);
      Serial.println(smsbuffer);

      // Temp reading can be plased her

        if (!strcmp(smsbuffer, "smson")) {
        smsonoff = true;
        digitalWrite(smsLedonoff, HIGH);
        Serial.println("SMS sending on");
        delay(1000); //test
      }
      if (!strcmp(smsbuffer, "smsoff")) {
        smsonoff = false;
        digitalWrite(smsLedonoff, LOW);
        Serial.println("SMS sending off");
        delay(1000); //test
      }
      delsms();
    }
  }
  Pir1Code();  
}    

void Pir1Code() {
  valPir1 = digitalRead(inputPir1Pin);
  unsigned long currentMillisPir1 = millis();

  if (valPir1 == HIGH) {
    delay(150);

    if ((unsigned long)(currentMillisPir1 - previousMillisPir1) > intervalPir1) {
      previousMillisPir1 = currentMillisPir1;
      if (pir1State == LOW) {
        Serial.println("BM Eetplaats high!");
        pir1State = HIGH;
        digitalWrite(pir1Led, HIGH);
        if (smsonoff) {	                                                                  //if sms sending is enabled send sms
          if (sms.SendSMS("+32xxxxxxxxx", "Bewegingsmelder Eetplaats Actief!"))
            Serial.println("\nSMS sent OK");
          Serial.print("motion 1 detected at ");
          Serial.print(currentMillisPir1/1000);
          Serial.println(" sec"); 
        }
      }
    }
  }
  else {
    delay(150);

    if (valPir1 == LOW) {
      // Serial.println("BM Eetplaats low!");

      pir1State = LOW;
      digitalWrite(pir1Led, LOW);
    }
  }
}

void delsms() {
  Serial.println("Checking SIM card for messages...");
  for (int i = 0; i < 10; i++) {
    int pos = sms.IsSMSPresent(SMS_ALL);
    if (pos != 0) {
      Serial.print("\nFound SMS at the position ");
      Serial.println(pos);
      if (sms.DeleteSMS(pos) == 1) {
        Serial.print("\nDeleted SMS at the position ");
        Serial.println(pos);
      }
      else
      {
        Serial.print("\nCant delete SMS at the position ");
        Serial.println(pos);
      }
    }
  }
  Serial.println("Done deleting and resuming Detection Loop");
}

Serial Monitor result:

status=READY
calibrating sensor 60sec. :… done
SENSOR ACTIVE
BM Eetplaats high!

SMS sent OK
motion 1 detected at 352 sec
Receiving SMS
1
+32xxxxxxxxx
smsoff
SMS sending off
Checking SIM card for messages…

Found SMS at the position 1

Deleted SMS at the position 1
Done deleting and resuming Detection Loop
BM Eetplaats high!
Receiving SMS
1
+32xxxxxxxxx
smson
SMS sending on
Checking SIM card for messages…

Found SMS at the position 1

Deleted SMS at the position 1
Done deleting and resuming Detection Loop
BM Eetplaats high!

SMS sent OK
motion 1 detected at 870 sec
BM Eetplaats high!

SMS sent OK
motion 1 detected at 9836 sec
BM Eetplaats high!

SMS sent OK
motion 1 detected at 19681 sec

Hi,

I am facing exactly the same problem. I think it's problem of noise in the line, i am trying to solve it by adding some capacitors without luck. Have you solved it? If so I would really appreciate some help. Thanks in advance.

Hello,

Indeed, yes I resolved the issue and all is working perfect now. :slight_smile:
To resolve, I used shielded cable between arduino and PIR, since then no more strange behaviour or false triggers.

Good luck

Regards,
Gsll

Thank you for your quick response! So you add shielded cables in the three lines then? vcc, gnd and out ?
Which shielding did you use? Could you send a link to the ones you bought?

I am a newbie , so I would like if maybe you could help me in understanding why this solved your issue. As I understand shilding wires it's useful for the noise that is inciding in the wire from the outside, but in this case it really looks like a noisy gnd line , so the external noise shouldn't be the problem right??

Hello,

The shielded cable I used is like a normal alarm, videphone, ... Cable and contains 4 wires inside. I tested with 1 meter first and worked, now it's around 3-4 meters of cable and still works fine :slight_smile:
Normal cat5 network cable is also shielded so that should work as well.

I did not added anything else, just a normal standard shielded 4-wire cable.

Good luck,
GS

it worksssss

thanks

remark;

if using gsmshield

change the gsm.h file;

tx rx on 7 and 8 for Uno

9 shield power
9 reset disable

and than succes.

thanks i was needing this program for a greenhouse protection

does any body knows if it would be possible to at a cam for snap shot

thanks Frank

does any body knows if it would be possible to at a cam for snap shot

I've never hear of anyone being able to "at" a cam.

Adding a camera is a different story.