just buy two float sensor's like this float sensor and treat it like a button then simply use a int or boolean for a lock, i made you a sketch based on your code which should work as is. ![]()
/*-----( Setup function )-----*/
void setup() {
 Serial.begin(9600);
 pinMode(8, INPUT_PULLUP);
 pinMode(9, INPUT_PULLUP);
}
/*-----( Loop function )-----*/
void loop() {
 boolean run_cycle = true;
 const int lowerSersor = digitalRead(8); // lower float sensor on digital pin 8
 const int topSensor = digitalRead(9); // top float sensor on digital pin 9
 if (lowerSersor == LOW) { // float sensor has dropped down - tank empty
  // Toggle on
  if (run_cycle) {
   sendSMS();
   run_cycle = false;
  }
 }
 if (topSensor == LOW) { // tank now full again - this float sensor is upside down so it float when the tank is full
  // Toggle off
  if (run_cycle == false) {
   run_cycle = true;
  }
 }
}
void sendSMS() {
 // Some code here to send a sms
 Serial.println("AT");
 delay(1000);
 Serial.println("AT+CMGF=1"); // send SMS in text mode
 delay(1000);
 Serial.println("AT+CMGS=\"+01XXXX\""); //CHANGE TO Number , you'd like to receive message
 delay(1000);
 Serial.print("Water level is low in underground tank (attention required)"); // content of the message
 Serial.write(26); // ctrl+z ASCII code
}
Just as a note though, i have never used a gsm module to send a sms so im unsure of your setup for communication i.e. Serial.begin(9600); and Serial.println("AT"); but if it's like a esp8266 it and you're using a uno it should be:
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX on digital pins 6 and 7
/*-----( Setup function )-----*/
void setup() {
 Serial1.begin(9600);  // initialize serial for SMS module
 Serial.begin(115200); // debugging open serial monitor and set to 115200 baud rate for debugging text
 pinMode(8, INPUT_PULLUP);
 pinMode(9, INPUT_PULLUP);
}
/*-----( Loop function )-----*/
void loop() {
 boolean run_cycle = true;
 const int lowerSersor = digitalRead(8); // lower float sensor on digital pin 8
 const int topSensor = digitalRead(9); // top float sensor on digital pin 9
 if (lowerSersor == LOW) { // float sensor has dropped down - tank empty
  // Toggle on
  if (run_cycle) {
   sendSMS();
   run_cycle = false;
   Serial.println(F("tank low, sending sms")); // Serial.println(F saves the text in the flash to save space
  }
 }
 if (topSensor == LOW) { // tank now full again - this float sensor is upside down so it float when the tank is full
  // Toggle off
  if (run_cycle == false) {
   run_cycle = true;
   Serial.println(F("tank full"));
  }
 }
}
void sendSMS() {
 // Some code here to send a sms
 Serial1.println(F("AT"));
 delay(1000);
 Serial1.println(F("AT+CMGF=1")); // send SMS in text mode
 delay(1000);
 Serial1.println(F("AT+CMGS=\"+01XXXX\"")); //CHANGE TO Number , you'd like to receive message
 delay(1000);
 Serial1.print(F("Water level is low in underground tank (attention required)")); // content of the message
 Serial1.write(26); // ctrl+z ASCII code
 Serial.println(F("SMS sent !"));
}
But just look at the sms example for your module and copy that as im unsure as i said.