Array of data from Arduino to Processing
in
Integration and Hardware
•
2 years ago
Hi. I've been looking for a simple way to take data—6 values of High or Low from PIR sensors— and use it in processing script. The data from the arduino, regardless of the sensor, is all somewhat similar. I'm interested in how to separate each value by Pin so I can use it for processing.
If you could help me or point me in a direction it would be much appreciated. The end use is that each sensor represents an area in a gallery that controls lighting and will hopefully control a visual installation.
Below is the arduino code.
#define SIZE 6
int relay[SIZE] = {8, 9, 10, 11, 12, 13 }; // output digital pins to solid state relaysint pir[SIZE] = {2, 3, 4, 5, 6, 7 }; // input digital pins from Parallax PIR sensorint time= 1000;
unsigned long startTime[SIZE ] = {0,0,0,0,0,0 }; // time relay switched ONunsigned long duration[SIZE ] = {time, time, time, time, time, 20000 }; // for how long in milli-seconds (note this is minimum time)
void setup(){Serial.begin (9600);for (int i=0; i < SIZE; i++){pinMode(relay[i], OUTPUT);pinMode(pir[i], INPUT);}}
void loop(){for (int i =0; i<SIZE; i++){
if (digitalRead(pir[i]) == HIGH) // check PIR state{digitalWrite(relay[i], HIGH); // switch relay ONstartTime[i] = millis();Serial.print(digitalRead(pir[i]));Serial.print(",");}
if ((millis() - duration[i]) >= startTime[i]) // time to switch off ??{digitalWrite(relay[i], LOW); // switch relay OFF after x}}
}
2