# Read two separate sensor value

**URL:** <https://discourse.processing.org/t/read-two-separate-sensor-value/2161>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [July 28, 2018, 10:51am UTC](https://discourse.processing.org/t/read-two-separate-sensor-value/2161 "2018-07-28T10:51:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbalbarez](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@jbalbarez](https://discourse.processing.org/u/jbalbarez)\
**Post date:** [July 28, 2018, 10:51am UTC](https://discourse.processing.org/t/read-two-separate-sensor-value/2161/1 "2018-07-28T10:51:37Z")

</div>

I have two light sensor setup to my Arduino Uno, and I want to send the value of two sensors to processing and then separately assign it to val1 and val2 and show it in window. But in my Processing code it is only design on getting 1 value(val1) from one light sensor, is there anyone can help me to take the second value and set it in my val2 in my processing code. Thank you so much…

Arduino code:

int val1;  
int val2;  
int inputPin1 = A0; // Set the input to analog in pin A0  
int inputPin2 = A1; // Set the input to analog in pin A1  
void setup() {  
Serial.begin(9600); // Start serial communication at 9600 bps  
}

void loop() {  
val1 = analogRead(inputPin1)/4; // Read analog input pin, put in range 0 to 255  
val2 = analogRead(inputPin1)/4; // Read analog input pin, put in range 0 to 255  
Serial.write(val1); // Send the value1  
Serial.write(val2); // Send the value2  
delay(100); // Wait 100ms for next reading  
}

Processing Code:

import processing.serial.\*;

Serial port; // Create object from Serial class  
int val1; // Data received from the serial port

void setup() {  
size(200, 200);  
noStroke();  
frameRate(10); // Run 10 frames per second  
// Open the port that the board is connected to and use the same speed (9600 bps)  
port = new Serial(this, 9600);  
}

void draw() {  
if (0 \< port.available()) { // If data is available to read,  
val = port.read(); // read it and store it in val  
}  
background(204); // Clear background  
fill(val); // Set fill color with the value read  
rect(50, 50, 100, 100); // Draw square  
}

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 28, 2018, 8:28pm UTC](https://discourse.processing.org/t/read-two-separate-sensor-value/2161/2 "2018-07-28T20:28:35Z")

</div>

Please format your code above.

Have a look at these links:

> [SendingMultipleData \ Learning \ Wiring](http://wiring.org.co/learning/basics/sendingmultipledata.html)  
> [Receive Multiple Sensor Information from Arduino to Processing - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/6241/receive-multiple-sensor-information-from-arduino-to-processing)

Reading multiple sensors is common. You need to implement a first design based on examples that are readily available in previous posts or in the web.

looking at your ino code, you could do:

```c
Serial.write(val1); // Send the value1
Serial.write(','); //Need to check this or used the int equivalent
Serial.write(val2); // Send the value2
Serial.write(';'); 

```

So the data that you stream will look like this: `val1,val2;`. In other words, your values are separated by a ‘,’ char and your data stream ends with a ‘;’ character. In Processing, you read your serial buffer until the ‘;’ character and THEN your processed your data, splitting it at the ‘,’ and ‘;’ character and extracting `val1` and `val2`.

Kf

---

<div class="post-metadata">

**Author:** ![erwrow](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@erwrow](https://discourse.processing.org/u/erwrow)\
**Post date:** [August 1, 2018, 2:04pm UTC](https://discourse.processing.org/t/read-two-separate-sensor-value/2161/3 "2018-08-01T14:04:36Z")

</div>

@jbalbarez if you need to make a graph with that data, i would add a timestamp to the stream that @kfrajer told you, adding the value of the “millis()” function of your arduino, so you can make a way more acurrate graph
