How to make Serial.read() return an integer instead of an ascii value? I want Serial.read() to return an integer instead of an ASCII value. For example, in the below code if I input 2, I want the output as 2 instead of 50
void setup(){
    Serial.begin();
}

void loop(){
    if(Serial.available()){
    int t = Serial.read();
    Serial.println(t);
}
If it's a single digit:
if (t &gt;= '0' &amp;&amp; t &lt;= '9') {
    int numeric_value = t - '0';
} else {
    // Handle the input error.
}