Intro: 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: https://processing.org/reference/libraries/serial/Serial_available_.html
Step 1: 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
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.
- Connect the positive rail to the 10k resistor.
- On the same rail place one arm of the photo-resistor and wire going to A0 on the Arduino board.
- Ground the other arm of the photo-resistor by connecting it to the negative rail.
Step 3: 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
In case you get stuck!
Step 5: 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
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
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!
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.