I was testing the sim800l module with a code to read SMS from the following blog.
below which is from Controlar dispositivos electrónicos a través de mensajes de texto – SIM800L y Arduino – El Taller De TD
At first, it worked properly but suddenly it stopped receiving data. It seems like the module is connected to the network because the light blinks every 3 seconds but the sim either doesn't receive any data when is in the module or it cannot deliver it to the Arduino. If I use Serial.read() (in my code SIM800L.read()) it returns -1 which means that there's no data to read.
The first time I used the module I was working with an Arduino UNO and it was working perfectly but I had to change to an Arduino MEGA 2560 and then started to happen what I described before. I decided to go back to Arduino UNO but the problem persists. I have checked if is an alimentation problem or that I burn the sim800l but that is not the case, I even buy a new module thinking maybe I had damaged the RX pin but the new one doesn't work either.
This is the code I'm using:
#include <SoftwareSerial.h> //Incluimos la libreria Software Serial
//Creado por youtube/ElTallerDeTD
//eltallerdetd@gmail.com
SoftwareSerial SIM800L(8,9); //Instanciamos el objeto SIM800L y le pasamos los parametros de los pines TX y RX
String valor; //Declaramos la variable de tipo String valor.
int num;
void setup() {
pinMode(13, OUTPUT); //Declarar el pin 13 como salida.
Serial.begin(115200); //Inicializamos la primera comunicacion Serial.
SIM800L.begin(115200); //Inicializamos la segunda comunicacion Serial.
SIM800L.println("AT+CMGF=1"); //Vamos utilizar los SMS.
delay(100); //Delay de 0.1 sec
SIM800L.println("AT+CNMI=1,2,0,0,0"); //Configurar el SIM800L p/ que muestre msm por com. serie.
}
void loop() {
//Lograr que nos muestre lo que nos llega de mensaje por el monitor serial.
valor = SIM800L.read(); //Guardar en la var valor el sms que recibe el Arduino
Serial.println("Nuevo SMS: "+ valor); //Imprime ese SMS en el monitor Serial
if(SIM800L.available()>0){
valor = SIM800L.readString(); //Guardar en la var valor el sms que recibe el Arduino
Serial.println("Nuevo SMS: "+ valor); //Imprime ese SMS en el monitor Serial
}
if(valor.indexOf("ON")>=0){ //Si la var valor tiene la palabra ON hace esto:
digitalWrite(13, HIGH); //Se enciende el pin 13.
Serial.println("El Led se encendio"); //Immprime el mensaje
delay(15000);
}else{
digitalWrite(13, LOW); //Se apaga el pin 13.
Serial.println("El Led se apago"); //Immprime el mensaje
delay(15000);
}
}
NOTE: I have used many other codes and still have the same problem, but I think this is the easiest that I found.