SIM800L not responding to messages

hello! i'm building a project that aims to detect increases in water level using pressure sensors. Im using Arduino UNO R3, a BMP180 pressure sensor and a GSM SIM800L module. the system integrates a sim800l module for sms alerts and real-time monitoring via SMS. The SIM800L module's tx and rx pins is connected to the d7 and d8 pins respectively. im powering the module by connecting the vin to the 5v pin of the UNO, my laptop is the main powersource as we test the functionality of the device. the realtime monitoring functions when a user sends an sms to the module and then the module will reply with the current water status. the system works well except for the real-time monitoring system, it actually worked once (responded to two-three messages consecutively) and then it just stopped responding for some reason. I am new to all this and my codes are only the ones i gathered from the internet, modified it and put it altogether, ive tried finding solutions in the internet but i couldn't. this is my current code:

#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <SoftwareSerial.h>

SoftwareSerial SIM800L(7, 8); // RX, TX
const float criticalHeight = 0.3;
Adafruit_BMP085 bmp;

String textMessage;
String CellNum;
String CellNumtemp;
float levelHeight;

// Function prototypes
String getSenderNumber(String message);
void sendStatusSMS(String message, String phoneNumber);
void sendSMS(float levelHeight);
void checkForSMS();
void initializeGSM();
bool alertSent = false;

void setup() {
  SIM800L.begin(9600); // Setting the baud rate of SIM800L Module
  Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println("SIM800L Ready");
  delay(100);
  if (!bmp.begin()) {
    Serial.println("BMP085 init failed!");
    while (1);
  }
  // Initialize GSM
  initializeGSM();
}

void loop() {
  double P = bmp.readPressure();
  double pressureDifference = P - 100917; // Adjust the baseline pressure as needed
  float levelHeight = pressureDifference / 9806.65; // Convert pressure to water height
  Serial.print("Pressure: "); Serial.print(P); Serial.println(" Pa");
  Serial.print("Water Height: "); Serial.print(levelHeight); Serial.println(" m");
  
  // Check if the water level is above the critical height and the alert has not been sent
  if (levelHeight >= criticalHeight && !alertSent) {
    sendSMS(levelHeight);
    alertSent = true; // Set the flag to true after sending the alert
  }
  
  // Reset the alertSent flag if the water level drops below the critical height
  if (levelHeight < criticalHeight) {
    alertSent = false;
  }
  
  checkForSMS();
  delay(3000);
}
void initializeGSM() {
  SIM800L.println("AT"); // Check communication with GSM module
  delay(1000);
  SIM800L.println("AT+CMGF=1"); // Set SMS text mode
  delay(1000);
  SIM800L.println("AT+CNMI=1,2,0,0,0"); // Configure module to send SMS data to the serial port when it arrives
  delay(1000);
}

void sendSMS(float levelHeight) {
  Serial.println("Sending Message");
  SIM800L.println("AT+CMGF=1"); // Sets the SIM800L Module in Text Mode
  delay(1000);
  Serial.println("Set SMS Number");
  SIM800L.println("AT+CMGS=\"+639089913790\""); // Mobile phone number to send message
  delay(1000);
  Serial.println("Set SMS Content");
  SIM800L.println("Critical water height exceeded! Current height: " + String(levelHeight, 2) + " m."); // Message content
  delay(100);
  Serial.println("Finish");
  SIM800L.write(26); // ASCII code of CTRL+Z for sending SMS
  delay(1000);
  Serial.println("Message has been sent");
}

void checkForSMS() {
  Serial.println("Reading SMS");
  SIM800L.print("AT+CMGF=1\r");
  delay(100);
  SIM800L.print("AT+CMGR=1\r");
  delay(10);
  if (SIM800L.available() > 0) {
    textMessage = SIM800L.readString();
    Serial.print(textMessage);
    delay(10);
  }
  if (textMessage.indexOf("Status") >= 0) {
    Serial.println("Status command received");
    CellNumtemp = textMessage.substring(textMessage.indexOf("+63"));
    CellNum = CellNumtemp.substring(0, 13);
    smsstato();
    // Clear temporary variables
    CellNumtemp = "";
    textMessage = "";
}
SIM800L.print("AT+CMGD=1\r");
delay(100);
SIM800L.print("AT+CMGD=2\r");
delay(100);
Serial.println("Status command received");
Serial.print("Phone number: "); Serial.println(CellNum);
}
void smsstato() {
  SIM800L.println("AT"); // Check communication with GSM module
  delay(1000);
  SIM800L.print("AT+CMGD=1\r");
  delay(100);
  SIM800L.print("AT+CMGF=1\r");
  delay(1000);
  SIM800L.print("AT+CMGS=\"");
  SIM800L.print(CellNum);
  SIM800L.print("\"\r");
  delay(1000);
  SIM800L.print("Water level status: ");
  SIM800L.print(String(levelHeight, 2));
  SIM800L.print(" meters");
  delay(1000);
  Serial.println("sms stato");
  SIM800L.write(26); // ASCII code of CTRL+Z for sending SMS
  delay(100);}

have a read of how-to-get-the-best-out-of-this-forum
e.g.

  1. what microcontroller are you using?
  2. upload a schematic of the wiring in particular showing how you power the SIM880
  3. what other devices to you have connected?
  4. does the SIM800 respond to basic AT commands?

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