extra value created by serial port/monitor?

I am getting an extra data value (int) when I enter a single number into the serial monitor (see code). When I read back the value I entered via the serial monitor output as a zero that follows the value I entered. Is it my code or does the serial port produce this extra data?

int led0 = 11;
int led1 = 10;
int led2 = 9;
int Y;
void setup()
{
  Serial.begin(9600);
  
  pinMode(led0, OUTPUT);   
  pinMode(led1, OUTPUT);   
  pinMode(led2, OUTPUT);    
}

void loop()
{
 if (Serial.available()>0) // Checks for a character in the serial monitor
       {
       int Y = Serial.parseInt();
        Serial.println(Y);
       }
         /////  led1 start
        
        if (Y > 20)
           {  
            digitalWrite(led0, HIGH);   // turn the LED on (HIGH is the voltage level)
            delay(1500);               // wait for a second
            digitalWrite(led0, LOW);    // turn the LED off by making the voltage LOW
            delay(10);
            Serial.println ("test met");
           }
         else 
           {
            Serial.println (Y);  Serial.println ("test not met");  
           }
           delay (500);   
          
 }

This may be more like what you want.

int led0 = 11;
int led1 = 10;
int led2 = 9;
int Y;
void setup()
{
  Serial.begin(9600);

  pinMode(led0, OUTPUT);   
  pinMode(led1, OUTPUT);   
  pinMode(led2, OUTPUT);    
}

void loop()
{
  if (Serial.available()>0) // Checks for a character in the serial monitor
  {
    int Y = Serial.parseInt();
    Serial.println(Y);
    //}
    /////  led1 start

    if (Y > 20)
    {  
      digitalWrite(led0, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(1500);               // wait for a second
      digitalWrite(led0, LOW);    // turn the LED off by making the voltage LOW
      delay(10);
      Serial.println ("test met");
    }
    else 
    {
      Serial.println (Y);  
      Serial.println ("test not met");  
    }
    delay (500);   
  }     
}

Does this happen when the integer you entered into the serial monitor is greater than 20, or does it happen regardless of the integer entered?

Try adding:

while(Serial.available()) {
       Serial.read();}

to your code, after the Serial.parseInt line. That will clear the value from the Serial buffer.

Pat

hib1:
I am getting an extra data value (int) when I enter a single number into the serial monitor (see code). When I read back the value I entered via the serial monitor output as a zero that follows the value I entered. Is it my code or does the serial port produce this extra data?

it is likely reading a trailing character sent from your monitor.

your Serial monitor may append the data sent with a New Line, a Carriage Return, both or none as shown in the attached.

if you set it to None, you will not get the double entry.