Get two values ​​in arduino and display in C#


I have two Ultrasonics connected to my arduino, and I'm using this code to read their values ​​normally:

#include <Ultrasonic.h>

Ultrasonic ultrasonic(11, 12);
Ultrasonic ultrasonic1(8,9);  

const int TRIG = 8;
const int ECHO = 9;

const int TRIG2 = 11;
const int ECHO2 =12;

void setup() {


  pinMode (TRIG,OUTPUT);
  pinMode (ECHO,INPUT);

  pinMode (TRIG2,OUTPUT);
  pinMode (ECHO2,INPUT);


void loop() {

 int data = GetUltra(TRIG,ECHO);
 int data2 = GetUltra(TRIG2,ECHO2);
 char recep = data+"_"+data2;


double GetUltra(int trig, int echo){

   digitalWrite (trig,LOW);
   digitalWrite (trig,HIGH);
   digitalWrite (trig,LOW);

       double distance = (pulseIn(echo, HIGH) )*343.2 / 20000;
       return distance;


And now, I'm trying to read the values ​​from my little system in Visual Studio, using Split. However, returns the value of only 1 number

private void button1_Click(object sender, EventArgs e)
    message = porta.ReadLine();
    Receptor = message.ToString().Split('_');
    MessageBox.Show("message2" + Receptor[0]);
    MessageBox.Show("message2" + Receptor[1]);


Did I do something wrong? Am I not following the right thought?


I believe the problem is here on this line:

char recep = data+"_"+data2;

You are using the "char" type when you should actually use the "string" type.

Scroll to Top