Problem on Send and Read Data

Hi everyone!
I have no idea what I am doing. Help needed :slight_smile:

I am doing send and read multiple data on arduino and c# and the result comes:
Data 1=0
Data 2=0
Data 3=241
Data 1=0
Data 2=0
Data 3=242
Data 1=0
Data 2=0
Data 3=255

What I want is:
Data 1=241
Data 2=242
Data 3=255

Noob here...
Here's my code

String data_read,data_read2,data_read3;
void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  while(Serial.available()){
    data_read = Serial.read();
    if(data_read == "1"){
      break;
    } 
  }

  while(Serial.available()){
    data_read2=Serial.read();
    if(data_read2=="2"){
      break;
    }
  }

  while(Serial.available()){
    data_read3=Serial.read();
    if(data_read3=="3"){
      break;
    }
  }

  while(Serial.available()){
    Serial.write(0xff);
    Serial.write(0xf1);
    Serial.write(0xf2);
  }
  
}

p.s: it is have no error and I use Arduino Uno

Thanks for your help :slight_smile:

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable.

You can send data in a compatible format with code like this (or its equivalent in any other programming language)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

...R