Sim 900 and pir sensor

Hi, guys, i cant make to send sms any pir event, pls help

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
String incomingData;  
String message = "";
String stareAP = "";
String mesajPornire = "";
//int relay_pin = 12;
#define pirPin 11 
int calibrationTime = 30; 
long unsigned int lowIn; 
long unsigned int pause = 5000; 
boolean lockLow = true; 
boolean takeLowTime; 
int PIRValue = 0;



void setup()
{
  delay(20000);
  Serial.begin(19200); // baudrate for serial monitor
  SIM900.begin(19200); // baudrate for GSM shield
  //pinMode(relay_pin, OUTPUT);
  pinMode(pirPin, INPUT);
  //digitalWrite(relay_pin, HIGH);  
  SIM900.print("AT+CMGF=1\r");
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
  mesajPornire = "Initializare aparat...";
  send_message(mesajPornire);
}
void loop()
{
  receive_message();
  if (incomingData.indexOf("on") >= 0)
  {
    //digitalWrite(relay_pin, HIGH);
    message = "ONline";
    send_message(message);
    PIRSensor();
  }
  if (incomingData.indexOf("off") >= 0)
  {
    //digitalWrite(relay_pin, LOW);
    message = "OFFline";
    send_message(message);
  }
  if (incomingData.indexOf("stare") >= 0)
  {
    //digitalWrite(relay_pin, LOW);
   //String stareAP = "Activ";
    send_message(message);
  }
    
}
void send_message(String message)
{
  SIM900.println("AT+CMGF=1");    //Set the GSM Module in Text Mode
  delay(100);
  SIM900.println("AT+CMGS=\"+4074141xxxx\""); // Replace it with your mobile number
  delay(100);
  SIM900.println(message);   // The SMS text you want to send
  delay(100);
  SIM900.println((char)26);  // ASCII code of CTRL+Z
  delay(100);
  SIM900.println();
  delay(1000);
}

void receive_message()
{
  if (SIM900.available() > 0)
  {
    incomingData = SIM900.readString();
    Serial.print(incomingData);
    delay(10);
  }
void PIRSensor() 
{ 
    if(digitalRead(pirPin) == HIGH) 
    { 
        if(lockLow) 
        { 
            PIRValue = 1; 
            lockLow = false; 
            Serial.println("Motion detected.");
            message = "miscare detectata";
            send_message(message);
            delay(50); 
        } 
        takeLowTime = true; 
    } 
    if(digitalRead(pirPin) == LOW)
    { 
        if(takeLowTime)
        { 
            lowIn = millis();
            takeLowTime = false; 
        } 
        if(!lockLow && millis() - lowIn > pause)
        { 
            PIRValue = 0; 
            lockLow = true; 
            Serial.println("Motion ended.");
            message = "fara miscare";
            send_message(message);
            delay(50); 
        } 
    }     
}

What's the output of your code now? Isn't it behaving as you want it to? Are you getting SMS?

You are declaring this inside void receive_message()

Yes, I receive sms, the problem was that I don't receive when movement is detected

As Xfpd has pointed out, looks like there are some mistakes in your brackets. void receive_message() and void PIRSensor() are two different functions. But you have written void PIRSensor() inside void receive_message(). void receive_message() should be defined like the following:


void receive_message()
{
  if (SIM900.available() > 0)
  {
    incomingData = SIM900.readString();
    Serial.print(incomingData);
    delay(10);
  }
}

But you have missed the last bracket here and put it somewhere else. Please correct it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.