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;
}
}