Arduino convert ascii characters to string

arduinoasciistring

I'm using this sensor with an arduino board.

On page 2, it describes the serial output from pin 5.

http://www.maxbotix.com/documents/HRXL-MaxSonar-WR_Datasheet.pdf

The output is an ASCII capital "R", followed by four ASCII character
digits representing the range in millimeters,followed by a carriage
return (ASCII 13). The serial data format is 9600 baud, 8 data bits, no parity,
with one stop bit (9600-8-N-1).

This is my arduino code (which isn't correct). It only outputs the '82' which is the capital R.

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

void loop()
{  
 int data = Serial.read();
 Serial.println(data);
 delay (1000);
}

How do I get a distance reading to a string?

Many thanks

Best Answer

Do you tried the readBytesUntil method ?

You should use it like that :

byte DataToRead [6];
Serial.readBytesUntil(char(13), DataToRead, 6);

Your data is contained into DataToRead (your 'R' in DataToRead[0] etc.)