Afternoon Dust

Controlling SuperCollider using an Arduino sensor

I’ve been experimenting with controlling SuperCollider using Arduino sensors, and since it was hard to find accurate documentation of this on the web I decided to write up some of my own.

The sad news is that I could only get this procedure to work on a Linux system, though Mac users should also be able to make use of it. The code relies on the SerialPort class, which currently seems to have trouble recognising Windows serial port addresses.

Here’s what you will need:

  • SuperCollider running on Mac OSX or Linux (I used version 3.6)
  • The ArduinoSMS quark
  • Arduino board with suitable analogue sensor

For the process of installing quarks in SuperCollider, refer to the documentation. For setting up your Arduino board and sensor, see the ‘Basics > AnalogSerialRead’ and ‘Analog > Calibration’ examples included with the Arduino software.

Once you’ve uploaded your Arduino sketch and checked that the sensor is working properly, make sure to close the Arduino serial monitor. Now it’s time to write some SuperCollider code.

The SuperCollider code

    1. In a new SC document, create an object to interact with the Arduino board using the ArduinoSMS class. This will cause the Arduino to reload the most recently uploaded sketch, so be sure to re-do any calibration if you’re using it.
        p = ArduinoSMS("/dev/ttyACM0", 115200);
    2. Next, create your synth def. Here’s a simple example in which the argument ‘add’ will be the value controlled by the input from the Arduino sensor:
            SynthDef(\Sine, { arg add = 0;
                var sine;
                sine =,0,0.2,0);
    3. Now create your synth object. You should hear a single stereo tone at 440Hz, as the ‘add’ argument is still set to default, which is 0.
        x = Synth(\Sine);
    4. The next step is to set the ‘add’ argument to the value of the Arduino sensor. Here we use the ‘action’ method to read the messages coming in from the Arduino via the serial port, and set the value of ‘add’ to match those messages. The frequency of the tone should now change to 440Hz + the value read by the sensor. Adjusting this value (for example by changing the amount of light it receives if it is a photometer, or tilting it if it is a gyroscope) should change the pitch of the tone.
            p.action = {
                | ... msg |
    5. To close the serial port, fixing the pitch of the tone at the last set value:

This is a very simple example of what can be done — the flexibility of SuperCollider means that similar code could be used to link the input from the sensor to almost any parameter of any synth, or use it to control aspects of tasks and patterns, such as when to start or stop. Go experiment!