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:

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.

  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

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.

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    10 Discussions


    4 years ago on Introduction

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


    4 replies

    Reply 4 years ago on Introduction

    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?


    Reply 4 years ago on Introduction

    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?


    Reply 4 years ago on Introduction

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

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


    Reply 4 years ago on Introduction

    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];


    4 years ago on Introduction

    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!


    4 years ago

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


    4 years ago

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