0

The objective is to enter "on" and "off" in COM port and switch the Pin 13. No matter what I do. It won't switch on or off. Need help. I tried to see if the string I entered is "on". It prints "on" but when I check for the result it shows its different. What is wrong?

String SData;
String SData1;
 void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
delay(5000);
digitalWrite(13,LOW);
delay(1000); 
 }

 void loop() {
// put your main code here, to run repeatedly:
while(Serial.available()==0)
{

}
SData=Serial.readString();
SData1="on";
if(SData==SData1)
Serial.print("Same");
else
{
Serial.print("Different");
// Serial.print(SerialData-SerialData1);
Serial.print(".");
}
if(SData=="on")
  {
  digitalWrite(13,HIGH);

  Serial.println("LED ON");
  delay(2000);
  }
Serial.println(SData);
if(SData=="off")
 {
  digitalWrite(13,LOW);
  Serial.println("LED OFF");
  delay(2000);
 }
SData="";
}

0 Answers0