More than 1 value


My name is Jessy.
I’m trying to send more than 1 values from Arduino to Processing over Serial.
But what is the best method of sending them from the Arduino, and receiving it on Processing?

I know how to send 1 value, but when there is more coming over the Serial line, then i don’t know how to let Procesing pick up the second value.

This is what i have now, just for testing.


int potPin = A0;

void setup() {

void loop() {
  int val = map(analogRead(potPin), 0, 1023, 0, 255);


import processing.serial.*;
import controlP5.*; 

Serial port;
float hoogte = 0;

void setup() {

  size(500, 500);
  port = new Serial(this, "COM3", 9600);

void draw() {
  rect(125, 400, 50, -hoogte);

void serialEvent (Serial port) {

  hoogte = float(port.readStringUntil('\n'));

Now i want to add a LDR to my Arduino, but i don’t know how to let Processing know, which value that is.
So that i can make a second rect with the second value from the serial line.

Could anyone help me? :slight_smile:

Thanks in advance.

When sending multiple values there are a number of ways to distinguish between them

  • Always send the values in the same sequence with some means to determine one sequence from the next. This can be a time gap of some minimum length or a unique value.
  • Have a identifier preamble each value. That way you are not bound to the sequence but decoding is more complicated
  • Use the msb to distinguish between control and data bytes. This limits the transfer to 7 bits/byte instead of 8

Since you are sending the data as text,


In Processing, use the port.readStringUntil('\n') method, to read the data into a String. Then, use the split() method to split the string into an array of ints (not floats, since you are NOT sending floats).