I just started working with Arduino and in my project I am trying to achieve the COMM between two Arduino using HC-05 in master and slave mode respectively, I configured it all successfully.

Now I want to send three HCSR-04 distance sensors data from master Arduino to slave Arduino via HC-05. I am sending each sensor data separated by " | ". following is the example format., which I got in serial monitor by connecting the master Arduino directly to PC via USB.





Now the problem is I am not able to read and parse this on the slave side. I tried with serail.readbytesuntill but I could not succeed. Please help me out that how I can read it and parse it.

Thanks in advance.

  • 1
    what does this mean? not able to read and parse ...... you either get no data, so there is nothing to parse or you get data, but you are unable to parse it .............. what does this mean? I could not succeed ..... please describe what actually happens – jsotola Mar 19 at 17:49
  • it would be helpfull if you add the parts of your code ment for sending and reciving the data. Without it is difficult to find an answer. – RJPlog Mar 19 at 21:38

As you can see from the comments Birender Brar, we need more information to be able to help you.

One way to accomplish your goal would be to:

Use Serial.readBytesUntil('\n', buffer, length) on the slave device to "read" the data in to a char array. The serial monitor can be set to automatically send a \n character for testing purposes, but your code on the master will have to do this. Send the data 168|200|76 with a \n appended to the end of the data: 168|200|76\n

Parse the data. Here is a example sketch that parses the data in to a integer array.

// Use Serial.readBytesUntil('\n', buffer, length)
// to fill the char array / string.
char str[] = "168|200|76\n";

// Set array size to maximum number of integers you will receive.
uint16_t myArray[3];

void setup(){


  int counter = 0;
  char* pch = strtok(str, "|");

  while(pch != NULL){
    myArray[counter] = atoi(pch);
    pch = strtok(NULL, "|");
    counter += 1;

  // Print out the contents of the integer array.
  for(int i = 0; i < counter; i++){

void loop(){}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.