GSM SIM800L - Call Repeatedly unitl picks

Hello Friends,

I’m trying to develop a project including the PIR Sensor, Module GSM SIM800L and Arduino MEGA.

Basically if the PIR Sensor detects any movement, it will send a signal to Arduino and the Arduino will

make a call.

I did it, but I want to increment 3 more functions.

  • If the person do not listen the call, the system will call again until the person pick the call;

  • If the person picks the call, the system will immediately hang up the call;

  • After hangs up, it will send a message.

There is the code:

I tried to include the function ‘rede’, to verify the data of the module and if it detects “NO ANSWER” it

would call again, but it doesn’t work. Maybe I’m not using perfectly the AT Commands.

#include <Sim800l.h> // just to send and receive sms
#include <SoftwareSerial.h>
SoftwareSerial gsm (10,11); // to call

Sim800l Sim800l;

void fazLigacao();
void rede();
String textSms, numberSms, telefone, call;
String str1 = “”;
uint8_t LED1 = 4; //Conexao Led vermelho
uint8_t LED2 = 5; //Conexao Led verde
int pir = 2;

char dados;

bool error;

char controlo = 0x00;
int leitura;
void setup()
{
pinMode(pir, INPUT);
gsm.begin(9600);
Serial.begin(9600);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(8, OUTPUT);
Sim800l.begin();
Serial.print(“Limpando SMS antigos…”);
error = Sim800l.delAllSms(); //Apaga SMS
Serial.println(" Apagados!");
Serial.println("\nAguardando comandos por SMS…");
error = Sim800l.sendSms("+258848401136",“SYSTEM INITIALIZED” );

}

void loop()
{
//Le o SMS da posicao 1
textSms = Sim800l.readSms(1);
//*****************************************

rede();

if(str1.indexOf(“NO ANSWER”)>=0)
{
fazLigacao();
}

//************************************************
if (controlo>0x00)//controlo do sensor
{
digitalWrite(LED1, HIGH);
leitura = digitalRead(pir);
if (leitura == HIGH)
{
digitalWrite(13, HIGH);
fazLigacao();
}
}

//*******************************************************
//Verifica se o SMS foi recebido e eh valido
if (textSms.indexOf(“OK”) != -1)
{
//Verifica se o SMS esta vazio
if (textSms.length() > 7)
{
//Retorna o numero do celular que enviou o SMS
numberSms = Sim800l.getNumberSms(1);
//Mostra o numero do telefone no Serial Monitor
Serial.println(numberSms);
//Converte o texto para maiusculas
textSms.toUpperCase();

//Caso receba L1, acende o led 1 (vermelho)
if (textSms.indexOf(“L1”) != -1)
{
Serial.println(“Led 1 Ligado”);
error = Sim800l.sendSms("+258848401136",“SYSTEM ENABLED” );
controlo++;

}
//Caso receba D1, apaga o led 1 (vermelho)
else if (textSms.indexOf(“D1”) != -1)
{
Serial.println(“Led 1 Desligado”);
digitalWrite(LED1, 0);
digitalWrite(13,0);
controlo = 0x00;
error = Sim800l.sendSms( “+258848401136”,“SYSTEM DISABLED”);
}
//Caso receba L2, acende o led 2 (verde)
else if (textSms.indexOf(“CHAMAR”) != -1)
{
fazLigacao();
}
//Caso receba D2, apaga o led 2 (verde)
else if (textSms.indexOf(“TESTE”) != -1)
{
digitalWrite(5,1);
delay(2000);
digitalWrite(5,0);
}
//Apaga todos as mensagens da memoria, garantindo que o proximo
//SMS esteja sempre na posicao 1
Sim800l.delAllSms();
}
}

}

void fazLigacao() {
gsm.println(“ATD848401136;”);
}

void rede ()
{
if (gsm.available())
{
str1 = gsm.readString();
}

}

Generally not a good idea to post your phone number inside code.
Also we will like you a lot more if you use the inline </> code tags !

Ok Thank you. I didn't know about this rule.

But can you help me in this problem ?

Assuming you haven’t made any changes yet…
Here’s the OP code from up top

Thoughts.
I’m not very good at understanding your commentary (in Spanish ?)
and i don’t use the off-the-shelf SMS libraries. I started from FONA - then rewrote most of it to be asynchronous/ non-blocking (but it’s too untidy to re-post yet!)

Try not to use Strings (big S) as they tend to screw up your memory footprint on a small processor like Arduino

Break your code (you have already started) so that functions are separate - and get them to work individually. Then join them together

#include <Sim800l.h> // just to send and receive sms
#include <SoftwareSerial.h>
SoftwareSerial gsm (10,11); // to call

Sim800l Sim800l;

void fazLigacao();
void rede();
String textSms, numberSms, telefone, call;
String str1 = "";
uint8_t LED1 = 4; //Conexao Led vermelho
uint8_t LED2 = 5; //Conexao Led verde
int pir = 2;

char dados;

bool error;

char controlo = 0x00;
int leitura;
void setup()
{
pinMode(pir, INPUT);
  gsm.begin(9600);
  Serial.begin(9600);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
   pinMode(8, OUTPUT);
  Sim800l.begin();
  Serial.print("Limpando SMS antigos...");
  error = Sim800l.delAllSms(); //Apaga SMS
  Serial.println(" Apagados!");
  Serial.println("\nAguardando comandos por SMS...");
  error = Sim800l.sendSms("+258848401136","SYSTEM INITIALIZED" );
}

void loop()
{
  //Le o SMS da posicao 1
   textSms = Sim800l.readSms(1);
//*****************************************

rede();  

  if(str1.indexOf("NO ANSWER")>=0)
  {
    fazLigacao();
  }


//************************************************
  if (controlo>0x00)//controlo do sensor
  {
    digitalWrite(LED1, HIGH);
    leitura = digitalRead(pir);
    if (leitura == HIGH)
    {
      digitalWrite(13, HIGH);
      fazLigacao();
    }
  }

//*******************************************************
  //Verifica se o SMS foi recebido e eh valido
  if (textSms.indexOf("OK") != -1)
  {
    //Verifica se o SMS esta vazio
    if (textSms.length() > 7)
    {
      //Retorna o numero do celular que enviou o SMS
      numberSms = Sim800l.getNumberSms(1);
      //Mostra o numero do telefone no Serial Monitor
      Serial.println(numberSms);
      //Converte o texto para maiusculas
      textSms.toUpperCase();

      //Caso receba L1, acende o led 1 (vermelho)
      if (textSms.indexOf("L1") != -1)
      {
        Serial.println("Led 1 Ligado");
        error = Sim800l.sendSms("+2588xxxxxxx","SYSTEM ENABLED" );
        controlo++;
      }
      //Caso receba D1, apaga o led 1 (vermelho)
      else if (textSms.indexOf("D1") != -1)
      {
        Serial.println("Led 1 Desligado");
        digitalWrite(LED1, 0);
        digitalWrite(13,0);
        controlo = 0x00;
        error = Sim800l.sendSms( "+2588xxxxxxx","SYSTEM DISABLED");
      }
      //Caso receba L2, acende o led 2 (verde)
      else if (textSms.indexOf("CHAMAR") != -1)
      {
        fazLigacao();
      }
      //Caso receba D2, apaga o led 2 (verde)
      else if (textSms.indexOf("TESTE") != -1)
      {
           digitalWrite(5,1);
           delay(2000);
           digitalWrite(5,0);
      }
      //Apaga todos as mensagens da memoria, garantindo que o proximo
      //SMS esteja sempre na posicao 1
      Sim800l.delAllSms();
    }
  }
}
  
//*******************************************************
void fazLigacao() {
   gsm.println("ATD84xxxxxxxxx;"); 
}

//*******************************************************
void rede () 
{
  if (gsm.available())
  {
       str1 = gsm.readString();
  }
}

After you’ve made your changes - use CTRL-T (the IDE code formatter) and re-post the updated code i a new reply.