Hello guys, i'm starting programming at arduino and i'm trying to make this project that should receive sms execute an action and answer with another sms that the action was executed, but he isn't answering me.
I hope someone could support me.
This is the code.
PS: SORRY ABOUT THE BAD ENGLISH.
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
char number[] = ""; //Guarda o número de telefone que enviou SMS para o Arduino.
char message[100]; //Armazena o texto contido no SMS enviado ao Arduino.
char pos; //Armazena a função de leitura de SMS não lidos;
void setup() {
Serial.begin(9600); //Inicializa a comunicação serial com velocidade de 9600 bits por segundos.
pinMode(13, OUTPUT);
if (gsm.begin(2400)) { // Inicializa a comunicação GSM e caso esteja em sincronia com a rede aparece a mesagem "READY", caso contrário aparece a mensagem "IDLE".
Serial.println("\nstatus=READY");
}
else {
Serial.println("\nstatus=IDLE");
}
}
void loop() {
//gsm.SimpleWriteln("AT+CSQ"); //COMANDO PARA INFORMAR O NÍVEL DO SINAL;
int led = digitalRead(13); // Atribui à variável "led" o estado lógico do pino 13 (Se é HIGH ou LOW).
pos = sms.IsSMSPresent(SMS_UNREAD); //Armazena a função de leitura de SMS não lidos;
if ((int)pos) { // Se a variável "pos" encontrar SMS não lido, as seguintes etapas serão realizadas:
sms.GetSMS((int)pos, number, message, 100); //GetSMS recebe o arquivo SMS, o número de origem do SMS, o texto contido no SMS, o limite de caracteres no corpo do SMS.
if (strstr (message, "Liga led") && strstr(number, "031971774886")) { // Se o texto contido na variável "message" for igual ao texto na função "strstr", o pino 13 irá alterar seu estado para HIGH.
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500);
if (led = HIGH) {
sms.SendSMS("031971774886", "LED LIGADO"); //Responde o SMS para o número contido na variável "number" com a frase dentro das aspas "". ******
delay(300);
}
}
if (strstr(message, "Desliga led") && strstr(number, "031971774886")) {
digitalWrite(13, LOW); // Se o texto contido na variável "message" for igual ao texto na função "strstr", o pino 13 irá alterar seu estado para HIGH.
delay(500);
if (led = LOW) {
sms.SendSMS("031971774886", "LED DESLIGADO");
delay(300);
}
}
if (strstr(message, "Reset shield") && strstr(number, "031971774886"))
{
digitalWrite(5, HIGH);
delay(500);
digitalWrite(5, LOW);
delay(1000);
sms.SendSMS("031971774886", "RESETADO");
delay(300);
}
else
{
sms.SendSMS(number, "ENVIE 'Liga led' PARA LIGAR O LED E 'Desliga led' PARA DESLIGAR O LED"); /* SE A MENSAGEM RECEBIDA FOR DIFERENTE DE "RAFAEL" SERÁ ENVIADO O TEXTO "MENSAGEM RECEBIDA COM SUCESSO";
ESTE COMANDO DE ENVIO DE SMS PODE SER TROCADO PARA O ACIONAMENTO DE UMA SAÍDA DO ARDUÍNO, POR EXEMPLO;*/
}
}
delay(2000); // TEMPO EM QUE O CÓDIGO É LIDO DE NOVO (VARREDURA DO PROGRAMA);
delet_sms();
//mostra_sinal();
delay(300);
};
/void mostra_sinal() {
Serial.print("\nSinal de rede:");
gsm.SimpleWriteln("AT+CSQ"); //COMANDO PARA INFORMAR O NÍVEL DO SINAL;
}/
void delet_sms() {
int i;
for (i = 0; i < 2; i++) {
pos = sms.IsSMSPresent(SMS_READ);
if (sms.DeleteSMS(pos) == 1) {
Serial.print("\nDeletando SMS da posicao ");
Serial.println(pos);
}
}
}