There is always a zero in the buffer

Hi there!

I'm new using arduino so I've begun with simple sketches like this:

[code]
int number;
void setup() {
  Serial.begin(9600);

}

void loop() {
  if(Serial.available()>0){
    number=Serial.parseInt();
    Serial.println(number);
    if(numero==23){
      Serial.println("Number is equal to 23");
    }else if(numero>23){
      Serial.println("Number is more than 23");
    }else{
      Serial.println("Number is less than 23");
        }
  }
}

[/code]

If you write a number in the serial monitor, the code compares to 23 and shows the result correctly but right after appears:

0
Number is less than 23

I've tried with other sketches and it always happens when using if(Serial.available()>0). It seems to me as if there was always a zero value in the buffer.. but I'm not an expert at all.

Any help is welcome, thanks.

In the serial monitor, at the bottom, try setting the line ending to "No line ending".

I see you changed "numero" to "number", but missed a couple. :slight_smile:
(You'll get a compile error with the code as shown.)

Hi OldSteve!

Thank you very much! :slight_smile: Now it works. I didn't know anything about that part of the Serial Monitor , so I've looked for some information and it makes sense!

Yes, you are right I missed two "numero" :blush: . I just translated from spanish in the post, but the code in my computer is all in the same language :smiley: .

Irenuka:
Hi OldSteve!
Thank you very much! :slight_smile: Now it works.

No problem. Glad to help. :slight_smile: