Introduction: Arduino Processing Graphic Transition

Hi, this project is for making visible graphics from unvisible particles which could be sensed by sensors. In this case, I used the ultrasonic sensor and photoresistor to control light and distance. I visualize it by making the variables from the sensor as variables in processing. Then I connect Arduino and Processing to control Arduino with Processing. Thus, the graphic in Processing would apply variables from the Arduino sensor.

Step 1: Step 1: Prepare Parts

Here are the components that you will need to make this project:

- 10k OHM

- Ultrasonic sensor

- Photoresistor

- Arduino Uno

- 7 wires

Step 2: Step 2: Connect All Components

The photoresistor and Ultrasonic sensor need a space for accurate detection. Save some space and think about light for photoresistor.

Step 3: Step 3: Code!

*Add library in both Arduino and Processing.

Arduino: search "new ping" in the library

Processing: search "serial" in the library

Code for Arduino:

#include <NewPing.h>

#define TRIGGER_PIN 12 #define ECHO_PIN 11 #define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

int lightSensorPin = A0; int analogValue = 0;

void setup() { Serial.begin(9600); }

void loop() { int Value1 = sonar.ping_cm(); Value1 = map(Value1, 1, 60, 500, 24); Value1 = constrain(Value1, 24, 500);

analogValue = analogRead(lightSensorPin); int cVal1 = map (analogValue, 200, 600, 249, 100);

int cVal2 = map (analogValue, 200, 600, 247, 97);

int cVal3 = map (analogValue, 200, 600, 243, 101);

int cVal4 = map (analogValue, 200, 600, 243, 150);

delay(50);

Serial.print(Value1); Serial.print(",");

Serial.print(cVal1); Serial.print(","); Serial.print(cVal2); Serial.print(","); Serial.print(cVal3); Serial.print(","); Serial.print(cVal4); Serial.print(",");

Serial.println(); }

Code for Processing:

//class: (basic)//

import processing.serial.*;

int end = 10; String serial; Serial port;

int pcount = 350; Particle[] p = new Particle[pcount]; int diagonal; int e = 100;

void setup() { port = new Serial(this, "/dev/cu.usbmodem141101"); port.clear(); serial = port.readStringUntil(end); serial= null; for (int i = 0; i

float rotation = 0;

void draw() { while (port.available() > 0) { serial = port.readStringUntil(end); delay(10); } if (serial != null) { String[] a = split(serial, ','); println(a[0]); println(a[1]); println(a[2]); println(a[3]); println(a[4]); int result1 = Integer.parseInt(a[0]); System.out.println(result1); frameRate(result1); int result2 = Integer.parseInt(a[1]); System.out.println(result2); int result3 = Integer.parseInt(a[2]); System.out.println(result3); int result4 = Integer.parseInt(a[3]); System.out.println(result4); int result5 = Integer.parseInt(a[4]); System.out.println(result5); background(result2, result3, result4); translate(width/2, height); rotation-=0.0005; rotate(rotation); for (int i = 0; i diagonal) { p[i] = new Particle(); } } } }

//class: Particle//

class Particle {
float n; float r; float o; float c; float d; int l; Particle() { l = 100; n = random(3, width/2); r = random(0.10, TWO_PI); o = random(1, random(1, width/n)); c = random(180, 228); d = random(160, 208); } void draw() { l++; pushMatrix(); rotate(r); translate(drawDist(), 1); ellipse(10, 10, width/o/4, width/o/4); popMatrix(); o-=0.06; } float drawDist() { return atan(n/o)*width/HALF_PI; } }

Step 4: Step 4: Connect and Test

Step 5: Step 5: See the Result!

The speed of the moving ball will be faster when anything is closer to the ultrasonic sensor. Plus, the light control with photoresistor will appear in processing as background darkness.