serial.read() not what I input?

Hi,

So I bought a CZ-HC-05, hooked everything up, but when I type in "1" through my BlueTooth terminal serial.print(serial.read()) gives me "49"? Does it have something to do with the RX/TX?

Try this:

serial.print(serial.read()-48);

:slight_smile:

Does it have something to do with the RX/TX?

No. What you are seeing the the ASCII value of the character you entered, hence the suggested solution.

aarg:
Try this:

serial.print(serial.read()-48);

:slight_smile:

For characters other than digits, try:

Serial.print((char)Serial.read());

Serial.read() returns an integer ('int'). That is so you can tell the difference between -1 (No Data Available) and 255, which both look the same in a byte/char. By 'casting' the int to a char you tell the compiler that you want the version of .print() that prints a single character, rather than the one that prints the value of an integer.
If you get a 'ÿ' character that usually means there was no data and you turned the int -1 into the char 'ÿ'.

You are recommended to use Serial.available() to test for available data, then you
can just cast the result of read() to a single character as -1 will not be seen.