Introduction: How to Control a Processing Sketch With Two Arduino Inputs

Picture of How to Control a Processing Sketch With Two Arduino Inputs

This tutorial will show you how to build a basic Arduino circuit that can control a fun coloured ball sketch in Processing.

You will need:

  • 1x Arduino Board (I am using an Uno)
  • 1x Breadboard
  • 1x Photo-Resistor
  • 1x 10k Ohm Resistor (Brown-Black-Orange)
  • 1x Potentiometer
  • A handful of wires

You will also need to have installed on your computer Processing 2.2.1 or above and Arduino 1.5.8 or above. The code for this tutorial was written on a Mac so you Window users might run in to some issues when trying to get Processing to communicate with Arduino. Please refer to this article if you run in to any issues:

Step 1: Connect the Potentiometer to the Breadboard

Picture of Connect the Potentiometer to the Breadboard

You will need three wires for this. Connect the positive and negative wires to the power rails. The third, central wire transmits data to the Arduino. Connect that to port A1 (Analogue 1).

Step 2: Connect the Photo-Resistor

Picture of Connect the Photo-Resistor

This is a bit more complicated as you will need to include a resistor in the setup. Fortunately you don't have to worry about the polarity (which way round) the photo-resistor goes.

  1. Connect the positive rail to the 10k resistor.
  2. On the same rail place one arm of the photo-resistor and wire going to A0 on the Arduino board.
  3. Ground the other arm of the photo-resistor by connecting it to the negative rail.

Step 3: Connect the Power Lines

Picture of Connect the Power Lines

The black wire will attach to one of the ground points on the Arduino board and the negative power rail.

The red wire will attach to the of the 5V point on the Arduino board and the positive power rail.

Step 4: Fritzing Diagram

Picture of Fritzing Diagram

In case you get stuck!

Step 5: Open the Arduino IDE

Picture of Open the Arduino IDE

  • Unzip the attached files
  • Open the file named 2 inputs in the Arduino IDE

Step 6: Check the File and Your Connections

Picture of Check the File and Your Connections

Make sure you have your computer attached to the Arduino's USB port. Run the Serial Monitor to make sure you have properly set up your Arduino. You should be able to see a console outputting a pair of values, both between 0 and 255. Twist the potentiometer or cover the photo-sensor to see if the serial monitor registers any change.

Step 7: Load Processing

Picture of Load Processing

We're nearly done now...

Load the processing script called Waterfall_with_Arduino_Controls.pde

Hit the play button in the top left corner of the Processing IDE and you should see a ball making its way down the screen.

Step 8: Have Fun!

Picture of Have Fun!

You should now be controlling the processing script with two external inputs.

Be sure to change the values in the processing script or use some different inputs. The whole point of these inputs is to be creative and interact with your computer in new and different ways than you are used to with a keyboard and mouse.


tytower (author)2015-03-15

I did not see the pde file below . Where exactly do I find it?


tytower (author)tytower2015-03-15

Sorry I see it is in the download you provide .

Compiling this though I found a problem with my serial port.The lines

String portName = Serial.list()[5];

myPort = new Serial(this, portName, 9600);

gives an error as port not found . My arduino is on the usb port USB0 not tttys3 as it tries to connect to . can you tell me how to change the port?

tytower (author)tytower2015-03-15

OK I was able to get it going by changing the sketch to

myPort = new Serial(this, "/dev/ttyUSB0",9600);

but I would like to have this find the right port itself . Is this possible?

tytower (author)tytower2015-03-15

Its seeing 8 ports ,one of which is the one I want.

println(Serial.list()); in the loop somewhere displays them

tytower (author)tytower2015-03-17

Hm keeps dropping posted material . I was able to fix it by using

println(Serial.list()); in the loop somewhere then noting the position my USB0 appeared (7) and altering this line so

String portName = Serial.list()[7];

jenniferm8 (author)2015-03-16

I am trying to set up multiple light sensors that will trigger sound. I'm using both arduino and processing.. Does anyone know what I should put into y code to allow this to happen? The bit that sorta says "if light sensor 1 reads value 0, trigger sound1'. I've tried this multiple times but doing it with more than one sensor doesn't seem to work. Hope someone can help or direct me where else to look!

mrandle (author)2015-03-14

Looks good. I feel like processing doesn't get as much exposure as it should, it's very handy even without an arduino.

script_coded (author)2015-03-14

I have two arduinos, so I'm having some great ideas right now...
Great i'ble!

tomatoskins (author)2015-03-14

I love the quality of your pictures! I'm excited to see more from you around the community!

AlexanderM6 (author)tomatoskins2015-03-14

Thanks! I hope to get stuck in and try out some other projects on here.

About This Instructable




More by AlexanderM6:How to control a Processing sketch with two Arduino Inputs
Add instructable to: