Problem of GSM Voltage Monitoring

I'm doing a project about a GSM Switch with voltage monitoring. When I sent a SMS to the GSM Switch, it will replay my phone with SMS that how many voltage the GSM Switch now. However, my problem is when I sent a SMS to the GSM Switch request for the voltage information, it keeps sending the SMS (non-stop) to reply me how many voltage now. I want it reply only one SMS to me when I sent a request.

Anyone can help me to fix this problem, please.

I'm using Arduino Uno, Voltage Sensor, 2 Relay Switch and SIM900 GSM Module.

Here is my code:

#include <SoftwareSerial.h>

// Configure software serial port
SoftwareSerial SIM900(7, 8);

// Variable to store Phone No
// REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
// USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
String PhoneNo = "+xxxxxxxxxxx";

// Variable to store text message
String textMessage;

String VoltageString;

// want SMS show relay off by default
String Relay1State = "Off";
String Relay2State = "Off";

// Voltage Sensor
int analogInput = A1;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; //  
float R2 = 7500.0; // 
int value = 0;

const int Relay1 = 11;      // Relay1 connected to pin 11
const int Relay2 = 12;      // Relay2 connected to pin 12

void setup() {
  pinMode(Relay1, OUTPUT);   // Set relay as OUTPUT
  pinMode(Relay2, OUTPUT);   // Set relay as OUTPUT
  pinMode(analogInput, INPUT);   // Set Voltage sensor as INPUT
  
  // By default the relay is off
  digitalWrite(Relay1, HIGH);
  digitalWrite(Relay2, HIGH);
    
  SIM900.begin(19200);         // Arduino communicates with SIM900 GSM shield at a baud rate of 19200
  Serial.begin(9600);

 // Give time to your GSM shield log on to network
  delay(10000); 

  // AT command to set SIM900 to SMS mode
  SIM900.print("AT+CMGF=1\r"); 
  delay(100);

  // Set module to send SMS data to serial out upon receipt 
  SIM900.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);

  // Send the SMS
  sendSMS();
 
}

void CheckVoltage() {
  // Check voltage
  value = analogRead(analogInput);    // read the value at analog input
  vout = (value * 5.0) / 1024.0;  // see text
  vin = vout / (R2/(R1+R2));
  VoltageString = String(vin,2);   // Convert float to String
  VoltageString = (VoltageString + "v");

  delay(500);
}

void sendSMS() {
  SIM900.println("AT + CMGS = \"" + PhoneNo + "\""); 
  delay(100);
  
  // REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
  SIM900.println("GSM Switch Ready"); 
  delay(100);

  // End AT command with a ^Z, ASCII code 26
  SIM900.println((char)26); 
  delay(100);
  SIM900.println();
  // Give module time to send SMS
  delay(5000); 
}

// Function that sends State SMS
void sendState(String statemessage) {
  // AT command to set SIM900 to SMS mode
  SIM900.print("AT+CMGF=1\r"); 
  delay(100);

  SIM900.println("AT + CMGS = \"" + PhoneNo + "\""); 
  delay(100);
  
  // Send the SMS
  SIM900.println(statemessage); 
  delay(100);

  // End AT command with a ^Z, ASCII code 26
  SIM900.println((char)26);    // ctrl+z
  delay(100);
  SIM900.println();
  // Give module time to send SMS
  delay(5000);  
}

// Function that sends Voltage SMS
void sendVoltage(String voltagemessage) {
  // AT command to set SIM900 to SMS mode
  SIM900.print("AT+CMGF=1\r"); 
  delay(100);

  SIM900.println("AT + CMGS = \"" + PhoneNo + "\""); 
  delay(100);
  
  // Send the SMS
  SIM900.println(voltagemessage); 
  delay(100);

  // End AT command with a ^Z, ASCII code 26
  SIM900.println((char)26);   // ctrl+z
  delay(1000);
  SIM900.println();
  // Give module time to send SMS
  delay(5000);
}

void loop() { 
  // Display any text that the GSM shield sends out on the serial port
  if(SIM900.available()>0) {
  textMessage = SIM900.readString();     //Get the character from the cellular serial port
  Serial.print(textMessage);             //Print the incoming character to the terminal
  delay(10);
  } 
   
  // Turn on relay1 and save current state
  if(textMessage.indexOf("Relay1ON")>=0) {
  digitalWrite(Relay1, LOW);
  Relay1State = "On";
  Serial.println("Relay1 set to ON");  
  textMessage = "";
  }

  // Turn off relay1 and save current state
  if(textMessage.indexOf("Relay1OFF")>=0) {
  digitalWrite(Relay1, HIGH);
  Relay1State = "Off"; 
  Serial.println("Relay1 set to OFF");
  textMessage = ""; 
  }

  // Turn on relay2 and save current state
  if(textMessage.indexOf("Relay2ON")>=0) {
  digitalWrite(Relay2, LOW);
  Relay2State = "On";
  Serial.println("Relay2 set to ON");  
  textMessage = "";
  }

  // Turn off relay2 and save current state
  if(textMessage.indexOf("Relay2OFF")>=0) {
  digitalWrite(Relay2, HIGH);
  Relay2State = "Off"; 
  Serial.println("Relay2 set to OFF");
  textMessage = ""; 
  }

  // Check relay state
  if(textMessage.indexOf("STATE")>=0) {
  String statemessage = "Relay1 is " + Relay1State + ", Relay2 is " + Relay2State;
  sendState(statemessage);
  Serial.println("Relay state resquest");
  textMessage = "";
  }

  // Check Voltage
  if(textMessage.indexOf("Voltage")>=0) {
  CheckVoltage();
  String voltagemessage = "Voltage = " + VoltageString;
  sendVoltage(voltagemessage);
  Serial.println("Voltage resquest");
  textMessage = "";
  }

}

If you get a text message, containing "Voltage", you want to get one response, right? So, where do you delete the text message, so you don't read the same one again?

Hi PaulS,

Yes, I want if I send a text message "Voltage" from my phone to the Arduino GSM Switch, it will response a text message to my phone and show it's battery voltage containing in the text message.

But my problem is, I can sent the request text message "Voltage" to arduino, and the arduino can response my request (return text message to my phone). But it not only response by one text message. It is continue non-stop to send the text message to my phone containing the battery voltage result.

Thanks

Yautsz:
Hi PaulS,

Yes, I want if I send a text message "Voltage" from my phone to the Arduino GSM Switch, it will response a text message to my phone and show it's battery voltage containing in the text message.

But my problem is, I can sent the request text message "Voltage" to arduino, and the arduino can response my request (return text message to my phone). But it not only response by one text message. It is continue non-stop to send the text message to my phone containing the battery voltage result.

Thanks

You did not answer my question. When you get a text message, with "Voltage" in it, you read the text, find that it contains voltage, and send a reply.

Then, since the text message hasn't been deleted, you read the text, find that it contains "Voltage", and send a reply.
Then, since the text message hasn't been deleted, you read the text, find that it contains "Voltage", and send a reply.
Then, since the text message hasn't been deleted, you read the text, find that it contains "Voltage", and send a reply.
Then, since the text message hasn't been deleted, you read the text, find that it contains "Voltage", and send a reply.
Then, since the text message hasn't been deleted, you read the text, find that it contains "Voltage", and send a reply.
Then, since the text message hasn't been deleted, you read the text, find that it contains "Voltage", and send a reply.
Then, since the text message hasn't been deleted, you read the text, find that it contains "Voltage", and send a reply.

See the problem?

Text message

Yautsz:
Text message

Your point being?

I sent a text message "Voltage" from my phone.
It answer and send a text message "Voltage = 5.37v" to my phone and then it continue send....
Voltage = 5.35v
Voltage = 5.35v
Voltage = 5.36v
Voltage = 5.35v
......

Until I turn off the arduino power.

Yautsz:
I sent a text message "Voltage" from my phone.
It answer and send a text message "Voltage = 5.37v" to my phone and then it continue send....
Voltage = 5.35v
Voltage = 5.35v
Voltage = 5.36v
Voltage = 5.35v
......

Until I turn off the arduino power.

I want you to write "Voltage" on the wall. Then, I want you to read what is on the wall, and write it down on a piece of paper. If the paper then says "Voltage" on it, I want you to whack yourself on the head. Then, I want you to erase what is on the paper.

Then, read what is on the wall, and write it down on a piece of paper. If the paper then says "Voltage" on it, I want you to whack yourself on the head. Then, I want you to erase what is on the paper.

Then, read what is on the wall, and write it down on a piece of paper. If the paper then says "Voltage" on it, I want you to whack yourself on the head. Then, I want you to erase what is on the paper.

Then, read what is on the wall, and write it down on a piece of paper. If the paper then says "Voltage" on it, I want you to whack yourself on the head. Then, I want you to erase what is on the paper.

Then, read what is on the wall, and write it down on a piece of paper. If the paper then says "Voltage" on it, I want you to whack yourself on the head. Then, I want you to erase what is on the paper.

Then, read what is on the wall, and write it down on a piece of paper. If the paper then says "Voltage" on it, I want you to whack yourself on the head. Then, I want you to erase what is on the paper.

Got a headache, yet?

At some point, don't you think it is necessary to erase what you wrote on the wall?

Where do you delete the text message? Reading a message does NOT make it go away.

Ok

I write the AT code to delete the message, also cannot work.

// Check Voltage
  if(textMessage.indexOf("Voltage")>=0) {
  CheckVoltage();
  String voltagemessage = "Voltage = " + VoltageString;
  sendVoltage(voltagemessage);
  SIM900.println("AT+CMGD=1,4");  //delete all messages from SIM card
  Serial.println("Voltage resquest");
  textMessage = "";
  }

Hi, did u manage to solve this issue? Please show me the code