How to Control a Processing Sketch With Two Arduino Inputs

by AlexanderM6 in Circuits > Arduino

14088 Views, 149 Favorites, 0 Comments

How to Control a Processing Sketch With Two Arduino Inputs

Setup for Instructables-01.png

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

Connect the Potentiometer to the Breadboard

Setup for Instructables-02.png

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).

Connect the Photo-Resistor

Setup for Instructables-03.png

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.

Connect the Power Lines

Setup for Instructables-04.png

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.

Fritzing Diagram

Setup for Instructables-05.png

In case you get stuck!

Open the Arduino IDE

Setup for Instructables-06.png

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

Check the File and Your Connections

Setup for Instructables-07.png

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.

Load Processing

Setup for Instructables-08.png

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.

Have Fun!

Setup for Instructables-09.png

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.