Multiple arduino inputs

You are probably sending the value over with Serial, right? Then you just need to send all the values from the different sensors with delimiters and assign different variables to them respectively.

Example :

Arduino :

int values[3];

void setup() {
//initialize serial communications at a 9600 baud rate
   Serial.begin(9600);
}

void loop() {
   values[0] = analogRead(A0);
   values[1] = analogRead(A1);
   values[2] = analogRead(A2);
   //the individual sensors values

   Serial.println(value[0] + "split" + value[1] + "split" + value[2]);
   //you can use any char/String as a delimiter

   delay(100);
}

Processing :

Serial myPort;
String val;     // Data received from the serial port

int[] intVals;

void setup() {
  String portName = Serial.list()[0]; //change the 0 to match your port
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.readStringUntil('\n');         // read it and store it in val
  }

  intVals = int(split(val, "split"));
  //you can use splitTokens(val, delimiters) to split on multiple token. 
   
println(val, intVals); //print it out
}
1 Like