Arduino problem with cycle

HI everyone, I have a problem when I write 1 to the serial port, my cycle does not work and does not write out GO, I will be grateful for your help

String value = "";
void setup() {
Serial.begin(9600);
}
void loop() {
  // put your main code here, to run repeatedly:
while(Serial.available()>0){
  value = char(Serial.read());
  Serial.print(value);
}
if(value ==1){
  Serial.println("Go");}
}

You are comparing a String to a number. Never be equal.

value must be char if i want for example number or word?

Check out toInt()

1 Like
`if(value == "1"){`
1 Like


its doesnt work corectly because if i write 1 second time its dosnt work

Once value becomes '1', nothing in the code will change it until you type something else.

Set value to 0 after you serial print.

I've edited your code on the assumption you understood you need to compare to a character.

I've added some formatting. Please start using the IDE Autoformat tool if you can't manage to write formatted code all by yourself. No shame.

And I removed the comment so ppl won't think you're a total noob. :wink:

a7

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