Skip to main content
edited tags
Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50
added 40 characters in body
Source Link
3kstc
  • 221
  • 2
  • 14

Code Snippet:

String a;

const int red_led_pin = 13;

void setup() 
{
  Serial.begin(115200);
  Serial.println("Hello, ESP32-S2!");
  pinMode(red_led_pin, OUTPUT); 
}

void loop() {

    while (Serial.available()) 
    {
        a = Serial.readString();// read the incoming data as string
        Serial.print(" First: ");
        Serial.println(a);
    

        if (a.equals("on"))
        {
          Serial.println("LED ON");
          digitalWrite(red_led_pin, HIGH);

        }


        else  if (a == "off" || a == "OFF")
        {
          Serial.println("LED OFF");
          digitalWrite(red_led_pin, LOW);
        }

        Serial.print("Second: ");
        Serial.println(a);
    }
}

Serial.print out:

enter image description here

Circuitry:

enter image description here

Issue:

The code can't capture the on string or any other string (on, off or OFF) that I pass. However it does pick it up and Serial.print it.

What is going wrong?

Things I have tried:

I have tried as a comparison:

  • if (a.equals("on")){<>}
  • if (a == "on")){<>}
  • if (a.equalsIgnoreCase("on")){<>}

Due Diligence / Prior Research:

Code Snippet:

String a;

const int red_led_pin = 13;

void setup() 
{
  Serial.begin(115200);
  Serial.println("Hello, ESP32-S2!");
  pinMode(red_led_pin, OUTPUT); 
}

void loop() {

    while (Serial.available()) 
    {
        a = Serial.readString();// read the incoming data as string
        Serial.print(" First: ");
        Serial.println(a);
    

        if (a.equals("on"))
        {
          Serial.println("LED ON");
          digitalWrite(red_led_pin, HIGH);

        }


        else  if (a == "off" || a == "OFF")
        {
          Serial.println("LED OFF");
          digitalWrite(red_led_pin, LOW);
        }

        Serial.print("Second: ");
        Serial.println(a);
    }
}

Serial.print out:

enter image description here

Circuitry:

enter image description here

Issue:

The code can't capture the on string or any other string (on, off or OFF) that I pass. However it does pick it up and Serial.print it.

What is going wrong?

Things I have tried:

I have tried as a comparison:

  • if (a.equals("on")){<>}
  • if (a == "on")){<>}
  • if (a.equalsIgnoreCase("on")){<>}

Due Diligence / Prior Research:

Code Snippet:

String a;

const int red_led_pin = 13;

void setup() 
{
  Serial.begin(115200);
  Serial.println("Hello, ESP32-S2!");
  pinMode(red_led_pin, OUTPUT); 
}

void loop() {

    while (Serial.available()) 
    {
        a = Serial.readString();// read the incoming data as string
        Serial.print(" First: ");
        Serial.println(a);
    

        if (a.equals("on"))
        {
          Serial.println("LED ON");
          digitalWrite(red_led_pin, HIGH);

        }


        else  if (a == "off" || a == "OFF")
        {
          Serial.println("LED OFF");
          digitalWrite(red_led_pin, LOW);
        }

        Serial.print("Second: ");
        Serial.println(a);
    }
}

Serial.print out:

enter image description here

Circuitry:

enter image description here

Issue:

The code can't capture the on string or any other string (on, off or OFF) that I pass. However it does pick it up and Serial.print it.

What is going wrong?

Things I have tried:

I have tried as a comparison:

  • if (a.equals("on")){<>}
  • if (a == "on")){<>}
  • if (a.equalsIgnoreCase("on")){<>}

Due Diligence / Prior Research:

Became Hot Network Question
edited tags
Source Link
3kstc
  • 221
  • 2
  • 14

Code Snippet:

String a;

const int red_led_pin = 13;

void setup() 
{
  Serial.begin(115200);
  Serial.println("Hello, ESP32-S2!");
  pinMode(red_led_pin, OUTPUT); 
}

void loop() {

    while (Serial.available()) 
    {
        a = Serial.readString();// read the incoming data as string
        Serial.print(" First: ");
        Serial.println(a);
    

        if (a.equals("on"))
        {
          Serial.println("LED ON");
          digitalWrite(red_led_pin, HIGH);

        }


        else  if (a == "off" || a == "OFF")
        {
          Serial.println("LED OFF");
          digitalWrite(red_led_pin, LOW);
        }

        Serial.print("Second: ");
        Serial.println(a);
    }
}

Serial.print out:

enter image description here

Circuitry:

enter image description here

Issue:

The code can't capture the on string or any other string (on, off or OFF) that I pass. However it does pick it up and Serial.print it.

What is going wrong?

Things I have tried:

I have tried as a comparison:

  • if (a.equals("on")){<>}
  • if (a == "on")){<>}
  • if (a.equalsIgnoreCase("on")){<>}

Due Diligence / Prior Research:

Code Snippet:

String a;

const int red_led_pin = 13;

void setup() 
{
  Serial.begin(115200);
  Serial.println("Hello, ESP32-S2!");
  pinMode(red_led_pin, OUTPUT); 
}

void loop() {

    while (Serial.available()) 
    {
        a = Serial.readString();// read the incoming data as string
        Serial.print(" First: ");
        Serial.println(a);
    

        if (a.equals("on"))
        {
          Serial.println("LED ON");
          digitalWrite(red_led_pin, HIGH);

        }


        else  if (a == "off" || a == "OFF")
        {
          Serial.println("LED OFF");
          digitalWrite(red_led_pin, LOW);
        }

        Serial.print("Second: ");
        Serial.println(a);
    }
}

Serial.print out:

enter image description here

Issue:

The code can't capture the on string or any other string (on, off or OFF) that I pass. However it does pick it up and Serial.print it.

What is going wrong?

Things I have tried:

I have tried as a comparison:

  • if (a.equals("on")){<>}
  • if (a == "on")){<>}
  • if (a.equalsIgnoreCase("on")){<>}

Due Diligence / Prior Research:

Code Snippet:

String a;

const int red_led_pin = 13;

void setup() 
{
  Serial.begin(115200);
  Serial.println("Hello, ESP32-S2!");
  pinMode(red_led_pin, OUTPUT); 
}

void loop() {

    while (Serial.available()) 
    {
        a = Serial.readString();// read the incoming data as string
        Serial.print(" First: ");
        Serial.println(a);
    

        if (a.equals("on"))
        {
          Serial.println("LED ON");
          digitalWrite(red_led_pin, HIGH);

        }


        else  if (a == "off" || a == "OFF")
        {
          Serial.println("LED OFF");
          digitalWrite(red_led_pin, LOW);
        }

        Serial.print("Second: ");
        Serial.println(a);
    }
}

Serial.print out:

enter image description here

Circuitry:

enter image description here

Issue:

The code can't capture the on string or any other string (on, off or OFF) that I pass. However it does pick it up and Serial.print it.

What is going wrong?

Things I have tried:

I have tried as a comparison:

  • if (a.equals("on")){<>}
  • if (a == "on")){<>}
  • if (a.equalsIgnoreCase("on")){<>}

Due Diligence / Prior Research:

added 414 characters in body
Source Link
3kstc
  • 221
  • 2
  • 14
Loading
Source Link
3kstc
  • 221
  • 2
  • 14
Loading