Double Conditional with Ethernet Shield

a cordial greeting

I am doing a project where I must activate a system and then read a motion sensor and depending on whether the system is active or not, an action will be performed.

IF (readString.indexOf ("? PIR")> 0 && readString.indexOf ("? SISTEMON")> 0) {

IF (digitalRead (ControlPIR) == HIGH) {

client.println ("ON");

      Serial.println (digitalRead (ControlPIR));
  } 
  else if (digitalRead (ControlPIR) == LOW) {
      client.println ("OFF");
      Serial.println (digitalRead (ControlPIR));
         
    }

}

But the comparison of both variables (PIR and SISTEMON) is not working for me. I do not know if another syntax should be applied since when I do not compare the SISTEMON if the sensor reading works

Put some print statements into you code to check variable etc are what you think they should be and the code works as you think it might .

Are you sure you need the “?” In there...


void setup() {
  Serial.begin(9600);

  String myString = "Arduino, ArduinoGetStarted.com";
  int index = myString.indexOf("Arduino");
  Serial.println(index);
}

void loop() {
}


Keen sorts will ask you to post all your code and describe the project in a bit more detail .

You might also note that the first position of a string is 0 so your tests won't succeed if they are at the beginning of the String.

Note: String.indexOf() returns -1 if the substring is not found. You are comparing to >0 so if the substring is found starting at the first character (character 0) you will count it as missing.

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