Arduino not receiving sms commands

Hello hi, sorry am trying to design SMS based prepaid water meter system but when i try to recharge the system by sending sms like 500 or when i need to know the status of the balance available in the system by sending sms command STATUS nothing it happen on the system side the arduino not receiving sms commands i don't know why, please anyone help me to solve this problem, below is the full code.

#include <LiquidCrystal.h>
#include <EEPROM.h>

// Define pin connections for motorized ball valve and flow sensor
const int valvePin = 11;
const int flowSensorPin = 2;
const int button = 12;

// Define pin connections for LCD display
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);

// Define phone number to accept SMS messages from
const char* validPhoneNumber = "+33756491202";
const char* operator_Number = "+33756491201";

// Define starting amount of water
float waterAmount = 0.0;

// Define EEPROM address to store water amount
int eepromAddress = 0;
int remaining_water=0,old_amount=0,stop_flag=0,stop_INT=0;

void setup() {
  // Initialize LCD display
  lcd.begin(16, 2);

  // Initialize motorized ball valve pin as output
  pinMode(valvePin, OUTPUT);

  // Initialize flow sensor pin as input
  pinMode(flowSensorPin, INPUT);
  pinMode(button, INPUT_PULLUP);

  // Initialize GSM module
  Serial.begin(9600);

      Serial.println("AT");
      delay(1000);
      Serial.println("AT");
      delay(1000);
  // Read stored water amount from EEPROM
  EEPROM.get(eepromAddress, remaining_water);
      delay(1000);

  lcd.clear();
}

void loop() {
  // Measure flow rate and update water amount
   float flowRate = pulseIn(flowSensorPin, HIGH);
  waterAmount += flowRate / 7.5;
  float waterAmountLiters = waterAmount / 1000; // Convert to liters

  // Display water amount in liters on LCD
  // Display water amount on LCD
  lcd.setCursor(0, 0);
  lcd.print("FLING WTR:");
  lcd.print(waterAmountLiters);
  
  lcd.setCursor(0, 1);
  lcd.print("REAMIN WTR: ");
  lcd.print(remaining_water);

  // Check for incoming SMS messages
  if (Serial.available()) {
    String sms = Serial.readString();

    // Parse phone number and message from SMS
    int phoneNumEnd = sms.indexOf(",");
    String phoneNumber = sms.substring(0, phoneNumEnd);
    String message = sms.substring(phoneNumEnd + 1);

    // Check if phone number is valid
    if (phoneNumber == validPhoneNumber) {
      if (sms.indexOf("STATUS") == -1) {
      // Convert message to float and update water amount
      float waterAmount_receive = message.toFloat();
      remaining_water= waterAmount_receive + old_amount;

      // Store new water amount in EEPROM
      EEPROM.put(eepromAddress, remaining_water);


      // Send confirmation SMS to sender
      Serial.println("AT+CMGF=1");
      delay(1000);
      Serial.println("AT+CMGS=\""+String(validPhoneNumber)+"\"");
      delay(1000);
      Serial.print("New water amount set to: ");
      Serial.print(remaining_water);
      delay(100);
      Serial.write((byte)26);
      delay(1000);
      stop_INT=0;
    }
    //of messge ststud is receieve send ststus
   if (sms.indexOf("STATUS") != -1) {
 // Send confirmation SMS to sender
      Serial.println("AT+CMGF=1");
      delay(1000);
      Serial.println("AT+CMGS=\""+String(validPhoneNumber)+"\"");
      delay(1000);
      Serial.print("remaining water is ");
      Serial.print(remaining_water);
      delay(100);
      Serial.write((byte)26);
      delay(1000);
    
   }
    }
  }
if(digitalRead(button)==LOW ){
if (!stop_flag){
 if (remaining_water > 0) {
    digitalWrite(valvePin, HIGH);
    waterAmountLiters=0;
  }
stop_flag=1;
}else{
 digitalWrite(valvePin, LOW);
old_amount=remaining_water-waterAmountLiters;
remaining_water=old_amount;
      EEPROM.put(eepromAddress, remaining_water);
      delay(200);
stop_flag=0;
}
}
  // Check if water [amount is too low and close valve if necessary
 if(remaining_water<=0 && !stop_INT){
 // Send confirmation SMS to sender
      Serial.println("AT+CMGF=1");
      delay(1000);
      Serial.println("AT+CMGS=\""+String(validPhoneNumber)+"\"");
      delay(1000);
      Serial.print("NO AMOUNT IS REMAINING IN MACHINE PLEASE UPDATE");
      delay(100);
      Serial.write((byte)26);
      delay(2000);
// Send confirmation SMS to operator
      Serial.println("AT+CMGF=1");
      delay(1000);
      Serial.println("AT+CMGS=\""+String(operator_Number)+"\"");
      delay(1000);
      Serial.print("NO AMOUNT IS REMAINING IN MACHINE PLEASE contact OWNER");
      delay(100);
      Serial.write((byte)26);
      delay(1000);  
  stop_INT=1;
 }
}

Is that the kind of project you mean?

PS: You posted your phone number. Just an info, maybe not everyone likes to see it.

No, just read my explanations above.

What do you mean?

What sort of SMS/GSM module are you using? Have you confirmed that it is working right -- is powered on, connected to a mobile network, serial lines wired properly and it responds to serial commands? How is your Arduino powered? If is it connected to a USB, it is normally not possible to connect another serial device (the GSM modem) since the main serial connection is connected to the USB chip on the board. Consider using software serial on other pins to talk to the GSM module.

I would consider adding some method to debug the connection to your program -- eg: display something on the LCD as your code talks to the GSM module, so you can see what is going on. Using software serial on other pins to talk to the GSM module would allow you to copy useful debug information to the serial monitor and see what is happening.

Consider using a pre-designed and documented GSM module library to talk to the module. These have good debugging and error-checking that will help you get it working.

It's your number?

Gsm it works fine coz I can see commands on serial monitor that I send from the phone.

Please read my explanations above

1 Like

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