Need help in Switch case based on SMS

Hi Experts,

I need help to switch case based on GSM shield received SMS. Below is a part of my sketch which change the case on push button. I want to change this case with sms also. or at least pin “Solenoid” toggle with sms.

Currently my sketch is working fine and when I am sending sms with letter “H” it received with GSM shield and reply message to my mobile that Solenoid ON. But actually there is some conflict in my sketch which did not allow the Solenoid to be ON.

Process Flow is:

  1. if DP_Sensor HIGH wait for few second (delay on to activate logic).
  2. Send SMS one time than it will be false
  3. if temp high or oil level low engine stop. When engine stop DP_Sensor detect as #1.
  4. A push button ACK will reset the Triptrigger logic.

Now I want to off the engine with SMS.

Any suggestion appreciated.

Thanks,

  if (digitalRead(MODE) == HIGH)       //if button is pressed
  {
    Mode++;
    if (Mode > 3) Mode = 1;      //button State from 1 to 3

    delay(50);                           //A very simple way to handle button bouncing, but need to adjust the delay time to optimize the result.
  }

switch (Mode) {

    case 1:
      lcd.setCursor(2, 0);
      lcd.print("OFF ");
      EngOFF();
      break;

    case 2:
      lcd.setCursor(2, 0);
      lcd.print("ON  ");
      if (averageC > hot || Level < 20 ) {
        EngOFF();
      } else {
        EngON();
      }

      if (digitalRead(ACK) == HIGH) {
        digitalWrite(SMS, LOW);
        lcd.setCursor(8, 1);
        lcd.write(" ");
        Triptrigger = true;
        EngON();
      }
      break;
      
    case 3:
      lcd.setCursor(2, 0);
      lcd.print("AUTO");
      if (digitalRead(DP_Sensor) != DP_reading ){
        DP_reading = !DP_reading;
        previousMillis = millis();
      }
      if (DP_reading)
      {
        if (millis() - previousMillis > interval)
        {
          previousMillis = millis();
          if (RunningState == HIGH && (Triptrigger))
          {
            EngOFF();
            digitalWrite(SMS, HIGH);
            lcd.createChar(1, ring);
            lcd.setCursor(8, 1);
            lcd.write((uint8_t)1); // ring Symbol
            RunningState = LOW;
            Triptrigger = !Triptrigger;
           // MSG();
          }
          else
          {
            RunningState = HIGH;
            EngOFF(); 
          }
          // digitalWrite(Solenoid, RunningState);
        }
      }
      else {
        // Serial.println(F("Engine Running & Solenoid Open"));
        if (averageC > hot || Level < 20 ) {
          EngOFF();
          Measurment();
        } else if (averageC < cold || Level > 30 ) {
          EngON(); 
        }
      }
      if (digitalRead(ACK) == HIGH) {
        digitalWrite(SMS, LOW);
        lcd.setCursor(8, 1);
        lcd.write(" ");
        Triptrigger = true;
        EngON();
      }    
      digitalWrite(Loop, HIGH);
      delay(100);
      digitalWrite(Loop, LOW);
///---------------------//////////////////------------///////////////////////////////
  if (SIM900.available() > 0) { //We check if there is data available from the SIM900
    caracter = SIM900.read(); // We read the data and the weights in the message variable
    Serial.print(caracter); //Prints the incoming data one by one on the serial terminal
    if (caracter == 'H') {
      Serial.println("-->Sending message");
      digitalWrite(Solenoid, HIGH);
      State = "Solenoid on";
      SendingMessage(State);
    }
    if (caracter == 'L') {
      Serial.println("-->Sending message");
      digitalWrite(Solenoid, LOW);
      State = "Solenoid off";
      SendingMessage(State);
    }
  }
    
      break;

Hi,

I get it now working fine but issue is : sms arrival speed is very slow letter by letter and may take 20 sec to complete the task even stop the serial printing. Any suggestion

Updated sketch below:

 case 3:

      lcd.setCursor(2, 0);
      lcd.print("AUTO");


      if (digitalRead(DP_Sensor) != DP_reading ) {
        DP_reading = !DP_reading;
        previousMillis = millis();
      }
      if (DP_reading)
      {
        if (millis() - previousMillis > interval)
        {
          previousMillis = millis();
          if (RunningState == HIGH && (Triptrigger))
          {
            EngOFF();
            digitalWrite(SMS, HIGH);
            lcd.createChar(1, ring);
            lcd.setCursor(8, 1);
            lcd.write((uint8_t)1); // ring Symbol
            RunningState = LOW;
            Triptrigger = !Triptrigger;
            //   MSG();
          }
          else
          {
            RunningState = HIGH; valve;
            //  Serial.print(F("Engine Stop & Solenoid closed"));
            EngOFF(); Measurment();
          }
          // digitalWrite(Solenoid, RunningState);
        }
      }
      else {
        // Serial.println(F("Engine Running & Solenoid Open"));
        if (averageC > hot || percentage < 20 ) {
          if (valve) {
            EngOFF();
            Measurment();
          }
        } else {
          if (!valve) {
            EngON();
            Measurment();
          }
        }  if (averageC <= cold || percentage > 30) {
          if (!valve ) {
            EngON();
          }
        }
      }
      // Serial.println(" ");

      if (digitalRead(ACK) == HIGH) {
        digitalWrite(SMS, LOW);
        lcd.setCursor(8, 1);
        lcd.write(" ");
        Triptrigger = true;
        !valve;
        EngON();
      }

 reply();

      break;


void reply() {

  if (SIM900.available() > 0) { //We check if there is data available from the SIM900
    caracter = SIM900.read(); // We read the data and the weights in the message variable
    Serial.print(caracter); //Prints the incoming data one by one on the serial terminal
    if (caracter == 'H') {
      Serial.println("-->Sending message");
      State = "led on";
     //  SendingMessage(State);
EngOFF();
      !valve;
    }
    if (caracter == 'L') {
      Serial.println("-->Sending message");
      State = "led off";
     // SendingMessage(State);
EngON();
      valve;
    }
  }
}

joe_wilson99:
I should mention that the netlight is solid but goes off after about 30 seconds.

netlight will bling once in every 3 sec if connect with network. Just see the below link may help you. Also I will suggest. Try to upload simple sending and receiving sms sketch to confirm that setup and configuration is okay.