Serial communication - ASCII problem

Hello everyone,

Today I want to programm as first step a Serial communication to the PC like that:

void setup()
{
Serial.begin(9600);
}

void loop()
{
while (Serial.available()==0);
int val = Serial.read();
Serial.print(val);
}

Well, If I send a "1" via the seriell Monitor I get "4910" back.
If I send a "20" via the seriell Monitor I get "504810" back.

Why is the "10" always at the end?

As next step I tried the following code:

void setup()
{
Serial.begin(9600);
}

void loop()
{
while (Serial.available()==0);
int val = Serial.read()-'0';
Serial.print(val);
}

Now, I send a "1" via the seriell Monitor I get "1-38" back.
When I send a "20" via the seriell Monitor I get "20-38" back.

What's that?

can someone explain that?

I want to tipe in "1" and get "1"...

and the character with ascii code 10 is ...

What are you using to send data TO the Arduino?

If you are using the Serial Monitor application, what have you selected, in the lower right, for what to also send with the data?

ASCII code 10 is LF (line feed)

I Use my Lenovo Laptop with Win 10 64bit

Thank you PaulS- there was "new line"

That's it! :slight_smile: