Skip to main content
added 94 characters in body
Source Link
chrisl
  • 16.6k
  • 2
  • 18
  • 27

Hello everyone I write my code and have some troubles. When I write on in my serial monitor my buzzer condition wasn't changed. Can you help me realize the reason. I wrote code with int type and it works with Serial.parseInt() function properly.

String ask="Please enter buzzer condition"; int buzzerPin=2; String state; void setup() { pinMode(buzzerPin,OUTPUT); Serial.begin(115200);

}

void loop() { Serial.println(ask); state=Serial.readString(); Serial.println(state); while(Serial.available()==0){

} if(state=="on"){ digitalWrite(buzzerPin,HIGH); } if(state=="off"){ digitalWrite(buzzerPin,LOW); } }

String ask="Please enter buzzer condition";
int buzzerPin=2;
String state;
void setup() {
  pinMode(buzzerPin,OUTPUT);
  Serial.begin(115200);

}

void loop() {
 Serial.println(ask);
 state=Serial.readString();
 Serial.println(state);
 while(Serial.available()==0){
  
 }
 if(state=="on"){
  digitalWrite(buzzerPin,HIGH);
 }
 if(state=="off"){
  digitalWrite(buzzerPin,LOW);
}
}

Hello everyone I write my code and have some troubles. When I write on in my serial monitor my buzzer condition wasn't changed. Can you help me realize the reason. I wrote code with int type and it works with Serial.parseInt() function properly.

String ask="Please enter buzzer condition"; int buzzerPin=2; String state; void setup() { pinMode(buzzerPin,OUTPUT); Serial.begin(115200);

}

void loop() { Serial.println(ask); state=Serial.readString(); Serial.println(state); while(Serial.available()==0){

} if(state=="on"){ digitalWrite(buzzerPin,HIGH); } if(state=="off"){ digitalWrite(buzzerPin,LOW); } }

Hello everyone I write my code and have some troubles. When I write on in my serial monitor my buzzer condition wasn't changed. Can you help me realize the reason. I wrote code with int type and it works with Serial.parseInt() function properly.

String ask="Please enter buzzer condition";
int buzzerPin=2;
String state;
void setup() {
  pinMode(buzzerPin,OUTPUT);
  Serial.begin(115200);

}

void loop() {
 Serial.println(ask);
 state=Serial.readString();
 Serial.println(state);
 while(Serial.available()==0){
  
 }
 if(state=="on"){
  digitalWrite(buzzerPin,HIGH);
 }
 if(state=="off"){
  digitalWrite(buzzerPin,LOW);
}
}
Source Link

Arduino Serial.readString() trouble

Hello everyone I write my code and have some troubles. When I write on in my serial monitor my buzzer condition wasn't changed. Can you help me realize the reason. I wrote code with int type and it works with Serial.parseInt() function properly.

String ask="Please enter buzzer condition"; int buzzerPin=2; String state; void setup() { pinMode(buzzerPin,OUTPUT); Serial.begin(115200);

}

void loop() { Serial.println(ask); state=Serial.readString(); Serial.println(state); while(Serial.available()==0){

} if(state=="on"){ digitalWrite(buzzerPin,HIGH); } if(state=="off"){ digitalWrite(buzzerPin,LOW); } }