user38727: I was having some problems on a project, so to test my Arduino, I wrote the following program to check things. When I start the serial monitor, the value of i is 1, but after I start sending numbers, they change into ASCII. Why?
int i = 1;
void setup(){
  Serial.begin(9600);
}
void loop(){
  Serial.println(i);
  if(Serial.available()){
    i = Serial.read();
  }
}


user972: When you send the character 1, Serial.read() returns the integer 49.
Serial.println(i) then sends the characters 4, 9, carriage return and a newline.
If you want to get back the same characters that you sent, change the type of i to char.

38727: <p>I was having some problems on a project, so to test my Arduino, I wrote the following program to check things. When I start the serial monitor, the value of <code>i</code> is 1, but after I start sending numbers, they change into ASCII. Why?</p>

<pre class="lang-cpp prettyprint-override"><code>int i = 1;
void setup(){
  Serial.begin(9600);
}
void loop(){
  Serial.println(i);
  if(Serial.available()){
    i = Serial.read();
  }
}
</code></pre>
 972: <p>When you send the character <code>1</code>, <code>Serial.read()</code> returns the integer 49.<br>
 <code>Serial.println(i)</code> then sends the characters <code>4</code>, <code>9</code>, carriage return and a newline.</p>

<p>If you want to get back the same characters that you sent, change the type of <code>i</code> to <code>char</code>.</p>
