Serial value

Hi, using the code below I am sending a number(1 or 2 or 3, etc) to the Arduino via Serial Monitor.
I would like the Arduino to tell me the number that it has received, instaid I receive for the number 1 > 49 and for number 2 > 50 etc
Thanks in advance!!

int dataPC;

void setup() 
{
  Serial.begin(9600);    //Open serial port.
}

void loop() 
{
  if (Serial.available())
  {
    dataPC = Serial.read();
    
    Serial.print("I received: ");
    Serial.println(dataPC, DEC); 
  }
}
  dataPC = Serial.read();
  if (dataPC >= '0' && dataPC <= '9') {
      dataPC -= '0';
  }
     
  Serial.print("I received: ");
  Serial.println(dataPC, DEC); 
}

The value you're getting is an ascii character rather than a number.

If you want to use it as a number within the sketch you can use the approach AWOL showed to convert each character to the corresponding decimal number. Note that this would only work for numbers 0 - 9. If you want to pass numbers with two or more digits, you would need a more complicated approach.

However, if all you want is to have the sketch return the same character it received then you can achieve that by using Serial.write() instead of Serial.print().

Or, just store the Serial.read() value in a char, and remove the ,DEC bit.